PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue May 23, 2017 6:50 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Feb 17, 2014 1:09 pm 
Offline

Joined: Mon Feb 17, 2014 12:34 pm
Posts: 1
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 183 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group