Cross reference table is split into separate subsections

We get a problem in signing a PDF generated with Aspose.PDF.

The problem is caused by an error in the PDF generated by Aspose.PDF: The cross reference table of the initial revision in a PDF must not be split into separate subsections but PDF generated by Aspose.PDF do split it.

The details are described here: java - PAdES LTV signing of a PDF/A-3A document yields invalid signature - Stack Overflow

@studs0815

The archive contains 3 PDF files and two of them are created using Aspose.PDF for .NET 21.3. We also checked the related post on stackoverflow but could not find the code snippet which was used to save/generate these documents in the first place. Please share how you are creating the document using Aspose.PDF for .NET after which the issue is occurring. Also, please share the sample certificate file which was used to sign the document. We will test the scenario in our environment and address it accordingly.

Hi there,

Attached an Example FileTest_Produkt_Service_contract.pdf (262.7 KB)

Here the way we genereate the pdf documents:

public static byte[] ConvertWordFileToPdfA(byte[] wordFile) {
return ConvertWordFileToPdf(wordFile)
.OnSuccess(ConvertPdfFileToPdfA).Value;
}

public static Result<byte[]> ConvertWordFileToPdf(byte[] wordFile) {
if (wordFile == null) {
throw new ArgumentNullException(nameof(wordFile));
}

        using (MemoryStream stream = new MemoryStream(wordFile)) {
            Document wordDocument = new Document(stream);

            using (MemoryStream pdfDocument = new MemoryStream()) {
                wordDocument.Save(pdfDocument, SaveFormat.Pdf);
                pdfDocument.Flush();
                pdfDocument.Position = 0; 
                return Result.Ok(pdfDocument.ToArray());
            }
        }
    }
	
	
	
	
	  public static Result<byte[]> ConvertPdfFileToPdfA(byte[] pdfFile) {
        if (pdfFile == null) {
            throw new ArgumentNullException(nameof(pdfFile));
        }

        using (MemoryStream stream = new MemoryStream(pdfFile)) {
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(stream);

            //Der Log-Stream wird nicht benötigt.
            using (MemoryStream logStream = new MemoryStream()) {
                //konvertieren
                document.Convert(logStream, Aspose.Pdf.PdfFormat.PDF_A_3A, Aspose.Pdf.ConvertErrorAction.Delete);
            }

            using (MemoryStream pdfStream = new MemoryStream()) {
                document.Save(pdfStream);
                return Result.Ok(pdfStream.ToArray());
            }
        }
    }

@nowhowmartin

Thanks for sharing the sample PDF and code snippet.

The PDF you shared seems like the final output. Please also share the same PDF that you achieve after converting from Word and before converting to PDF/A. Furthermore, as per your understandings, the issue is occurring when you sign the PDF document. Please share the way how you are signing the document so that we can proceed further with the investigation.

Hi there,

Informatione how the signing is done are available under : java - PAdES LTV signing of a PDF/A-3A document yields invalid signature - Stack Overflow

Attached the pdf before convertingtest.pdf (86.2 KB)

@nowhowmartin

An investigation ticket as PDFNET-50579 has been logged in our issue tracking system for this scenario. We will look into its details and let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any news on this issue ?

@nowhowmartin

The ticket was recently logged in our issue management system and it is pending for a review. We will surely investigate and resolve it on a first come first serve basis and let you know once we make some definite progress towards its rectification. Please spare us some time.

We are sorry for the inconvenience.

Any news on this issue ?

@nowhowmartin

We would like to share with you that the ticket has been resolved. We have changed the code snippet as below in order to generate a correct document and we hope it may help you as well:

[Test(Description = "Cross reference table is split into separate subsections")]
public void PDFNET_50579()
{
    string inFile = dataDir + "test.pdf";
    string outFile = dataDir + "test_out.pdf";
    using (var fs = new FileStream(inFile, FileMode.Open))
    {
        var pdfFile = new byte[fs.Length];
        fs.Read(pdfFile, 0, (int)fs.Length);
        var convertedPdfA = ConvertPdfFileToPdfA(pdfFile);
        using (var fsConverted = new FileStream(outFile, FileMode.Create))
        {
            fsConverted.Write(convertedPdfA, 0, convertedPdfA.Length);
        }
    }
}
public static byte[] ConvertPdfFileToPdfA(byte[] pdfFile)
{
    if (pdfFile == null)
    {
        throw new ArgumentNullException(nameof(pdfFile));
    }
    using (MemoryStream stream = new MemoryStream(pdfFile))
    {
        var document = new Aspose.Pdf.Document(stream);
        //Der Log-Stream wird nicht benötigt.
        using (MemoryStream logStream = new MemoryStream())
        {
            //konvertieren
            document.Convert(logStream, Aspose.Pdf.PdfFormat.PDF_A_3A, Aspose.Pdf.ConvertErrorAction.Delete);
        }
        using (MemoryStream pdfStream = new MemoryStream())
        {
            document.IsXrefGapsAllowed = false;
            document.Save(pdfStream);
            return pdfStream.ToArray();
        }
    }
}

Main difference is the use of the property: IsXrefGapsAllowed = false, before saving. Please note that when the document is converted, the signatures would be broken which is expected behavior.