After trying to use the gnujpdf package, I found that it
seems not be able embed two or more images in a
single PDF file. Although no compilation error and
runtime error occur when generating the PDF, there is
an error alert from the acrobat reader when viewing the
generated PDF. The error alert is "Cannot find the
XOject named 'Image2'". Could anyone help me to solve
the problem? Thanks a lot!
Logged In: NO
There is an error when printing several images in a same page.
The PDF code generated is:
.../ProcSet 7 0 R /XObject << /Image1 9 0 R >> /XObject <<
/Image2 10 0 R
>>...
instead of:
.../ProcSet 7 0 R /XObject << /Image1 9 0 R /Image2 10 0 R
>> >>...
To fix this, I added a list of images in the PDFPage object
in addition
to the list of objects that is currently used and I print
the images
differently that the object. I attach the code to this email
(the
modifications are prefixed by a '// JM' comments). To be
more percise,
here are the changes:
in PDFGraphcis.drawImage, replaced:
page.addResource("/XObject << " + image.getName() + " " +
image.getSerialID() + " 0 R >>");
by
page.addImageResource(image.getName() + " " +
image.getSerialID() +
" 0 R");
in PDFPage class:
added attribute: protected Vector imageResources;
initialized in PDFPage() constructor:
imageResources = new Vector();
added metod:
public void addImageResource(String resource) {
imageResources.addElement(resource);
}
in PDFPage.write, added:
// Any other resources
for(Enumeration
en=resources.elements();en.hasMoreElements();) {
String str = en.nextElement().toString();
os.write(str.getBytes());
os.write(" ".getBytes());
}
// ADDED THIS BLOC OF CODE HERE:
if(imageResources.size() > 0) {
os.write("/XObject << ".getBytes());
for(Enumeration
en=imageResources.elements();en.hasMoreElements();) {
String str = en.nextElement().toString();
os.write(str.getBytes());
os.write(" ".getBytes());
}
os.write(" >> ".getBytes());
}
os.write(">>\n".getBytes());
// The thumbnail
...