So your problem is with PDFBox that can't read the text? You're in the wrong 
mailing list.

Paulo

----- Original Message ----- 
From: "Xavier Sudan" <xsu...@gmail.com>
To: <itext-questions@lists.sourceforge.net>
Sent: Tuesday, August 04, 2009 1:44 PM
Subject: [iText-questions] Reuse the same file multiple time...


Hello,

I would like to take one file, create with his contains another, and another 
and another... (multiple time, for example to get a file, and make two, 
after make four, ...).

My problem is that after the creation of two files, the last is unreadable 
and I don't know what I do wrong... For my tests, I take one PDF (PDF_A) 
from 1 page, and I create the PDF_B. After I take PDF_B to create PDF_C and 
there PDF_C is unreadable (with Code using PDFBox, but I can open and read 
it by the OS system). When I use the code below to read the new PDF, it see 
just the contains : "\r\n"
Test with IText 2.1.4 and 2.1.7.


What I do wrong during the creation of the new file ?

Thanks

-------------------------------------
Code to create new PDF
------------------------------------
....
com.lowagie.text.Document document = new com.lowagie.text.Document(
                        reader.getPageSizeWithRotation(numberOfPage));
                PdfWriter writer;
                try {
                    File f = new File(nameOfNewFile);
                    if (f.exists()) {
                        ...
                    }
                    writer = PdfWriter.getInstance(document,
                            new FileOutputStream(nameOfNewFile));
                } catch (Exception e) {
                   ...
                    succesfull = false;
                    continue;
                }
                document.open();
                PdfContentByte cb = writer.getDirectContent();
                PdfImportedPage page;
                int rotation;
                for (int pageNumber = pdfFromERP.pageBegin + 1; pageNumber 
<= pdfFromERP.pageEnd + 1; pageNumber++) {
                    document.setPageSize(reader
                            .getPageSizeWithRotation(pageNumber));
                    document.newPage();
                    page = writer.getImportedPage(reader, pageNumber);
                    rotation = reader.getPageRotation(pageNumber);
                    if (rotation == 90 || rotation == 270) {
                        cb.addTemplate(page, 0, -1f, 1f, 0, 0, reader
                                .getPageSizeWithRotation(pageNumber)
                                .getHeight());
                    } else {
                        cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
                    }
                }
                document.close();

-------------------------------------
Code read a PDF
------------------------------------
...
try {
            parser.parse();
            cosDoc = parser.getDocument();
            pdfStripper = new PDFTextStripper();
            pdDoc = new PDDocument(cosDoc);
            int numberOfPage = pdDoc.getNumberOfPages();
            // Get Content
            for (int i = 1; i <= numberOfPage; i++) {
                pdfStripper.setStartPage(i);
                pdfStripper.setEndPage(i);
                listContentPDFText.add(pdfStripper.getText(pdDoc));
            }
...
(source : 
http://www.prasannatech.net/2009/01/convert-pdf-text-parser-java-api-pdfbox.html)



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to