PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 09, 2024 4:15 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Nov 16, 2010 5:27 pm 
Offline

Joined: Tue Nov 16, 2010 5:24 pm
Posts: 1
Hi there,

How i can remove some blank pages in PDF documents using this component(PDFSharp) ?

Thanks,

Rogério Ramos.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 17, 2010 10:44 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I would load the Pdf into a PdfDocument, then loop through the pages and check the MyPdfDocument.Elements.Count property. I dont think its 0 on a blank page, but maybe something like 4 or whatever. If you test with a blank document, you shoud be able to find the magic number and then use that as the condition. If the condition is true, then remove the page:

Code:
int _emptyNum = 4;
int _cnt = MyPdfDocument.PageCount;
for(int i = 0; i < _cnt; i++){
   if(MyPdfDocument.Pages[i].Elements.Count == _emptyNum){
       MyPdfDocument.Pages.RemoveAt(i);
       _cnt--;
   }
}

I havnt tested that code, but i think it will work without giving any out of bounds array errors etc.

Hope this helps,

Mike


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2011 1:52 am 
Offline

Joined: Wed Jun 08, 2011 1:47 am
Posts: 4
When i use the code above, the page count it is giving 0 and all the pages in the pdf are deleted even though i commented the line (Remove);
:oops:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 33 guests


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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group