Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

c# - ASPOSE Converting PDF to SVG via streams produces invalid results

I'm trying to convert a pdf document into svg pages. My first attempt was to load the pdf document and save it as a stream and then load that supposedly converted svg stream as a SVGDocument, this however produces a garbage object.

pageDocument.Save(ms, SaveFormat.Svg);
pageDocument.Save("temp.svg", SaveFormat.Svg);

// Object is invalid
var svgDocument1 = new SVGDocument(ms, ".");

// Create a FileStream object
using (var stream = new FileStream("temp.svg", FileMode.Open, FileAccess.Read))
{
   // Valid object
   var svgDocument2 = new SVGDocument(stream, ".");
}

By slightly modifying the code to save the pdf page as a svg image and then loading that as a file stream works perfectly, so I am not sure what is going on here.

Needles to say, I want to try and avoid creating unnecessary files just for the sake of conversion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As shared in the forum thread over the official forum, seeking the memory stream back to the beginning will resolve the issue. Please add the following line of code before loading the SVGDocument from MemoryStream:

ms.Seek(0, SeekOrigin.Begin);

We are also going to add descriptions to the API that document is processed from the current position in the stream as working with positions in streams is a regular practice described in Microsoft documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...