ERROR CONVERTING JPG TO PDF

Hello,

We have a problem to convert the jpg file (seejpg attached file) to PDF, the result give us an empty PDF file (see PDF attached file). It’s very strange and we don’t find why only for this file it doesn’t work.

Can you please help ?

Thank you in advance for your support.

Regards.Test.pdf (5.3 KB)
Test.JPG (238.2 KB)

@dlan
I used this code

var pdfDocument = new Aspose.Pdf.Document();
var pdfPage = pdfDocument.Pages.Add();
            
var image = new Aspose.Pdf.Image();
image.File = myDir + "Test.jpg";

pdfPage.Paragraphs.Add(image);

pdfDocument.Save(myDir + "Test-out.pdf"); 

the result is valid
Test-out.pdf (258.8 KB)

Hello,

Thank you for your response.

Below the code we use to convert Image to PDF=>

public static void convertImageToPDF(String filePathLicense, String imageFilepath, String pdfOutFilepath ) {
com.aspose.pdf.License license = new com.aspose.pdf.License();
try {
license.setLicense(Paths.get(filePathLicense).toString());
} catch (Exception e1) {
e1.printStackTrace();
}

    com.aspose.pdf.Document doc = new com.aspose.pdf.Document() ;
    com.aspose.pdf.Page page = doc.getPages().add();
    page.getPageInfo().setHeight(A4Height);
    page.getPageInfo().setWidth(A4Width);

    com.aspose.pdf.Image image = new com.aspose.pdf.Image();
    BufferedImage readImage = null;
    try {
        readImage = ImageIO.read(new File(imageFilepath));
        int srcimgHeight = readImage.getHeight();
        int srcimgWidth = readImage.getWidth();
        image.setFile(imageFilepath);

        // Set margins so image will fit, etc.
        page.getPageInfo().getMargin().setBottom(marginBottom);
        page.getPageInfo().getMargin().setTop(marginTop);
        page.getPageInfo().getMargin().setLeft(marginLeft);
        page.getPageInfo().getMargin().setRight(marginRight);

        double PDFPageScale =  page.getPageInfo().getWidth() > page.getPageInfo().getHeight() ? (page.getPageInfo().getHeight() - marginTop - marginBottom) : (page.getPageInfo().getWidth() - marginRight - marginLeft);
        double ImageMaxHeigtWidth = srcimgHeight > srcimgWidth ? srcimgHeight : srcimgWidth;
        double ScalingFactor = PDFPageScale > ImageMaxHeigtWidth ? 1 : (PDFPageScale / ImageMaxHeigtWidth);

        image.setFixWidth(srcimgWidth* ScalingFactor);
        image.setFixHeight(srcimgHeight * ScalingFactor); 
        image.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);
        image.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Center);
        page.getParagraphs().add(image);

        doc.save(Paths.get(pdfOutFilepath).toString());
    } catch (Exception de) {
        System.err.println(de.getMessage());
        throw new com.aspose.pdf.exceptions.PdfException("Erreur Exception lors de la conversion de l'image");
    } finally {
        if (doc != null)
            doc.close();
        if (readImage != null)
            readImage = null;
    }


} 

We are very surprised that it doesn’t work for some case.
Maybe you can help us.

@dlan
I’ll take a look and write to you tomorrow.

@dlan
What version of the library are you using?
What variable values are you setting for:

page.PageInfo.Height = PageSize.A4.Height;
page.PageInfo.Width = PageSize.A4.Width;
int marginBottom = 20;
int marginTop = 20;
int marginLeft = 20;
int marginRight = 20;

?
after the sign = those that I took and I created a valid document. True, I used a library for C #, I don’t use Java, and if the code had been given right away, I would not have taken this question (but the libraries must be synchronized).