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.

Mon Dec 07, 2020 10:29 am

Hello,
In our mvc asp.net application on Azure we use 6.5.15 (professional) SprePdf.
When we try to open large file (27 pages) 4 MB we receive exception ..

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Spire.Pdf.Exceptions.PdfDocumentException: Invalid/Unknown/Unsupported format
at spr?.?(Int32 A_0)
at spr?.?(String A_0)
at spr?.?(Dictionary`2 A_0, spr? A_1)
at spr?.?(Stream A_0, Boolean A_1)
at spr?..ctor(Stream A_0)
at Spire.Pdf.PdfDocument..ctor(Stream stream)
at Billennium.Spire.SpirePdfFactory.Create(Stream stream) in E:\agent\wd\3\s\Billennium.Spire\SpirePdfFactory.cs:line 32


But when we check it on local development environment it work but we notice (catched) exception :
System.Text.DecoderFallbackException: 'Unable to translate bytes [ED][96] at index 2 from specified code page to Unicode.'

mscorlib.dll!System.Text.UTF8Encoding.GetChars(byte* bytes, int byteCount, char* chars, int charCount, System.Text.DecoderNLS baseDecoder) Unknown
mscorlib.dll!System.Text.DecoderNLS.Convert(byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed) Unknown
mscorlib.dll!System.Text.DecoderNLS.Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed) Unknown
System.Xml.dll!System.Xml.XmlTextReaderImpl.GetChars(int maxCharsCount) Unknown
System.Xml.dll!System.Xml.XmlTextReaderImpl.ReadData() Unknown
System.Xml.dll!System.Xml.XmlTextReaderImpl.SwitchEncoding(System.Text.Encoding newEncoding) Unknown
System.Xml.dll!System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(bool isTextDecl) Unknown
System.Xml.dll!System.Xml.XmlTextReaderImpl.Read() Unknown
System.Xml.dll!System.Xml.XmlLoader.Load(System.Xml.XmlDocument doc, System.Xml.XmlReader reader, bool preserveWhitespace) Unknown
System.Xml.dll!System.Xml.XmlDocument.Load(System.Xml.XmlReader reader) Unknown
System.Xml.dll!System.Xml.XmlDocument.Load(System.IO.Stream inStream) Unknown
Spire.Pdf.dll!spr᝟.ᜀ() Unknown
Spire.Pdf.dll!spr᝟.spr᝟(sprᣃ A_0, sprប A_1) Unknown
Spire.Pdf.dll!sprᣃ.ᜁ() Unknown
Spire.Pdf.dll!sprᣃ.ᜀ(System.IO.Stream A_0, bool A_1) Unknown
Spire.Pdf.dll!Spire.Pdf.PdfDocument.PdfDocument(string filename) Unknown
Billennium.Spire.dll!Billennium.Spire.SpirePdfFactory.Create(string filePath) Line 48 C#


So it work without debuging correct.

When we try to open those pdf with simple console app it work good without throwing internal exceptions at all.

So it seams that:
1. On Azure application will crash
2. On local IIS it work but internal exception is throw and catch.
3. On console app it work good.

May be 1 and 2 situations wasn't caused by the same problem ?

Please help, how we can fix it?

Best regards
Dariusz Arendarski

P.S. We have done test on version 4.8 ...problem still exist, but when we generate again document (using PdfDocument.MergeFiles(streams) 4.8) problem disappear (all works ok).
So it seem that problem is in PdfDocument.MergeFiles

d.arendarski
 
Posts: 10
Joined: Mon Dec 07, 2020 10:13 am

Tue Dec 08, 2020 6:57 am

Hello,

Thanks for your inquiry.
According to your description, I did an initial test on console app, local IIS and Azure, but did not encounter the issue you mentioned. To help us investigate it more accurately, please provide your full test code (including merging files), your input files that could reproduce your issue. You could send them to us ([email protected]) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Dec 08, 2020 11:34 am

Hello,

Thanks for your answer. We have changed version to 6.8.5 and for our case problem has gone.
But when we enlarge files size, problem occur again. When we add about 5 MB files (all merged files) PdfDocument.MergeFiles crash with similar call stack.
When we use a little less size crash occur when we try to open file created with PdfDocument.MergeFiles by PdfDocument.PdfDocument(string filename).

Is it posible that this error is caused by out of memory or other resource error ?

Spire.Pdf.Exceptions.PdfDocumentException: Invalid/Unknown/Unsupported format
at spr?.?(Int32 A_0)
at spr?.?(String A_0)
at spr?.?(Dictionary`2 A_0, spr? A_1)
at spr?.?(Stream A_0, Boolean A_1)
at spr?..ctor(Stream A_0)
at Spire.Pdf.PdfDocumentBase.?(Stream[] A_0)
at Billennium.Spire.PdfFormsAccessService.MergeAndSave(Stream[] streams, Stream outputStream) in E:\agent\wd\3\s\Billennium.Spire\PdfFormsAccessService.cs:line 320
at DataSourcePlugins.GenerateDocumentForClient.GenerateDocumentPlugin.MergeAttachmentsAndUploadFile(String fullFileName, IEnumerable`1 attachmets, Stream inputStream) in

We will check it in newest version and if it not helps we will prepare minimal app to send to You.

Best reagards
Dariusz Arendarski

d.arendarski
 
Posts: 10
Joined: Mon Dec 07, 2020 10:13 am

Wed Dec 09, 2020 7:04 am

Hello,

Thanks for your feedback.
We're sorry that we can't give you an accurate answer about the cause of this problem based on currently available information. We need more information for further investigation.
I will wait for your further test results.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Dec 15, 2020 1:59 pm

Hello,

So, we have work around. We notice that problem exist if we try to open PDF size exactly greater than 4MB (azure blob block size ?).

using (var memoryStream = new MemoryStream())// Workaround of problem in azure client collaboration with SpirePdf for large files > 4MB
{
stream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return new PdfDocument(memoryStream);
}

Stream that we use is from CloudBlob.OpenRead(). We test sequence read streams Azure and memory copy and all have the same size and check sum. May be something wrong happens when stream is read with Seek over 4 MB block ?
Best regards
Dariusz Arendarski

d.arendarski
 
Posts: 10
Joined: Mon Dec 07, 2020 10:13 am

Wed Dec 16, 2020 10:28 am

Hello,

Thanks for your feedback.
I tried the following code on Azure to simulate your scenario but did not encounter any issue.
Code: Select all
            using (var memoryStream = new MemoryStream())
            {
                FileStream stream = new FileStream(Server.MapPath("test1.pdf"), FileMode.Open);//This file exceeds 4M
                stream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                return new PdfDocument(memoryStream);
            }

Please try to use the following code to write the stream directly to a PDF file, if the generated PDF file has errors or can't be opened normally, I'm afraid that your issue is related to your input stream itself but not our product.
Code: Select all
            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                byte[] fileBytes = memoryStream.ToArray();
                FileStream fileStream = new FileStream("result.pdf", FileMode.Create, FileAccess.ReadWrite);
                fileStream.Write(fileBytes, 0, fileBytes.Length);
            }


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF