Aspose.PDF Html to PDF linear-gradient low resolution

When converting HTML to PDF using Aspose.PDF, the linear-gradient css converts into the PDF as a low resolution (72DPI) image. This is not suitable for high quality print.

How do I increase the resolution of the gradient in the PDF?
GradientExample.zip (38.6 KB)

To increase the resolution of linear gradients when converting HTML to PDF using Aspose.PDF, you can adjust the downsample options and image quality settings. By default, images, including gradients, may be rendered at a lower resolution (72 DPI), which is not suitable for high-quality prints.

Here are some steps you can take to improve the resolution:

  1. Set Downsample Options: You can specify downsample options to control the resolution of images in the PDF. This includes setting the desired DPI for images.

  2. Adjust JPEG Quality: If your gradients are being converted to JPEG images, you can set the JPEG quality to a higher value (up to 100) to ensure better quality.

  3. Enable High-Quality Rendering: You can enable high-quality rendering options to improve the overall output quality of the PDF.

Here is a code example demonstrating how to set these options:

using Aspose.Pdf;
using Aspose.Pdf.Devices;

public void ConvertHtmlToPdfWithHighQuality(string htmlFilePath, string pdfFilePath)
{
    // Load HTML file
    Document pdfDocument = new Document(htmlFilePath);

    // Set downsample options
    DownsampleOptions downsampleOptions = new DownsampleOptions
    {
        Resolution = 300 // Set desired resolution
    };

    // Set image compression options
    pdfDocument.SaveOptions.ImageCompression = PdfImageCompression.JPEG;
    pdfDocument.SaveOptions.JpegQuality = 100; // Set JPEG quality to maximum

    // Enable high-quality rendering
    pdfDocument.SaveOptions.UseHighQualityRendering = true;

    // Save the document
    pdfDocument.Save(pdfFilePath);
}

By implementing these settings, you should be able to achieve a higher resolution for linear gradients in your PDF output, making it more suitable for high-quality printing.

Sorry mister robot but “SaveOptions” is not a property on a Document instance, and “UseHighQualityRendering” is not a property on PdfSaveOptions

@ANDREA.FARRIS
Could you share code you are using to convert html to pdf?

@ilya.zhuykov No, it’s too complicated to share.

But if you take my originally attached HTML, and run it through your online converter, you can recreate the issue. The image I attached in the zip is actually from taking the provided HTML and converting it here: HTML to PDF Converter using C# | Aspose.PDF

@ANDREA.FARRIS
That’s enough, thanks

@ANDREA.FARRIS
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-57828

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.

I reproduced the issue, at first glance there is no obvious solution, therefore i added task for development team
I’ll try investigate a bit further, I’ll write you in case I find some solution or workaround