We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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

i have supplied a filepath to my local desktop for the converted svg document from PDF. But the converter produces multiple SVG files. How can i combine them into one directly from the converter itself? Is this possible?

Hello i tried this but it does not parse the PDF file correctly I get the following error:

This page contains the following errors:

error on line 1 at column 1: Document is empty
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.


This Topic is created by codewarior using the Email to Topic plugin.

Hi Shayan,

Thanks for contacting support.

During our testing with following code snippet where we have used our sample PDF files, we are unable to notice any issue. The might be related to the input PDF file which you are using, so can you please share the input PDF file, so that we can test the scenario in our environment.
[C#]
var doc = new Aspose.Pdf.Document(“c:/pdftest/Input.pdf”);
var saveOptions = new Aspose.Pdf.SvgSaveOptions()
{
CompressOutputToZipArchive = true
};
doc.Save(“c:/pdftest/Converted.svg”, saveOptions);

what happened to the old message? I still would like to be able to save the output to a MemoryStream? Also it wont let me upload my input file. it says new users cannot upload files for some reason.

Hi Shayan,

You can see the older discussion in read only mode in our older forums. However the issue PDFNET-42889 related to saving the output in MemoryStream is also associated with this thread and as soon as the problem is resolved, you will be intimated in this thread.

The problem related to attachments is resolved and you should be able to attach files in this thread. In case you still face any issue, please feel free to contact.

Hello, I’m still getting the same error: “Sorry, new users cannot upload files”

Hi Shayan,

The issue has been fixed and you should be able to upload the files now. Please try again and let us know if you still see any issue. We are sorry for the inconvenience.

Best Regards,
Muhammad Ijaz

html.pdf (121.6 KB)

@shayan.ahmad,

Thanks for sharing the sample file. I have tested the scenario using latest release of Aspose.Pdf for .NET 17.6 in Visual Studio 2010 project running over Windows 7 (x64) and I am unable to notice any issue. As per my observations, the PDF pages are properly being converted to SVG images are they are properly being saved. For your reference, I have also attached the output generated over my end. ConvertedArchive.zip (38.7 KB)

[C#]

var doc = new Aspose.Pdf.Document("c:/pdftest/html.pdf");
var saveOptions = new Aspose.Pdf.SvgSaveOptions()
{
    CompressOutputToZipArchive = false
};
doc.Save("c:/pdftest/html_Converted.svg", saveOptions);

Hello Nayyer,

I want one SVG file generated. it was suggested that i set CompressOutputToZipArchive = true. could you please try this?

Also, I cannot download the zip file you have attached it is giving me a “only staff members can download” error.

@shayan.ahmad,

I have also managed to generate output as single archived SVG when using CompressOutputToZipArchive = true. For your reference, I have also attached the archived output generated over my end html_Converted.zip (39.0 KB).

We are further looking into this matter and will get back to you soon. We are sorry for this inconvenience.

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

@shayan.ahmad,

As we recently logged above mentioned issue, so it is pending for review and unless the product team completes their investigation, we may not be able to share the tentative timelines regarding its resolution. Please note that issues are resolved in first come first serve basis as we believe it is the fairest policy to all the customers. As soon as we have some definite updates, we will let you know.

Your patience and comprehension is greatly appreciated in this regard.

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