首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用iTextSharp将PDFA文档连接成有效的PDFA文档

使用iTextSharp将PDFA文档连接成有效的PDFA文档
EN

Stack Overflow用户
提问于 2012-01-03 20:04:54
回答 1查看 921关注 0票数 1

我正在尝试使用iTextSharp 5.1.3将几个PDFA文档连接成一个文件,代码如下:

代码语言:javascript
复制
    Try
        Dim f As Integer = 0
        Dim outFile As String = destinationFile
        Dim document As iTextSharp.text.Document = Nothing
        Dim writer As PdfSmartCopy = Nothing
        While f < sourceFiles.Length
            ' Create a reader for a certain document
            Dim reader As New PdfReader(sourceFiles(f))

            ' Retrieve the total number of pages
            Dim n As Integer = reader.NumberOfPages
            If f = 0 Then
                document = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
                writer = New PdfSmartCopy(document, New FileStream(outFile, FileMode.Create))
                document.Open()
            End If

            Dim page As PdfImportedPage
            Dim i As Integer = 0
            While i < n
                i += 1
                page = writer.GetImportedPage(reader, i)
                writer.AddPage(page)
            End While
            Dim form As PRAcroForm = reader.AcroForm
            If form IsNot Nothing Then
                writer.CopyAcroForm(reader)
            End If
            f += 1
        End While
        document.Close()
    Catch generatedExceptionName As Exception
    End Try

如果我在Acrobat Reader X中打开任何输入文件,我会得到一条消息,告诉我它们确实是PDFA,但如果我打开上面代码创建的输出文件,就不是这样了。因此,我新创建的连接PDF文档似乎不符合PDFA。

我尝试将writer.PDFXConformance属性设置为PdfWriter.PDFA1A,但没有帮助。

有没有人知道是否有可能实现我正在尝试做的事情?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 06:53:39

在使用PDFXConformance时,还需要在writer对象上调用CreateXmpMetadata。我通常在关闭文档之前这样做,我不是100%确定它是否需要放在那里,但其他人都是这么做的。

代码语言:javascript
复制
End While
writer.CreateXmpMetadata()
document.Close()

然后,当您实例化您的写入器时,就像您所做的那样设置conformance属性:

代码语言:javascript
复制
writer = New PdfSmartCopy(document, New FileStream(outFile, FileMode.Create))
writer.PDFXConformance = PdfWriter.PDFA1A
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8712028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档