PDF文件合并问题,求解决
Public Function Merge_PDF(ByVal vF1 As MemoryStream, ByVal vF2 As MemoryStream) As MemoryStream
Dim mst As New MemoryStream
Try
Dim doc As New iTextSharp.text.Document
Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, mst)
doc.Open()
Dim cb As iTextSharp.text.pdf.PdfContentByte = writer.DirectContent
Dim page As iTextSharp.text.pdf.PdfImportedPage
Dim reader As iTextSharp.text.pdf.PdfReader
Dim numberOfPages As Integer
Dim currentPageNumber As Integer
Dim rotation As Integer
vF1.Position = 0
vF2.Position = 0
reader = New iTextSharp.text.pdf.PdfReader(vF1)
numberOfPages = reader.NumberOfPages
currentPageNumber = 0
Do While (currentPageNumber < numberOfPages)
currentPageNumber += 1
'doc.SetPageSize(PageSize.letter)
doc.NewPage()
page = writer.GetImportedPage(reader, currentPageNumber)
rotation = reader.GetPageRotation(currentPageNumber)
If (rotation = 90) Or (rotation = 270) Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(currentPageNumber).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
Loop
reader = Nothing
reader = New iTextSharp.text.pdf.PdfReader(vF2)
numberOfPages = reader.NumberOfPages
currentPageNumber = 0
Do While (currentPageNumber < numberOfPages)
currentPageNumber += 1
'doc.SetPageSize(PageSize.letter)
doc.NewPage()
page = writer.GetImportedPage(reader, currentPageNumber)
rotation = reader.GetPageRotation(currentPageNumber)
If (rotation = 90) Or (rotation = 270) Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(currentPageNumber).Height)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
Loop
'Loop
doc.Close()
doc.CloseDocument()
reader.Close()
writer.Close()
Catch ex As Exception
Response.Write("PDF Merge Fail : " & ex.Message.ToString)
End Try
Return mst
End Function
为何该段代码执行完后mst无结果,求指教 --------------------编程问答-------------------- 我不能指出代码错误哈,但是我觉得你可以看一下这个open source 代码,应该可以让文章作者帮你看一哈
http://www.codeproject.com/Articles/28283/Simple-NET-PDF-Merger
另外,我想问下,PDF merge 这个功能是不是应该是PDF reader的一部分哇?
补充:.NET技术 , VB.NET