我所著应该工作的代码,但我有一个问题,因为当我打开这个程序maked文件的Adobe说我这是错误的。
这个过程应该说还没有一个重复的字体文件。
Using msDoc As MemoryStream = New MemoryStream()
Using document As iTextSharp.text.Document = New iTextSharp.text.Document()
Using copy As iTextSharp.text.pdf.PdfSmartCopy = New iTextSharp.text.pdf.PdfSmartCopy(document, msDoc)
document.Open()
Dim pdfReader As New iTextSharp.text.pdf.PdfReader("C:\Users\pier\Desktop\prova.pdf")
For i As Integer = 1 To pdfReader.NumberOfPages
copy.AddPage(copy.GetImportedPage(pdfReader, i))
Next
msDoc.Position = 0
System.IO.File.WriteAllBytes("C:\Users\pier\Desktop\file213.pdf", msDoc.ToArray())
End Using
End Using
End Using
document
已关闭后的结果PDF完成。在你的情况document
在End Using
隐含地关闭和您检索之前,该流的字节。此外,你玩弄msDoc.Position = 0
前的数据流位置(document
)是封闭的,所以你还导致PDF的结尾部分,以覆盖其开始...
此外,不要把PdfSmartCopy
实例为Using
线;当document
关闭这种情况下是隐式关闭,但在尝试之前关闭它。
因此,做相反:
Using msDoc As MemoryStream = New MemoryStream()
Using document As iTextSharp.text.Document = New iTextSharp.text.Document()
Dim copy As New iTextSharp.text.pdf.PdfSmartCopy(document, msDoc)
document.Open()
Dim pdfReader As New iTextSharp.text.pdf.PdfReader("C:\Users\pier\Desktop\prova.pdf")
For i As Integer = 1 To pdfReader.NumberOfPages
copy.AddPage(copy.GetImportedPage(pdfReader, i))
Next
End Using
System.IO.File.WriteAllBytes("C:\Users\pier\Desktop\file213.pdf", msDoc.ToArray())
End Using
你说
这个过程应该说还没有一个重复的字体文件。
你的代码删除非常特定的重复字体项。无论是从您的文档删除所有,取决于他们是否全部都是特定类型的。