Solved

iTextSharp Coding error

Posted on 2010-08-13
6
376 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
Industry Leaders: 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 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

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!

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

749 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