PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Removing blank pages in PDF document https://forum.pdfsharp.net/viewtopic.php?f=2&t=1422 |
Page 1 of 1 |
Author: | rogeriocbr [ Tue Nov 16, 2010 5:27 pm ] |
Post subject: | Removing blank pages in PDF document |
Hi there, How i can remove some blank pages in PDF documents using this component(PDFSharp) ? Thanks, Rogério Ramos. |
Author: | mikesowerbutts [ Wed Nov 17, 2010 10:44 am ] |
Post subject: | Re: Removing blank pages in PDF document |
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 |
Author: | kompellamurthy [ Wed Jun 08, 2011 1:52 am ] |
Post subject: | Re: Removing blank pages in PDF document |
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); |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |