Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

iTextSharp Coding error

Posted on 2010-08-13
6
Medium Priority
?
381 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
Zhaolai earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

610 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