Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...