如何降低PDF内嵌重复字体

问题描述 投票:0回答:1

我所著应该工作的代码,但我有一个问题,因为当我打开这个程序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
vb.net itext
1个回答
0
投票

你抢字节完成的结果文档之前。

document已关闭后的结果PDF完成。在你的情况documentEnd 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

删除重复的字体

你说

这个过程应该说还没有一个重复的字体文件。

你的代码删除非常特定的重复字体项。无论是从您的文档删除所有,取决于他们是否全部都是特定类型的。

© www.soinside.com 2019 - 2024. All rights reserved.