SVG to Aspose Image to be passed to StampAnnotation

Does Aspose.PDF support this?


i have an SVG file and i would like to pass that to a StampAnnotation object

Hi Chit,


Thanks for contacting support.

Aspose.Pdf for .NET supports the feature to convert add SVG image to PDF file and it also provides the capabilities to Add SVG Object to Table Cell. But I am afraid currently it does not support the feature to use SVG as StampAnnotation. However as a workaround, you may consider Converting SVG To Raster Format using Aspose.Imaging for .NET and then Add Image Stamp in PDF File using Aspose.Pdf for .NET.

Should you have any further query, please feel free to contact.

ok thank you for the info.


but that is not considered a workaround because a stamp annotation is not the same an image stamp.


ill look for some other alternative

Hi Chit,


Thanks for sharing the details.

Currently the StampAnnotation class supports PNG and JPEG images but currently it does not support SVG images. However for the sake of correction, I have logged this enhancement request as PDFNET-42444 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hello,

I also need this, 4 years later what is the status of this demand ?

Thanks

im afraid this may not even be possible for them since they need to add more libraries for image processing.

what i did was use 3rd party libraries that output svg to inputstream, then you use that to pass to stamp annotation.

@chitgoks, @tfipsrd

We thank you for your patience and would like to share with you that support of SVG image in StampAnnotation was added in the API. Please use following code snippet with Aspose.PDF for .NET 20.12 and let us know if you still face any issue:

Document doc = new Document();
doc.Pages.Add();
Aspose.Pdf.Annotations.StampAnnotation stamp = new Aspose.Pdf.Annotations.StampAnnotation(doc.Pages[1], new Aspose.Pdf.Rectangle(10,10,100,100));
stamp.Image = new FileStream("input.svg", FileMode.Open);
doc.Pages[1].Annotations.Add(stamp);
doc.Save("stampannotation.pdf");
1 Like

The stream can be a svg file, but at the end, in the pdf, it will be transformed into a bitmap.
That’s not what I expected. I need to pass an svg and save it in the pdf as an svg to keep the quality.

@tfipsrd

We will surely investigate the feasibility of your requirements. However, could you please provide a sample SVG file along with expected output PDF. We will test the scenario in our environment and address it accordingly.

i just tried this using v20.2 in java
doesnt work. it shows empty.

im doing this in java

StampAnnotation stampAnnot = new StampAnnotation(asposePage, location);
stampAnnot.setTitle(“title”);
stampAnnot.setContents(“contents”);
stampAnnot.setImage(new FileInputStream(new File(“stamp_approved.svg”)));
asposePage.getAnnotations().add(stampAnnot);

stamp_approved.zip (4.1 KB)

In C# Though, it works but yes, the quality is not the same. looks like it gets transformed to PNG Just like what i currently am doing.

Also, question #2, does stamp support base 64 svg string?

@chitgoks

The archive was damaged or corrupted and we were unable to extract the sample SVG image from it for testing.

A feature request as PDFJAVA-40098 has been logged in our issue tracking system for the implementation. We will investigate the feasibility of this feature and let you know as soon as it is available. Please be patient and spare us some time.

We are sorry for the inconvenience.

that’s weird. i can download the zip file just fine, extracted it, viewed it in chrome browser and it loads just fine.

@chitgoks

It is quite possible that you have used a different utility to make an archive. You can please upload the SVG to Dropbox and share the link with us. Also, we have tested the scenario with one of our sample SVGs and were unable to notice any issue with the image quality in output PDF.

ezyzip.zip (4.1 KB)
Here please try this.

@chitgoks

Please check attached PDF document which was generated at our end using the following code snippet and Aspose.PDF for Java 21.1.

Document doc = new Document();
Page asposePage = doc.getPages().add();
StampAnnotation stampAnnot = new StampAnnotation(asposePage, new Rectangle(0,0,200,200));
stampAnnot.setTitle("title");
stampAnnot.setContents("contents");
stampAnnot.setImage(new FileInputStream(new File(dataDir + "stamp_approved.svg")));
asposePage.getAnnotations().add(stampAnnot);
doc.save(dataDir + "stamp.pdf");

stamp.pdf (42.4 KB)

Would you please check it and let us know if you notice any quality-related or other issues in it.

confirmed. it works. i was testing another svg that did not show the results. probably your svg only supports basic details?

but the quality as @tfipsrd mentioned is not vector. so this should be the priority. anyway. here is the vector that doesnt show up in case you may want to add more supported vector features into the lib.stamp.zip (4.6 KB)

@chitgoks

We have logged following two ticket in our issue tracking system:

  • PDFJAVA-40111 - Quality is not good in the output PDF for SVG in Stamp
  • PDFJAVA-40112 - Image is not showing in the output PDF when SVG is used in Stamp

We will further investigate these two tickets and post in this forum thread as soon as they are resolved. Please be patient and give us some time.

We are sorry for the inconvenience.