Reputation: 1328
I'm trying to concatenate several PDFA documents into one file using iTextSharp 5.1.3 using the following code:
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
If I open any of the input files in Acrobat Reader X I get a message saying that they are indeed PDFA, but not if I open the output file that the code above creates. So it would seem that my newly created concatenated PDF document doesn't conform to PDFA.
I've tried setting the writer.PDFXConformance property to PdfWriter.PDFA1A but that doesn't help.
Does anyone know if it is possible to achieve what I'm trying to do?
Upvotes: 1
Views: 952
Reputation: 55427
When using PDFXConformance
you also need to call CreateXmpMetadata
on the writer
object. I usually do that right before closing the document, I'm not 100% certain it needs to go there but that's where everyone else puts it.
End While
writer.CreateXmpMetadata()
document.Close()
Then when you instantiate your writer set the conformance property just as you were:
writer = New PdfSmartCopy(document, New FileStream(outFile, FileMode.Create))
writer.PDFXConformance = PdfWriter.PDFA1A
Upvotes: 1