0

I'm getting an error while closing my document. It's thrown when calling the function "FixTaggedStructure" from PdfCopy

        Dictionary<int, PdfIndirectReference> numTree = structureTreeRoot.NumTree;

My debugger shows that "structureTreeRoot" is null, but I don't know why.

My code is very simple. I am trying to convert a PDF to an PDF/A-1 referring to Convert PDF to PDF/A3 or PDF/A-1 to PDF/A-3

        Document doc = new Document();
        FileStream fs = new FileStream(destPdfA, FileMode.Create);
        PdfReader reader = new PdfReader(pdfParth);
        PdfCopy copy = new PdfCopy(doc, fs);

        copy.SetPdfVersion(PdfCopy.PDF_VERSION_1_4);
        copy.SetTagged();
        copy.CreateXmpMetadata();

        doc.Open();
        ICC_Profile icc = ICC_Profile.GetInstance(new FileStream(ICM, FileMode.Open));

        PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
        outi.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
        outi.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
        outi.Put(PdfName.S, PdfName.GTS_PDFA1);

        // get this file here: http://old.nabble.com/attachment/10971467/0/srgb.profile
        PdfICCBased ib = new PdfICCBased(icc);
        ib.Remove(PdfName.ALTERNATE);
        outi.Put(PdfName.DESTOUTPUTPROFILE, copy.AddToBody(ib).IndirectReference);

        copy.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, outi);

        copy.AddDocument(reader);
        doc.Close();
Community
  • 1
  • 1
AndreasGloeckner
  • 292
  • 3
  • 5
  • 18
  • Is your source PDF tagged already? Also, instead of using `AddDocument()` with the entire document, try using `AddPage()` like `for (var i = 1; i <= reader.NumberOfPages; i++) {copy.AddPage(copy.GetImportedPage(reader, i, true));}` The last parameter of `GetImportedPage()` is `keepTaggedPdfStructure` which is false by default and I'm not sure if `AddDocument()` uses. – Chris Haas Dec 14 '15 at 13:56
  • No, it's tagged. I don't think that your code is different to the code that addDocument calls: for (int i = 1; i <= reader.NumberOfPages; i++) { AddPage(GetImportedPage(reader, i, tagged)); } This is a part of the addDocument function. – AndreasGloeckner Dec 14 '15 at 15:27
  • Try just calling `PdfStructTreeController.CheckTagged()` on your `PdfReader` instance and see if it returns true or false. – Chris Haas Dec 14 '15 at 15:49
  • I get random error...sometimes I get the error, sometimes the PDF is correctly created. The error was thrown when closing the document or closing the PdfCopy. The structureTreeRoot variable is null and so numTree is. Pls explain me this accident. – AndreasGloeckner Dec 16 '15 at 10:52
  • Is the problem sporadic with a specific PDF or does it always work with some but not others? Can you provide a sample PDF that you are trying to convert? – Chris Haas Dec 16 '15 at 14:23
  • I am using the same PDF again and again. Sometimes it works and sometimes not. – AndreasGloeckner Dec 16 '15 at 14:29
  • Could anyone try this code above? I tried this code with java, c# and another pdf document, but still get the error when trying to copy pages from one document into a new tagged one with metadata!.. – AndreasGloeckner Jan 03 '16 at 12:41

0 Answers0