Solved

iTextSharp Coding error

Posted on 2010-08-13
6
372 Views
Last Modified: 2013-11-13
Hi, Experts

I would like to use this code in my program but i get attached error:-
Any one can help me so that i can modified the code and can be used in my program. Below is the original code.


''' <summary>

    ''' Extract selected pages from a source pdf to a new pdf

    ''' </summary>

    ''' <param name="sourcePdf">the full path to source pdf to a new pdf</param>

    ''' <param name="pageNumbersToExtract">the page numbers to extract (i.e {1, 3, 5, 6})</param>

    ''' <param name="outPdf">The full path for the output pdf</param>

    ''' <remarks>The output pdf will contains the extracted pages in the order of the page numbers listed

    ''' in pageNumbersToExtract parameter.</remarks>

    Public 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

        Try

            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))

            doc.Open()

            For Each pageNum As Integer In pageNumbersToExtract

                page = pdfCpy.GetImportedPage(reader, pageNum)

                pdfCpy.AddPage(page)

            Next

            doc.Close()

            reader.Close()

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

Open in new window

iTextSharp-error-modified.bmp
0
Comment
Question by:chkueh
  • 4
  • 2
6 Comments
 

Author Comment

by:chkueh
Comment Utility
Hi,

The attached file with red circle is the error that i get.

Thanks in advance.
0
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
1. The first error: replace (2) with New Integer(){2}.
 2. Be sure to download the latest iTextSharp. I just downloaded the dll and add the reference, and I do not see these issues.
 BTW, are you using VB 2003, VB 2005, VB 2008 or VB 2010? I tested in both VB 2008 and VB 2010.
0
 

Author Comment

by:chkueh
Comment Utility
Hi, Zhaolai

i using VB 2003. the dll that i use is version 1 which is the earlier 1. previously i download version 5 then i get error as my previous question. May i know which version are u download?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
Comment Utility
I just tried version 0.01, 0.02, 0.03, and 0.04. They all did not work. I got same errors.
But when I tried v3.0.0, it worked. Apparently those functions are not available until version 3.0.0.
Please download version 3.0.0 and try it. Hopefully it will work for you.


0
 

Author Comment

by:chkueh
Comment Utility
Hi, Zhaolai

Thanks a lot. i solve the problem.
0
 

Author Closing Comment

by:chkueh
Comment Utility
Good teacher...very patient to solve the problem with his testing and prove.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about a problem I had getting the GPS LocationListener working.
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now