Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jul 14, 2021 7:25 am

Hello guys, got a exception on loading xps doc from stream.
One solution so far is to save the file to the temp folder and open it from there. (This way i don't like.)

.NET5.0 / WIN 10 / VS19

ERROR
Exeption ausgelöst: "sprᜋ" in Spire.Pdf.dll
"RRX.exe" (CoreCLR: clrhost): "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.2\System.Reflection.Metadata.dll" geladen.
"RRX.exe" (CoreCLR: clrhost): "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.2\System.Collections.Immutable.dll" geladen.
"RRX.exe" (CoreCLR: clrhost): "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.2\System.IO.MemoryMappedFiles.dll" geladen.
sprᜋ: Zip exception.Can't locate end of central directory record. Possible wrong file format or archive is corrupt.
at Spire.Compression.Zip.ZipArchive.Open(Stream stream, Boolean closeStream)
at sprᢱ.ᜀ(Stream A_0, PdfConformanceLevel A_1)
at Spire.Pdf.PdfDocument.LoadFromXPS(Stream xpsStream)
at RRX.Canvas.SchemaCanvas.Print_Executed(Object sender, ExecutedRoutedEventArgs e) in Schema\SchemaCommands.cs:line 705

CODE

MemoryStream _streamDoc = new MemoryStream();
System.IO.Packaging.Package _package = System.IO.Packaging.Package.Open(_streamDoc, FileMode.Create, FileAccess.ReadWrite);
XpsDocument _doc = new XpsDocument(_package);
XpsDocumentWriter _writer = XpsDocument.CreateXpsDocumentWriter(_doc);

_writer.Write(this);
_doc.Close();

Spire.Pdf.PdfDocument docPDF = new Spire.Pdf.PdfDocument();
docPDF.LoadFromXPS(_streamDoc);

matthiasART
 
Posts: 2
Joined: Thu Dec 24, 2020 1:36 pm

Wed Jul 14, 2021 10:30 am

Hello,

Thanks for your inquiry!

I simulated an XPS file and did an initial test in .NET 5.0 application with the latest Spire.PDF for NET version 7.6.15, but did not reproduce your issue. If you were not using the latest version, I just recommend that you can try it first.

If the issue still exists after you trying the latest version, to help further look into your issue, please share us with your input XPS file, you can also send it to us via email ([email protected]). Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Jul 14, 2021 10:49 am

Thanks for the fast reply.

already using 7.6.15




XPS doc attached.

matthiasART
 
Posts: 2
Joined: Thu Dec 24, 2020 1:36 pm

Thu Jul 15, 2021 7:49 am

Hello,

Thanks for sharing more information!

I have reproduced your issue and logged it in our issue tracking system with the ticket SPIREPDF-4468for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Jul 16, 2021 11:37 am

Hello,

Thanks for your waiting.

After further investigate your code in .NET 5, we found that under the .NET 5 target framework, the MemoryStream returned an empty stream after writing the XPS document to the XpsDocument. Our Spire.PDF can only read the data in the memory stream, if the memory stream is empty, we cannot load it to the PdfDocument.

empty.png

Since the issue is caused by the .Net 5 framework, I am afraid that there is nothing that our product can make adjustment. Hope you can understand.

Here I also provide you with other solutions:
1. Directly transfer the XPS file stream or file bytes to the PdfDocument by PdfDocument.LoadFromXPS(Stream) or PdfDocument by PdfDocument.LoadFromXPS(Bytes)
2. Change the target framework of your project to .NET Framework 4.XX

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF