迭代实例化itextsharp pdfreader

时间:2017-11-29 07:40:33

标签: vb.net pdf itext

早上好,我正在使用itextsharp开发一个pdf合并,以创建由打印机处理的sigle文件作为唯一作业。对于一些pdf(并非全部),pdfreader的实例化很慢(大约需要1分钟)。我已经测试了5.5.10版甚至第7版,但问题仍然相同(即使版本7更快一点)

Dim document As Document = New Document
Dim PdfCopy As PdfSmartCopy = New PdfSmartCopy(document, New 
FileStream(filename, FileMode.Create))
document.Open()
Dim numPdf As Integer = pdfs.Count
For intI = 0 To numPdf - 1
 strFile = pdfs(intI)
 Debug.Print(Now.ToString)
 Dim reader As PdfReader = New PdfReader(strFile) 'SLOW
 Debug.Print(Now.ToString)
 Dim pages As Integer = reader.NumberOfPages
 For intJ = 0 To pages - 1
   document.SetPageSize(reader.GetPageSizeWithRotation(1))
   Dim page As PdfImportedPage = PdfCopy.GetImportedPage(reader, intJ + 1)
   PdfCopy.AddPage(page)
 Next
 reader.Close()
 reader = Nothing
Next
document.Close()

Dim document As Document = New Document Dim PdfCopy As PdfSmartCopy = New PdfSmartCopy(document, New FileStream(filename, FileMode.Create)) document.Open() Dim numPdf As Integer = pdfs.Count For intI = 0 To numPdf - 1 strFile = pdfs(intI) Debug.Print(Now.ToString) Dim reader As PdfReader = New PdfReader(strFile) 'SLOW Debug.Print(Now.ToString) Dim pages As Integer = reader.NumberOfPages For intJ = 0 To pages - 1 document.SetPageSize(reader.GetPageSizeWithRotation(1)) Dim page As PdfImportedPage = PdfCopy.GetImportedPage(reader, intJ + 1) PdfCopy.AddPage(page) Next reader.Close() reader = Nothing Next document.Close() 任何建议将不胜感激 感谢

1 个答案:

答案 0 :(得分:1)

该示例文档SAwzwnZoiGtD.pdf(由评论中的OP提供)已损坏:其主要交叉引用部分声称它有37个条目,但该表实际上只有35个条目......

因此,iText尝试在为其实例化PdfReader时重建交叉引用。这可能是某种缓慢的原因,特别是因为PDF中存在其他奇怪的伪像,例如有一个" 0.02 w"在间接PDF对象8和9之间:

8 0 obj
<< /Type /Font /Subtype /Type1 /Name /ETI /BaseFont /Arial,Italic /Encoding 3 0 R >>
endobj
0.02 w
9 0 obj 

此类工件也会妨碍修复机制。

相关问题