Aspose.Pdf convert PDF to SVG, save to MemoryStream not supported

Is it possible then as an alternative to use Aspose.Words by first converting PDF to DocX and then converting the resultant stream to SVG?

@shayan.ahmad,

Thanks for contacting support.

Aspose.Words for .NET supports the feature to load MS DOC/DOCX files and transform them to various other formats. As per your requirement, you may consider using following code snippet to convert DOCX file to SVG format and save the output in Stream instance. However when using this approach, the images used inside PDF file are saved in separate folder.

I am in coordination with respective team to generate the code snippet where all resources i.e. Images, CSS, Fonts etc referenced inside PDF file are also saved in stream object.

[C#]

// Load the document from disk.
Aspose.Words.Document doc = new Aspose.Words.Document("c:/pdftest/Aspose.Html for .NET.docx");
Aspose.Words.Saving.SvgSaveOptions svg_save = new Aspose.Words.Saving.SvgSaveOptions();
svg_save.ResourcesFolder = "c:/pdftest/SVGContents/";
svg_save.SaveFormat = Aspose.Words.SaveFormat.Svg;
MemoryStream stream = new MemoryStream();
// Save the document in PDF format.
doc.Save(stream, svg_save);
Console.WriteLine(stream.Length);

how do i correctly reconstruct the original file when it is split up like this?

@shayan.ahmad,
Thank you for the inquiry. You can convert a PDF to DOC/DOCX with Aspose.Pdf API, and then convert this Word document to a single SVG file with Aspose.Words API. Please try the following source code:

[C#]

// Load PDF document
Aspose.Pdf.Document doc = new Document(@"C:\Pdf\test142\input.pdf");
// Save the output in DOCX format
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.DocX);
// Load the DOCX file
Aspose.Words.Document document = new Aspose.Words.Document(stream);
// Save in single SVG file
document.Save(@"C:\Pdf\test142\Output.svg", Aspose.Words.SaveFormat.Svg);

Please let us know in case of any confusion or questions.

Best Regards,
Imran Rafique

So i tried your solution with the following code:

 using (var tmpDoc = new Aspose.Pdf.Document(inputStream))
                {
                    // response.Content = new ByteArrayContent(svgBytes.ToArray());
                    using (var tmpStream = new MemoryStream())
                    {
                        tmpDoc.Save(tmpStream, new Aspose.Pdf.DocSaveOptions(){
                            Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX,
                            Mode = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow,
                        });

                        var doc = new Aspose.Words.Document(tmpStream);
                        
                        // set target of each hyperlink to open in new tab or window.
                        foreach(Aspose.Words.Fields.Field f in doc.Range.Fields)
                            if (f.Type == Aspose.Words.Fields.FieldType.FieldHyperlink)
                                ((Aspose.Words.Fields.FieldHyperlink)f).Target =  "_blank";

                        var options = new Aspose.Words.Saving.SvgSaveOptions()
                            {
                                ExportEmbeddedImages = true,
                                TextOutputMode = Aspose.Words.Saving.SvgTextOutputMode.UsePlacedGlyphs
                            };
                        doc.Save(outputStream,options); 

Problem is: When i use Flow mode the images in my pdf file are preserved but on the next page the formatting for other images gets ruined. In textbox mode the first page does not show at all but the formatting is perfectly fine for the other pages.

I am going to attach the file in question.

I’ve tried the different options in the docsaveoptions but i can’t get it to be perfect.

@shayan.ahmad,
Thank you for the details. Kindly send us your source PDF file, we will investigate and share our findings with you. Your response is awaited.

Best Regards,
Imran Rafique

How can i send the document privately?

@shayan.ahmad,
Thank you for the inquiry. You can mark this thread as private by editing the first post of this forum thread, and then attach your source PDF to your reply post. In that way, only you and Aspose staff members can view this thread and download the attachment.

Best Regards,
Imran Rafique

Hello,

what is the status of this issue?

@shayan.ahmad,
We have requested you to share your source PDF in an earlier post. Once you will share the complete details of the use case, then we will be able to investigate it further. Your response is awaited.

Best Regards,
Imran Rafique

i am referring to this comment:

Can i get a timeline on the MemoryStream issue? I need this to be resolved soon because we are strongly considering buying your product. I need a working solution by end of next week

this has nothing to do with an input file. the doc.save method does not allow an memorystream to be output. it isn’t implemented it seems.

also is it possible for you to write an async version of doc.save(httpresponse)

it should take in HttpResponseMessage as the HttpResponse is obsolete

@shayan.ahmad,
Well, you are talking about unable to save output SVG in Stream instance problem which is already logged under the ticket ID PDFNET-42889 in our issue tracking. It is pending for the analysis and not resolved yet. We have logged an ETA request under the same ticket ID PDFNET-42889. We will let you know once a significant progress has been made in the regard.

We can write MemoryStream to Response object and when the ticket ID PDFNET-42889 is resolved, then you will be able to do so.

Best Regards,
Imran Rafique

Hello, is there an update on PDFNET-42889?

@psvitz,

The linked ticket ID PDFNET-42889 is pending for the analysis and not resolved yet. We will investigate as per the development schedules and notify you once it is fixed.

@imran.rafique the ticket is over 9 months old, could you please elaborate further on when this is expected to be released?

@psvitz,

In reference to the linked ticket ID PDFNET-42889, we are reviewing details of the recent status, and will let you know in case of the possibility of a reliable estimate. Besides this, we recommend our clients to post their critical issues (or ticket IDs) in the paid support forum. Please refer to this helping link: Aspose support options

Hi @imran.rafique, do you have an update on this? I would consider this to be quite a serious gap. Please note the original date on the ticket.

@psvitz

We are afraid that the logged ticket is still pending for investigations owing to critical and previously logged issues. We have raised its priority to next level and will schedule it soon. We will be able to share any ETA for this issue once it is investigated in our environment. We appreciate your patience and comprehension in this regard.

Any update on this would be helpful.