Hi,
I am using PDFBox in production and it is working great. I have a question on
how I am using it. I have a method that puts an image in a PDF as you can see
below. Since I have the same image on multiple pages it seems to me that this
code can/is drawing the same image on multiple pages. Is there a way to drop
an image into a PDF only once and then reference it on the various pages
specifying the location it is to be printed at? I hope that I made myself
clear, I'm trying to avoid multiple copies of the same image in the PDF.
Here is my code:
public void drawImage(Column column, float xPosition, float yPosition) throws
ProductRequestException {
float scale = 1f; // alter this value to set the image size
float imageYPosition = PDFGeneratorHelper.getImageYPosition(column,
yPosition);
float imageXPosition = PDFGeneratorHelper.getImageXPosition(column,
xPosition);
// Does NOT compress GIF and other image files
PDImageXObject pdImage;
try {
pdImage = PDImageXObject.createFromFile(
new
File(getClass().getClassLoader().getResource(column.getImagePath()).toURI())
.getAbsolutePath(), document);
} catch(IOException ioe) {
throw new ProductRequestException("IOException 1 in drawImage",
ioe);
} catch(URISyntaxException use) {
throw new ProductRequestException("URISyntaxException in
drawImage", use);
}
pdImage.getCOSObject().setName("BDSImageName", column.getImagePath());
try {
if (column.getImageWidth() == null) {
contentStream.drawImage(pdImage, imageXPosition,
imageYPosition, pdImage.getWidth() * scale,
pdImage.getHeight() * scale);
} else {
contentStream.drawImage(pdImage, imageXPosition,
imageYPosition,
Float.parseFloat(column.getImageWidth()),
Float.parseFloat(column.getImageHeight()));
}
} catch(IOException ioe) {
throw new ProductRequestException("IOException 2 in drawImage",
ioe);
}
}
Thank you,
Ray
________________________________
CONFIDENTIALITY NOTICE: This e-mail and any files transmitted with it are
intended solely for the use of the individual or entity to whom they are
addressed and may contain confidential and privileged information protected by
law. If you received this e-mail in error, any review, use, dissemination,
distribution, or copying of the e-mail is strictly prohibited. Please notify
the sender immediately by return e-mail and delete all copies from your system.