Add a grayscale jpeg to a PDF without bloating the size

When I take a 273kb jpeg that is 8 bit grayscale and add it to a PDF, the resulting PDF is 444kb. How can I add the jpeg without it getting bloated?

Aspose.Pdf.Page pdfPage = pdf.Pages.Add();
Aspose.Pdf.Image asposeImage = new Aspose.Pdf.Image();
asposeImage.ImageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
pdfPage.Paragraphs.Add(asposeImage);

I am using Aspose.PDF v23.9. I have the Total license if another product is better at this.

@gabe4797

After saving the document, would you please try to optimize it and see if the size is reduced. If issue still persist, please let us know.

00000000.jpg (268.5 KB)

Optimize did not change the size of the file at all. I have attached the sample file. I basically just want to be able to add an image without any modification and have the size come out similar to the source.
thank you!

@gabe4797

Have you tried optimizing the PDF document after it was saved with the image? Please try to save it to some path and re-initialize the Document with the save file to optimize it. In case issue still persists, please let us know.

I have done that, but not change.

@gabe4797

Please check the attached code snippet and the output PDFs that we generated in our environment using Aspose.PDF for .NET 23.9:

Document pdf = new Document();
Aspose.Pdf.Page pdfPage = pdf.Pages.Add();
Aspose.Pdf.Image asposeImage = new Aspose.Pdf.Image();
asposeImage.ImageStream = new FileStream(dataDir + "00000000.jpg", FileMode.Open, FileAccess.Read);
pdfPage.Paragraphs.Add(asposeImage);
pdf.Save(dataDir + "output.pdf");

pdf = new Document(dataDir + "output.pdf");
var opts = new Aspose.Pdf.Optimization.OptimizationOptions
{
    AllowReusePageContent = true,
    LinkDuplcateStreams = true,
    RemoveUnusedObjects = true,
    RemoveUnusedStreams = true,
    SubsetFonts = true,
    UnembedFonts = true,
    CompressObjects = true,
    ImageCompressionOptions =
    {
        Encoding = Aspose.Pdf.Optimization.ImageEncoding.Jpeg,
        MaxResolution= 150,
        ImageQuality = 20,
        ResizeImages = true,
        CompressImages = true
    }
};
pdf.OptimizeResources(opts);
pdf.Save(dataDir + "optimized.pdf");

optimized.pdf (86.8 KB)
output.pdf (442.8 KB)

Can you please make sure that you are using the API with a full or 30-days free temporary license? In case issue still persists, please let us know.

Thank you for your reply, but I am not looking to reduce the size or the quality of the image. I just want the original image in the PDF without it adding an extra 60% size. This appears to only happen with grayscale images (8bit). Color images are close enough. Can you please investigate further?

Also, I have been trying to get added to our paid support account, but the reset password link is not sending a password reset to our main account.

@gabe4797

Your this inquiry has been moved to Purchase forum where you will be assisted accordingly.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-55536

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as PDFNET-55536) have been fixed in Aspose.PDF for .NET 23.11.