Solved

iTextSharp Coding error

Posted on 2010-08-13
6
373 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
A short article about problems I had with the new location API and permissions in Marshmallow
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…
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…

930 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

14 Experts available now in Live!

Get 1:1 Help Now