Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

iTextSharp Coding error

Posted on 2010-08-13
6
375 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
ID: 33428005
Hi,

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

Thanks in advance.
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33429598
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
ID: 33434977
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33435131
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
ID: 33435485
Hi, Zhaolai

Thanks a lot. i solve the problem.
0
 

Author Closing Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…

828 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