我想使用itextsharp合并pdf文件。
这个问题让我在合并之前应用到单个文件的任何裁剪或旋转都被忽略了。所有的原始文件被剪切和旋转为TIFF然后转换为PDF,现在最后我试图合并它们。
我希望页面大小与添加的内容匹配,并且我已经应用了任何轮换。itextsharp合并调整大小和不旋转pdf
感谢您的帮助,
科尔宾日布鲁因
Public Function MergePDFFiles(FileList As Dictionary(Of String, String), DeleteOldFile As Boolean) As Byte()
' Public Function MergePDFFiles(FileList As Dictionary(Of String, String), DeleteOldFile As Boolean) As MemoryStream()
Dim document As New Document()
Dim output As New MemoryStream()
Try
Dim writer As PdfWriter = PdfWriter.GetInstance(document, output)
writer.PageEvent = New PdfPageEvents()
document.Open()
Dim content As PdfContentByte = writer.DirectContent
' foreach
For Each FilePath As KeyValuePair(Of String, String) In FileList
If File.Exists(FilePath.Value) Then
Dim reader As New PdfReader(FilePath.Value)
Dim numberOfPages As Integer = reader.NumberOfPages
For currentPageIndex As Integer = 1 To numberOfPages
document.SetPageSize(reader.GetPageSizeWithRotation(currentPageIndex))
document.NewPage()
' you can see iTextSharp.tutorial.01 - 0403sample
If currentPageIndex.Equals(1) Then
Dim par As New Paragraph(FilePath.Key)
Debug.Print("FilePath.Key = " & FilePath.Key)
Dim bookmark As New Chapter(par, 0) With {.NumberDepth = 0}
document.Add(bookmark)
End If
Dim importedPage As PdfImportedPage = writer.GetImportedPage(reader, currentPageIndex)
Dim pageOrientation As Integer = reader.GetPageRotation(currentPageIndex)
If (pageOrientation = 90) OrElse (pageOrientation = 270) Then
content.AddTemplate(importedPage, 0, 1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(currentPageIndex).Height)
Else
content.AddTemplate(importedPage, 1.0F, 0, 0, 1.0F, 0, 0)
End If
Next
End If
Next
Catch exception As Exception
Debug.Print("Failure")
Finally
document.Close()
End Try
If DeleteOldFile Then
'Delete(FileList)
End If
Return output.GetBuffer()
End Function
End Try
If DeleteOldFile Then
'Delete(FileList)
End If
Return output.GetBuffer()
我搜索了档案,发现了类似的答案。我承认并道歉,我不愿意偏离我得到的榜样。我只花了大约半天的时间,不知道itextsharp是以编程方式成功合并pdf的。我仍然是初学者,所以这对我来说很重要。我会研究你的解决方案。 – 2013-04-25 20:52:12