Please keep in mind that pagecontent is optional and can be missing for
blank pages. And of course it can be that there is something written in
white that only can be seen on pages with a black background. This came
up several times on this mailinglist and there is no easy solution.
However it might be possible to find a solution in a special case like
this one. Another one would be to render the page and look at the pixels.
Best regards,
Carsten
Mick Collins schrieb:
> rivate int blankPdfsize = 20;
> public void removeBlankPdfPages(String pdfSourceFile, String
> pdfDestinationFile, boolean debug)
> {
> try
> {
> PdfReader r = new PdfReader(pdfSourceFile);
> RandomAccessFileOrArray raf = new
> RandomAccessFileOrArray(pdfSourceFile);
> Document document = new Document(r.getPageSizeWithRotation(1));
> // step 2: create a writer that listens to the document
> PdfCopy writer = new PdfCopy(document, new
> FileOutputStream(pdfDestinationFile));
> // step 3: we open the document
> document.open();
> // step 4: we add content
> PdfImportedPage page = null;
>
> if (debug)
> {
> System.err.println("number of pages for "+pdfSourceFile+" =
> "+r.getNumberOfPages());
> }
> for (int i=1;i<=r.getNumberOfPages();i++)
> {
> byte bContent [] = r.getPageContent(i,raf);
> ByteArrayOutputStream bs = new ByteArrayOutputStream();
> bs.write(bContent);
> if (debug)
> {
> System.err.println("page content length of page "+i+" =
> "+bs.size());
> }
> if (bs.size() > blankPdfsize)
> {
> page = writer.getImportedPage(r, i);
> writer.addPage(page);
> }
> }
> document.close();
> writer.close();
> raf.close();
> r.close();
> }
> catch(Exception e)
> {
> System.err.println("IOException in removing blank pages from
> "+pdfSourceFile+" = "+e);
> }
> }
>
>
>> From: abc xyz <[EMAIL PROTECTED]>
>> Reply-To: Post all your questions about iText here
>> <[email protected]>
>> To: [email protected]
>> Subject: [iText-questions] can we detect Blank pages in PDF File or
>> pageswith specific text or pattern
>> Date: Thu, 8 Jun 2006 06:26:28 -0700 (PDT)
>>
>>
>> hi all
>> infact i want to detect a blank page in my pdf file so that i can exlude it
>> when i copying the pages to another file or do some thing other with it,
>> similarly i want to detect/trace a specific text or pattern in file pages.
>> can any one help me.
>> if possible plz give me some example code it will help me more.
>> thanks
>>
>> best regards,
>> Simaab
>>
>>
>> Simaab
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>
>
>
>
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions