Not able to convert from PDF to SVG via stream

Hi Asasd, I am using a Aspose.Total license file and I could verify that the license was applied because the evaluation watermark is gone. I won’t be able to share the exact test file I am testing but I will try to source a similar one. I can tell you that the pdf document has 5 pages with vector graphics in each page. The file was created with Adobe Illustrator. In the past we used LeadTools to do the same operations as now and it was working fine before.

in the meanwhile here is the code snippet

            // Convert each pdf into svg documents
            foreach ( var filePath in filePaths )
            {
                var document = new Document(filePath);

                foreach (var page in document.Pages)
                {
                    // Extract each page as a separate pdf document for conversion
                    var pageDocument = new Document();
                    pageDocument.Pages.Add(page);

                    // Convert page into svg document for manipulation
                    var ms = new MemoryStream();
                    pageDocument.Save(ms, new SvgSaveOptions());

                    var svgDocument = new SVGDocument(ms, ".");
                    svgDocuments.Add(svgDocument);
                    ms.Dispose();
                }
            }

@chiraagbangera

As shared earlier, we were unable to reproduce the issue at our end. We again tested the scenario in our environment and did not observe any issue with the same code snippet. Please try to share a sample file with us using which we can again test the scenario and try to replicate the issue.

Hi Asasd, can you please try the pdf attached with this message. On my computer i still have the same issue.

Sample_Tech_Pack_Advanced.pdf (637.4 KB)

@chiraagbangera

Could you kindly share the screenshot of the error with us. We tested the scenario using your file and did not notice any error or exception at var svgDocument = new SVGDocument(ms, ".");. We spectated the object and found that ChildNodes and Title Properties were NULL. While loading the SVG file from a file, the Title Property of the SVGDocument had some value.

Hi Asasd, I did not get any error, but when inspecting the svgdocument object, most of the properties were null including “ChildNodes”, “RootElement”. This is what lead me to believe that the svgdoucment object being created is empty/invalid. However, saving the file as a svg and then loading the file in as a file stream works perfectly.

image.png (33.1 KB)

image.png (37.2 KB)

@chiraagbangera

Please add following line of code before loading the SVGDocument from MemoryStream and let us know if issue still persists:

ms.Seek(0, SeekOrigin.Begin);

Hi Asad, that worked! Since this was not documented in the official documentation would this classify as a bug ?

@chiraagbangera

This would not be a bug in the API as seeking the memory stream back to the beginning resolved the issue. However, we will surely update our documentation accordingly so that such a situation can be prevented in the future.

@chiraagbangera

This to update you that we are going to add descriptions to API that document is processed from the current position in the stream. We think that it will be enough because working with positions in streams is a regular practice described in Microsoft documentation. Besides you are able to load documents from compound streams where position of document within the stream can be more than 0.

Thanks Asad, I agree.

1 Like

I have an additional question related to the same project when used as a managed library inside Unity3D. When I am loading the SVGDocument either through a stream or a file, it doesn’t seem to fully initialize. I end up with an object that is empty. The ready state says loading and doesn’t seem to change to complete. This is only in Unity3D, the unit tests work perfectly fine.

image.png (22.8 KB)
Is there something I am missing ?

@chiraagbangera

It is hard to tell the reason behind such behavior by the API. Would you please share the steps to replicate the same issue in our environment. Also, please share your sample SVG file with us. We will test the scenario in our environment and address it accordingly.

Hi Asasd, i have created a sample unity3d project and a sample .net standard library that is used in the unity project. I still have the same issue when using the sample file. I have attached everything needed to test with this message.

When inspecting the svgdocument object after creating a new instance via stream, the ReadyState still says loading. I already tried loading the document asynchronously with the example code from

but that creates an infinite loop at the documentEvent.WaitOne(); line and unity freezes obviously.

Also,
I tried loading a pdf/svg directly from the unity3d project with the code below, no luck. Changing unity player settings such as scripting backend and .net version also yielded no results.

var svgDocuments = new List();
var document = new Document(pdf);
foreach ( var page in document.Pages )
{
// Extract each page as a separate pdf document for conversion
var pageDocument = new Document();
pageDocument.Pages.Add(page);

        // Convert page into svg document for manipulation
        using ( var ms = new MemoryStream() )
        {
            pageDocument.Save(ms, SaveFormat.Svg);
            // Reset stream position to 0
            ms.Seek(0, SeekOrigin.Begin);

            var svgDocument = new SVGDocument(ms, ".");
            svgDocuments.Add(svgDocument);
        }
    }

    // Load SVG Directly from file
    var testSvg = new SVGDocument(".\\Assets\\temp.svg"); //same issue here

I do want to add that the pdf loads fine, i am able to save it as a file pdf/svg and it looks okay to me, it’s only when creating the svgdocument i have issues.

@chiraagbangera

We are checking the scenario in our environment with Unity3D and will get back to you shortly.

Sounds good. Thanks.

Hi, any updates to this issue yet ?

@chiraagbangera

We are in process of investigation and will get back to you in a while. Please give us some time.

Thanks @asad.ali, I understand, Please prioritize this issue as it is currently a blocker for us and we are on a deadline for our product launch this month. A workaround to get it working in Unity3D is also acceptable.

@chiraagbangera

An investigation ticket as SVG-100 has been logged in our issue tracking system for your scenario. We will further look into its details and inform you as soon as it is resolved. Please give us some time.

We apologize for the inconvenience.

@asad.ali Thanks, hoping for a speedy bug fix or workaround.