Free Support Forum - aspose.com

Urgent: Unable to render gradient while generating a jpeg/png file from a SVG file

Hi, we are trying to convert an SVG file to a jpeg/png file using JpegDevice/PngDevice, but it seems to be rendering the gradient incorrectly.

We are using this SVG image gradient_svg_image.zip (1.7 KB)

we have used the below code:
//“this.source” is the data of the SVG file in String.

SvgLoadOptions options = new SvgLoadOptions();
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(
new ByteArrayInputStream(this.source.getBytes()), options);

ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
Resolution resolution = new Resolution(this.height.intValue(), this.width.intValue());
JpegDevice jpegDevice = new JpegDevice(750, 472, resolution, this.res.intValue());// resolution,
// this.res.intValue());
jpegDevice.setCropRectangle(new Rectangle(0, 0, 562, 353));
jpegDevice.process(pdfDocument.getPages().get_Item(1), imageStream);
return imageStream.toByteArray();

Please let us know what seems to be the problem, or if there is anything that we can do differently.

@wvlabelmaker

Would you kindly share the missing values in your code snippet e.g. height/width/resolution. We will test the scenario in our environment and address it accordingly.

yes sure, the values are:
this.height and this.width is equal to 120.
and this.res = 90

Please let me know if you require anything else. Thanks again.

@wvlabelmaker

We were able to notice the issue in our environment using following code snippet with Aspose.PDF for Java 20.3.

SvgLoadOptions options = new SvgLoadOptions();
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "gradient_svg_image.svg", options);
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(120, 120);
com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(750, 472, resolution, 90);
//jpegDevice.setCropRectangle(new Rectangle(0, 0, 562, 353));
jpegDevice.process(pdfDocument.getPages().get_Item(1), dataDir + "output20.3.jpg");

Therefore, we have logged it as PDFJAVA-39280 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi, is there any work around that you will be able to suggest.

@wvlabelmaker

Regretfully we cannot offer any workaround at the moment as ticket is pending for analysis. We will surely share with you as soon as we have some updates about ticket resolution. Please spare us some time.

We are sorry for the inconvenience.