osmoz7 wrote:
> Hi,
> 
> I'm trying to split a pdf file according to an array of offsets and
> fragment's lengths. I have found the following solution, but I am not sure
> if it is the right way to do it.
> 
> PdfReader reader = new PdfReader("myfile.pdf");
>  
> for (int i = 0; i < beginIndexArray.length; i++) {
>  
>  FileOutputStream foStream = new FileOutputStream("myfragment"+i+".pdf");
>  PRStream prStream = new PRStream(reader, beginIndexArray[i] );
>  prStream.setLength(fragmentLengthArray[i] );
>  Document pdfFragmentDoc = new Document();
>  PdfWriter pdfFragmentWriter = PdfWriter.getInstance(pdfFragmentDoc , 
> foStream);
>  prStream.toPdf(pdfFragmentWriter, foStream);
> }
> 
> The javadoc API is not very clear about the use of toPdf() method. At the
> end, I have fragments of the pdf file, they are readable by Acrobat 8, but
> opening it with PDF-Analyzer
> (http://www.softpedia.com/get/Office-tools/PDF/PDFAnalyzer.shtml) leads to
> an error message. 
> Any help would be greatly appreciated. Thanks!

Please throw away your code and wish you had never posted it.

The javadoc API isn't clear about the use of toPdf() and no
documentation mentions the toPdf() method: not the tutorial,
not the book. There's a very good reason for this:
YOU ARE NOT SUPPOSED TO USE THE toPdf() METHODS!!!

I have no idea where to begin explaining why what you are doing
is very, very wrong. It's a miracle that Acrobat 8 shows something.
Your blasphemous code sample looks like you want to take some PDF
syntax from one file and copy it to another file. But what about
the resource dictionaries? What about shared objects such as images,
fonts,...?  What about the Cross-reference table?

Do you have any idea what a PDF file looks like on the inside?
Have you tried reading the iText tutorial? Did you read "iText
in Action"? Have you consulted the PDF Reference?

If you are not familiar with concepts such as "resource dictionary"
or "cross-reference table," nobody on this list will be able to help
you. The only advice you'll get is to read the PDF Reference (it
can be downloaded for free).
-- 
This answer is provided by 1T3XT BVBA

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to