Private Sub splitpdf(ByVal spage As String, ByVal parts As Integer, ByVal destinationpath As String, ByVal Download_list As String) Dim reader As iTextSharp.text.pdf.PdfReader = Nothing Dim doc As iTextSharp.text.Document = Nothing Dim pdfcpy As iTextSharp.text.pdf.PdfCopy = Nothing Dim page As iTextSharp.text.pdf.PdfImportedPage = Nothing Dim pagecount As Integer = 0 Dim outfile As String = String.Empty Try reader = New iTextSharp.text.pdf.PdfReader(spage) pagecount = reader.NumberOfPages If pagecount < parts Then Throw New ArgumentException("Not enough pages in source pdf to split") Else Dim s As Integer = pagecount \ parts Dim currentpage As Integer = 1 Dim ext As String = IO.Path.GetExtension(spage) Application.DoEvents() For i As Integer = 1 To parts outfile = spage.Replace(".pdf", "") & "_" & Format(i, "000") & ".pdf" doc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(currentpage)) destinationpath = serverpath & "\" & ComboBox1.Text pdfcpy = New iTextSharp.text.pdf.PdfCopy(doc, New IO.FileStream(destinationpath & "\" & Path.GetFileName(outfile), IO.FileMode.Create)) doc.Open() page = pdfcpy.GetImportedPage(reader, currentpage) pdfcpy.AddPage(page) currentpage += 1 doc.Close() Application.DoEvents() Call feedtype(ComboBox1.Text) update_extractfiles(ComboBox1.Text, Path.GetFileName(outfile), 1, "preprocess") Next End If reader.Close() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "splitpdf") errormsg = ex.Message End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)