Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
-none-

-none-

2007-09-05       - By Bruno Lowagie

 Back
pchoul wrote:
> Hello,
>
>   I have a question about IText functionallity.
>   I was wondering if IText is capable of retrieving the size of the file
>   its writing to, before it closes that file.
>  
>   e.g.
>    If I concatenate some files in a folder using PdfCopyFields I will not be
> able to retrieve the
>    size of the file im writing to using new File("fileName.pdf").length()
> until I say PdfCopyFields.close()
>    
>    What I am trying to do is merge a lot of files into large files, but of a
> certain size.

How much accuracy do you require?
iText works as follows: you create a new Document object (1).
You tell a PdfWriter it should listen to the document and
write content to an OutputStream (2).
When you open the document, the first bytes are written to
the OutputStream (3).
Then you start adding content (4). iText tries to write as
much information as possible to the OutputStream: resources
that are used (Images, Content Streams of completed pages,...).
However there is always data that must stay in memory and
that can only be written to the OutputStream at the moment
the document is closed (5). This data includes: the
Cross-Reference Table, Outlines, templates,...

Depending on the way you are using iText, you could use
a ByteArrayOutputStream as OutputStream and check the
number of bytes written at specific moment. This will not
be accurate of course, because iText will at least need
to add the Cross-Reference Table and the PDF trailer at
the end of the file, but it could give you the indication
you need.

If you are merging documents, I'd suggest that you create
temporary document in memory (ByteArrayOutputStream) like this:
(PSEUDO CODE)

MyPdf[] series_of_pdfs;
bytes[] result = readBytes(series_of_pdfs[0]);
int count = 1;
while (count < series_of_pdfs.length) {
  PdfReader = new PdfReader(tmp);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  merge2Pdfs(baos, reader, series_of_pdfs[count]);
  byte[] tmp = baos.toByteArray();
  if (tmp.length < MAXIMUM) {
    result = tmp;
  }
  else {
    break;
  }
}

This piece of pseudo code is very incomplete. I think it's not
very efficient, but maybe it can inspire you to build a better
solution.
br,
Bruno

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
__ ____ ____ ____ ____ ____ ____ ____ ____ ____
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

©2008 junlu.com - Jax Systems, LLC, U.S.A.