Hello I have support query and wondering if this is the right way to post it.
I have simplified our process to explain the problem:
We store PDF documents in our Document Management System (iShare). These PDFs are programmatically generated: first, we create a Word document using XperLogic’s SmartFlows, then convert it to PDF using Aspose. For each document, we maintain:
- An English version
- A Welsh version
The Aspose-related code is implemented in a WCF service, and its methods are executed via a plugin step. There are no issues with iShare, Dynamics CRM 2016, Welsh Content , or the plugin itself. I suspect the issue may be related to the Aspose .pdf.DLL.
Current implementation in WCF:
• Download the document contents into a byte[]
• Create a MemoryStream from the byte array
• Load the stream into an Aspose.Pdf.Document object
Observations:
• English version works fine.
• Welsh version works fine when generated programmatically.
• Issue arises when business users manually generate a new Word document via Dynamics CRM 2016 → XperLogic SmartFlows → do some changes (or don’t) → Save as PDF → Replace the existing PDF in iShare.
After this manual process:
• Downloading the new PDF into a byte[] and creating a MemoryStream
• Attempting to load it into Aspose.Pdf.Document fails with:
Aspose.Pdf.InvalidPdfFileFormatException: Trailer not found
Interestingly, this works fine on my development machine (both debug and release modes) but fails when run from the WCF service. I have confirmed that the Aspose.Pdf.dll versions are identical across environments (25.9.0)
My findings - PDF Header/Tail Inspection
Programmatic PDF (works):
Encoding.ASCII.GetString(ct.DocBodyBytes.Take(8).ToArray());
Header “%PDF-1.5”
Encoding.ASCII.GetString(ct.DocBodyBytes.Skip(Math.Max(0, ct.DocBodyBytes.Length -30)).ToArray());
Footer “R>>\r\nstartxref\r\n84151\r\n%%EOF\r\n”
Manual PDF (fails):
Encoding.ASCII.GetString(ct.DocBodyBytes.Take(8).ToArray());
Header “%PDF-1.4”
Encoding.ASCII.GetString(ct.DocBodyBytes.Skip(Math.Max(0, ct.DocBodyBytes.Length -30)).ToArray());
Footer “] >>\r\nstartxref\r\n357376\r\n%%EOF”
Both header and footer look ok to me.
Attempts to Fix / Workarounds
- Set Position = 0 on stream — did not help.
- Using using statements for streams — no effect.
- Checked license — loaded correctly, not the issue.
- Locally saved the pdf and tried to reload
- Could open the locally saved pdf without any issue
- Attempted TolerateCorruptedPDFs — not available in 25.9, not deducible.
Code snippet - highilghted line is failing
Attempt #1
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.PDF.NET.lic”);
Stream aisDocumentStream = new MemoryStream(verifiedBytes);
if (aisDocumentStream.Length > 0)
{
aisDocument = new Aspose.Pdf.Document(aisDocumentStream)
}
Attempt #2
if (aisDocumentStream.Length > 0)
{
aisDocument = new Aspose.Pdf.Document(aisDocumentStream) { IgnoreCorruptedObjects = true };
}
Attempt #3
string uniqueId = Guid.NewGuid().ToString(“N”);
string filePath = $@“C:\Temp\Report_{DateTime.Now:yyyyMMdd_HHmmss}_{uniqueId}.pdf”;
File.WriteAllBytes(filePath, ct.DocBodyBytes);
var doc = new Aspose.Pdf.Document(filePath);
doc.Repair();
doc.Save(filePath, Aspose.Pdf.SaveFormat.Pdf);
byte[] verifiedBytes = File.ReadAllBytes(filePath);
aisDocumentStream = new MemoryStream(verifiedBytes);
if (aisDocumentStream.Length > 0)
{
aisDocument = new Aspose.Pdf.Document(aisDocumentStream) { IgnoreCorruptedObjects = true };
}
Attempt #4
string uniqueId = Guid.NewGuid().ToString(“N”);
string filePath = $@“C:\Temp\Report_{DateTime.Now:yyyyMMdd_HHmmss}_{uniqueId}.pdf”;
File.WriteAllBytes(filePath, ct.DocBodyBytes);
aisDocument = new Aspose.Pdf.Document(filePath);
This Topic is created by amjad.sahi using Email to Topic tool.
Sample Document.pdf (352.6 KB)