Support query

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:

  1. An English version
  2. 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
  3. 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

  1. Set Position = 0 on stream — did not help.
  2. Using using statements for streams — no effect.
  3. Checked license — loaded correctly, not the issue.
  4. Locally saved the pdf and tried to reload
  5. Could open the locally saved pdf without any issue
  6. 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)

@greatstoneuk,

It seems you are encountering an issue with loading a manually generated PDF document into the Aspose.Pdf.Document object, while programmatically generated PDFs work fine. The error message “Trailer not found” suggests that there may be a structural issue with the manually generated PDF.

Here are several suggestions to troubleshoot and potentially resolve the issue:

  1. PDF Version Compatibility: The header of the failing PDF indicates it is version 1.4, while the working PDF is version 1.5. Ensure that the PDF generation process in Dynamics CRM and XperLogic is compatible with Aspose.Pdf. Check if there are any settings in the PDF generation process that can be adjusted to produce a PDF version that is more compatible.

  2. Stream Position: You mentioned setting the stream position to 0, which is correct. Ensure that this is done immediately before loading the PDF into the Aspose.Pdf.Document.

  3. Repairing the PDF: Since you can open the PDF locally, consider using the Repair method on the PDF document before loading it into the Aspose.Pdf.Document. This can help fix any structural issues.

  4. Ignore Corrupted Objects: You have already tried using the IgnoreCorruptedObjects option, which is a good approach. Ensure that this is set correctly when loading the document.

  5. Environment Differences: Since the issue does not occur on your development machine, check for any differences in the environment where the WCF service is running. This includes verifying permissions, file access, or configurations that might affect how the PDF is processed.

  6. Logging and Debugging: Implement logging to capture the byte array size and any other relevant information before loading the PDF. This can help identify if the PDF is being altered or corrupted during the process.

If these suggestions do not resolve the issue, consider reaching out to Aspose support with detailed information about the problem, including the PDF files and the environment setup.

Feel free to ask if you have more questions!

@greatstoneuk,

Thank you for reaching out. It appears you are using the Aspose.PDF API and have encountered an issue. I am moving your thread to the appropriate forum category, where one of our colleagues from the Aspose.PDF team will review your issue and assist you soon.

1 Like

@greatstoneuk
We’ve received your question and are reviewing it.
We’ll write to you as soon as we have any additional information or clarifying questions.

@amjad.sahi
Am I correct in understanding that you couldn’t reproduce the problem locally?

For the problematic scenario, can you perform a byte-by-byte comparison of what you want to write and what was actually written? That is, after writing, open the resulting file and perform a binary comparison of what was in the original stream/byte array and what was read from the written file.

@sergei.shibanov,

No, I did not evaluate or test the issue mentioned by the user. I simply reviewed the details of the scenario provided by him, and since they indicated that he is using Aspose.PDF APIs (as per his code snippet), I forwarded the matter to the Aspose.PDF category for the relevant team to review and address it.

@greatstoneuk,

This is for you, so please evaluate it and do the needful:

@amjad.sahi
I’m sorry, I really meant to make a request @greatstoneuk

@sergei.shibanov,

No worries at all, it’s absolutely fine.