PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

To handle export to pdf from xps which has >1 fixed document
http://forum.pdfsharp.com/viewtopic.php?f=4&t=2738
Page 1 of 1

Author:  navaneeth25 [ Mon Feb 17, 2014 1:09 pm ]
Post subject:  To handle export to pdf from xps which has >1 fixed document

Hi currently pdf sharp handles only conversion from xps to pdf document if xps internally has only one fixed document.i.e in XpsConverter.cs file currently a block of code is as shown below
It handles only export of xps pages which are in first fixed document of xps. If the xps was built with more than 1 fixed document then its not exporting the pages of second fixed document
fixedDocument = xpsDocument.GetDocument();
PdfDocument pdfDocument = new PdfDocument();
PdfRenderer renderer = new PdfRenderer();
int pageIndex = 0;

foreach (FixedPage page in fixedDocument.Pages)
{
if (page == null)
continue;
Debug.WriteLine(String.Format(" doc={0}, page={1}", docIndex, pageIndex));
PdfPage pdfPage = renderer.CreatePage(pdfDocument, page);
renderer.RenderPage(pdfPage, page);
pageIndex++;
#if DEBUG
// stop at page...
if (pageIndex == 50)
break;
#endif
}
pdfDocument.Save(pdfFilename);
xpsDocument.Close();
xpsDocument = null;

the enhancement code what I am proposing is shown below. Here I am taking the collection of Fixed documents in a xps document and looping it and adding pages of it.

//FixedDocument fixedDocument = xpsDocument.GetDocument();
FixedDocumentCollection fixedDocumentCollection = xpsDocument.Documents;
PdfDocument pdfDocument = new PdfDocument();
PdfRenderer renderer = new PdfRenderer();

int pageIndex = 0;
foreach (FixedDocument fixedDocument in fixedDocumentCollection)
{
foreach (FixedPage page in fixedDocument.Pages)
{
if (page == null)
continue;
Debug.WriteLine(String.Format(" doc={0}, page={1}", docIndex, pageIndex));
PdfPage pdfPage = renderer.CreatePage(pdfDocument, page);
renderer.RenderPage(pdfPage, page);
pageIndex++;

#if DEBUG
// stop at page...
if (pageIndex == 50)
break;
#endif
}
}
pdfDocument.Save(pdfFilename);
xpsDocument.Close();
xpsDocument = null;

I am also attaching the full XpsConverter.cs file for you reference.

Attachments:
XpsConverter.zip [3.68 KiB]
Downloaded 1021 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/