I am having difficulties adding multiple images to PDFs.

My development environment is Windows, Apache, Resin 3.
On this server, I am able to add multiple images to a
PDF using the iText library (1.1) and view the
resulting document.

On my production server (hosted by a third party),
which is Linux, Apache, Resin 2, a valid PDF document
fails to be created if I add more than one image.

In both cases I am using Adobe Reader 6 to open the
document. The error I am receiving in Adobe is "Adobe
Reader could no open 'Math-1.pdf' because it is either
not a supported file type or because the file has been
corrupted (...)"

One thing to note is that my production server is running
in headless mode without any graphics library
installed. I originally suspected this might be the
issue, but the fact that a single image can be added to
the PDF would appear to void this theory.

Here is an example image:
http://www.testdesigner.com/include/math/images/1358978531.png

Both my development and production code reference the same image. It doesn't matter if I add the same image twice or two different images. In both cases, the document fails to be created properly. I have also tried different images. Again, everything works locally, just not on my production server.

The relevant code is as follows:
final Phrase phrase = new Phrase();
final Image equation = Image.getInstance(new URL(url));
equation.setAlignment(Image.MIDDLE);
// vertical aligns text with images on a line
final Chunk ck = new Chunk(equation, 0.0F,
-equation.height() / 2.0F + 6.0F); // TODO: Determine
how to calculate 6 (what appears to be half line height)
// add image chunk
phrase.add(ck);
// add extra spacing to compensate for height of image
phrase.setLeading(equation.scaledHeight() * 1.2F);
final ListItem li = new ListItem(phrase);
final com.lowagie.text.List questionList = new
com.lowagie.text.List(true, false, 20);
questionList.add(li)
doc.add(questionList);

I create a new Phrase and add the next image in a loop.

Is there anything that happens
differently with the iText libraries on Linux that
doesn't happen on Windows that could be causing this
error. Is there any way to debug this issue without a debugger (since I can't debug on my
production server)?


My Servlet looks something like this:
baosPDF = TestManager.getPDFBytes(test);


resp.setHeader("Cache-Control", "max-age=30");
resp.setContentType("application/pdf");

final StringBuffer sbContentDispValue = new StringBuffer();
sbContentDispValue.append("attachment");
sbContentDispValue.append("; filename=");

final String fileName = test.getName() + ".pdf";
sbContentDispValue.append(fileName);

final String contentDisposition = sbContentDispValue.toString();
resp.setHeader("Content-disposition", contentDisposition);
final int size = baosPDF.size();
resp.setContentLength(size);
final ServletOutputStream sos = resp.getOutputStream();
baosPDF.writeTo(sos);
sos.flush();

Any suggestions or ideas would be appreciated.


Thank you, Michael

--
Michael Bacarella
Web Application Developer
www.bacman.net
www.testdesigner.com


begin:vcard
fn:Michael Bacarella
n:Bacarella;Michael
email;internet:[EMAIL PROTECTED]
tel;fax:347.683.8163
version:2.1
end:vcard

Reply via email to