Convert multiple JPG's to one PDF

Hey,

I was wondering if there is a way to convert multiple JPG images to a single PDF.

Atm we are scanning in batch and the output for every page is a JPG. Its a high quality JPG with 2480 x 3478 resolution. The images are usually between 500 and 1000kb.

Atm I’m using standard .NET code to convert all the JPG’s to one multipage tiff. I then convert the multipage tiff to PDF with Aspose.Words. I’m testing it with 3 images atm. (600kb, 600kb and 800kb).

Now the problem is that my output is huge. The PDF itself is fine and has all the pages nicely put together. However its about 22MB in size. When I create a Physical file from the multipage tiff the tiff is actually 40MB in size. so the conversion almost cuts that in half but its still huge. It looks like the problem is with the conversion to multi tiff before I go to PDF.

So I was wondering if there was a way to skip this step and merge the multiple JPG’s to a single PDF directly using Aspose.Words.

Thanks in advance

Hi Niels,

Thanks for your inquiry. You can directly save multiple JPEG images to a single PDF by using the following function:

public static void ConvertMultipleImagesToPDF(List<Image> images)
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Loop through all the images
    for (int i = 0; i < images.Count; i++)
    {
        PageSetup ps = builder.PageSetup;
        ps.PageWidth = ConvertUtil.PixelToPoint(images[i].Width, images[i].HorizontalResolution);
        ps.PageHeight = ConvertUtil.PixelToPoint(images[i].Height, images[i].VerticalResolution);
        // Insert one image per page, positioned at top left corner of document
        builder.InsertImage(images[i],
            RelativeHorizontalPosition.Page,
            0,
            RelativeVerticalPosition.Page,
            0,
            ps.PageWidth,
            ps.PageHeight,
            WrapType.None);
        // To prevent extra page break at the end of document
        if (i < images.Count - 1)
            builder.InsertBreak(BreakType.SectionBreakNewPage);
    }
    // Save Aspose.Words document to PDF format
    doc.Save(@"C:\test\Out.pdf");
}

I hope, this will help.

Best Regards,