xmlns:pdfviewer="using:Syncfusion.Windows.PdfViewer"
<pdfviewer:SfPdfViewerControl x:Name="pdfviewer"/> |
//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
StorageFile storageFile = null;
foreach (var sheet in this.spreadsheet.Workbook.Worksheets)
{
//Create the page
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create the parent grid
PdfGrid parentPdfGrid = new PdfGrid();
//Add the rows
for (int i = 0; i < this.spreadsheet.ActiveSheet.UsedRange.Row; i++)
{
PdfGridRow row1 = parentPdfGrid.Rows.Add();
row1.Height = 50;
parentPdfGrid.Columns.Add(this.spreadsheet.ActiveSheet.UsedRange.Column);
for (int j = 0; j < this.spreadsheet.ActiveSheet.UsedRange.Column; j++)
{
var style = this.spreadsheet.ActiveSheet.UsedRange[i, j];
PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j];
pdfGridCell.Value = style.Value;
}
}
//Draw the PdfGrid.
parentPdfGrid.Draw(pdfPage, PointF.Empty);
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting);
//Save the document.
await pdfDocument.SaveAsync(storageFile);
}
if (storageFile != null)
{
FileStream stream = File.OpenRead(storageFile.Path);
pdfViewer.Unload();
pdfViewer.LoadDocument(stream);
//Print the pdf file.
pdfViewer.Print();
pdfDocument.Dispose();
} |