Free Support Forum - aspose.com

I can't read the PDF files generated from certain JPG

Hello,
We have Aspose.Pdf version 11.4 and for certain JPG files generate a PDF file that we can’t read.
Can you help us solve the problem?
Can the generated PDF files be repaired?
Thank you

@rblasco76

Thank you for contacting support.

We would like to share with you that you are using an outdated version of the API. Please upgrade to latest version of Aspose.PDF API which includes more features and bug fixes. Also, the support is provided based on latest available version so kindly upgrade to Aspose.PDF for .NET 18.5. In case the issue persists, please share the source and generated files with us along with the code snippet that you are using for this conversion, so that we may investigate to help you out.

Hello,
we noticed the same problems with some JPG files unsing Aspose.Pdf 18.4 for Java. The resulting PDF file has errors.
Our code looks the same as the example of the Aspose.PDF Image Approach (https://docs.aspose.com/display/pdfjava/Convert+an+Image+to+PDF)
Attached is a JPG file and the generated PDF.bud.jpg (49.8 KB)
bud.pdf (60.2 KB)

@dvtdaten

Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-37760 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

However, you may use below code snippet in your environment to create a valid PDF file until logged ticket is investigated in our environment.

Document pdfDocument = new Document();
int lowerLeftX = 10;
int lowerLeftY = 10;
int upperRightX = 500;
int upperRightY = 500;
Page page = pdfDocument.getPages().add();
InputStream imageStream = new FileInputStream( dataDir + "bud.jpg");
page.getResources().getImages().add(imageStream);
page.getContents().add(new Operator.GSave());
Rectangle rectangle = new Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Matrix matrix = new Matrix(new double[] { rectangle.getURX() - rectangle.getLLX(), 0, 0, rectangle.getURY() - rectangle.getLLY(), rectangle.getLLX(), rectangle.getLLY() });
page.getContents().add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = page.getResources().getImages().get_Item(page.getResources().getImages().size());
page.getContents().add(new Operator.Do(ximage.getName()));
page.getContents().add(new Operator.GRestore());
dataDir = dataDir + "AddImage_18.4.pdf";
pdfDocument.save(dataDir);

We are sorry for the inconvenience.

Updating the version the problem is solved.

Thank you.