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.
|