Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good evening to all..

you will be thankful if you answer the question.

i am developing window application for extracting pdf..now my problem was i can't extract pages ans split ii when it was password protected.

how can we do with the help of itextsharp?

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
Posted
Updated 2-Mar-13 0:55am
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900