It seems that you are experiencing an issue with duplicate images being created when converting an image to a PDF using your provided code. This could be due to how the image is being added to the PDF document.
Here are a few suggestions to help you troubleshoot and resolve the issue:
Check for Multiple Additions: Ensure that the processFile method is not being called multiple times for the same image file. If this method is invoked in a loop or multiple times for the same file, it will add the image repeatedly.
Image Handling: Instead of directly adding the image file path to the Image object, consider using a stream or a buffered image. This can help manage how the image is processed and added to the PDF. For example, you can read the image into a BufferedImage and then add it to the PDF.
Use Unique Identifiers: If you are processing multiple images, ensure that each image is uniquely identified and added to the PDF. This can prevent duplicates if the same image is processed more than once.
Here’s a modified version of your code that demonstrates how to add an image from a BufferedImage to a PDF document, which may help avoid duplication:
In this example, the XImage.fromImage(bufferedImage) method is used to create an image object from the buffered image, which can help manage the image addition more effectively.
If the issue persists, consider checking the overall flow of your application to ensure that the processFile method is not being called unnecessarily for the same file.
Are you testing with the latest version of the API? Can you please share sample image and produced output PDF at your end for our reference? We will investigate in our environment and address the issue accordingly.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.