C# iTextSharp structureTreeRoot.numTree为空
我在关闭文档时出错。从PdfCopy调用函数“FixTaggedStructure”时抛出C# iTextSharp structureTreeRoot.numTree为空,c#,pdf,itextsharp,itext,pdfa,C#,Pdf,Itextsharp,Itext,Pdfa,我在关闭文档时出错。从PdfCopy调用函数“FixTaggedStructure”时抛出 Dictionary<int, PdfIndirectReference> numTree = structureTreeRoot.NumTree; 您的源PDF是否已标记?另外,不要对整个文档使用AddDocument(),而是尝试使用AddPage()像for(var i=1;i不,它被标记了。我不认为您的代码与AddDocument调用的代码不同:for(int i=1
Dictionary<int, PdfIndirectReference> numTree = structureTreeRoot.NumTree;
您的源PDF是否已标记?另外,不要对整个文档使用
AddDocument()
,而是尝试使用AddPage()
像for(var i=1;i不,它被标记了。我不认为您的代码与AddDocument调用的代码不同:for(int i=1;我尝试调用PdfStructTreeController.checktaged()
在您的PdfReader
实例上,查看它是否返回true或false。我得到随机错误…有时我得到错误,有时PDF创建正确。错误是在关闭文档或PdfCopy时抛出的。structureTreeRoot变量为null,因此numTree为空。请向我解释此事故。问题是spo吗radic是否与特定的PDF一起使用,或者它是否总是与某些PDF一起使用,但与其他PDF一起使用?您能否提供一个您正在尝试转换的PDF示例?
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();