Removing a page from a PDF and saving in VB.NET

How would I remove the first page from a PDF and then save it with the page removed?
Mike MillerSoftware EngineerAsked:
Who is Participating?
Mike MillerSoftware EngineerAuthor Commented:
Ok. Using this....
    Public Overloads Shared Sub ExtractPdfPage(ByVal sourcePdf As String, ByVal pageNumbersToExtract As Integer(), ByVal outPdf 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
            reader = New iTextSharp.text.pdf.PdfReader(sourcePdf)
            doc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
            pdfCpy = New iTextSharp.text.pdf.PdfCopy(doc, New IO.FileStream(outPdf, IO.FileMode.Create))
            For Each pageNum As Integer In pageNumbersToExtract
                page = pdfCpy.GetImportedPage(reader, pageNum)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

Open in new window

I can call with this
ExtractPdfPage(f, {2, 3}, strNewFile)
and it works fine.

If I do something like

dim strPages
strPages = "2, 3"
ExtractPdfPage(f, {strPages}, strNewFile)

The file is corrupted. How can I do this so the second method works?
Mike MillerSoftware EngineerAuthor Commented:
NM. Got it. Just used a list of integer to pass. THanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.