(Sorry I think have sent an earlier email again by mistake - the fun of a 
rubbish webmail)

My question was whether or not iText had a tool/utility for concatenating 
ByteArrayOutputStreams - to make it that little bit easier for a lazy developer 
;) 

I tried to do this earlier and found that only the last byte array to be copied 
would be displayed in the produced pdf.

  byte[] cover = cFs.cpbaos.toByteArray();
  byte[] toc = cFs.tocbaos.toByteArray();
  byte[] content = cFs.cbaos.toByteArray();
                        
  byte[] pdf = new byte[cover.length+toc.length+content.length];
  System.arraycopy(cover, 0, pdf, 0, cover.length);
  System.arraycopy(toc, 0, pdf, cover.length, toc.length);
  System.arraycopy(content, 0, pdf, cover.length+toc.length, content.length);

I ended up using PdfReader and PdfCopy and it worked well. Although I do still 
have a question in regards to concatenating documents. I want to be able to 
have the toc link through to the headings that they reference. I have done this 
successfully when implementing it in a document with no need to concatenate 
with another (when i tried the reordering example). However due to existing 
codebase I still want to be able to do this whilst concatenating a toc 
ByteArrayOutputStream and contents ByteArrayOutputStream. I have the following:

In the toc ByteArrayOutputStream:

Paragraph headingParagraph = new Paragraph();
Anchor pageReference = new Anchor(heading.getText());
pageReference.setReference("#"+heading.getText());
headingParagraph.add(pageReference);
document.add(headingParagraph);

In the content ByteArrayOutputStream:

Paragraph headingParagraph = new Paragraph(headingTitle);
Anchor headingReference = new Anchor();
headingReference.setName(headingTitle);
headingParagraph.add(headingReference);                 
document.add(headingParagraph);

(headingTitle is used to set the heading text that the toc uses)

When the pdf is produced the pointed cursor does display over the table of 
contents headings but doesn't appear to know what it references. Is this an 
issue with concatenating the two Documents or with how I have implemented it? 

Thanks again! 

-----Original Message-----
From: Katrina Walker
Sent: Wed 18/03/2009 09:15
To: [email protected]
Subject: Re: Concatenating two Document objects before creating the PDF file
 
My preferred way would be to create ByteArrayOutputStreams and then concatenate 
them. Do you provide any tools with iText for concatenating the 
ByteArrayOutputStreams? 

I have seen in the book that you use Concat.main(arguments) where arguments is 
a String array for the pdf file names - so as far as I understand I wouldn't be 
able to use that when working with ByteArrayOutputStreams. 
Alternatively in the book I have seen how you can use PDFReaders and PDFCopy 
but I can only see how that does it on a page by page basis.   

Thanks for your help.

>There are different ways to achieve this.

>You could create the PDFs in memory by writing to a 
>ByteArrayOutputStream instead of to a FileOutputStream, then when you 
>are finished concatenate them.

>Or you could add the TOC at the end of the file, and then reorder the 
>pages as explained in the book: http://1t3xt.be/?X000012



Katrina Walker wrote:
> Hi,
>
> I am trying to produce a pdf with a table of contents at the start of 
> the pdf. The problem I have is that the table of contents can only be 
> populated once all the content has been processed (due to existing 
> codebase).  I am currently using a com.lowagie.text.Document for the 
> table of contents and then a com.lowagie.text.Document for the 
> content. I was wondering if there is a way to concatenate the two 
> Documents and then create the PDF as opposed to creating two PDF's and 
> concatenating them.
>
> Thanks
> Kat Walker
>
>
>



*********************************************************************
Please note that:

1. This e-mail may constitute privileged information. If you are not the 
intended recipient, you have received this confidential email and any 
attachments transmitted with it in error and you must not disclose, copy, 
circulate or in any other way use or rely on this information.
2. E-mails to and from the company are monitored for operational reasons and in 
accordance with lawful business practices.
3. The contents of this email are those of the individual and do not 
necessarily represent the views of the company.
4. The company does not conclude contracts by email and all negotiations are 
subject to contract.
5. The company accepts no responsibility once an e-mail and any attachments is 
sent.
http://www.integralis.com
*********************************************************************


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to