f



Extract some pages out of PDF in to a new PDF

Mission: To extract some pages out of a PDF and create a new PDF

Tools available: Adobe Acrobat SDK for 6.0 and .NET studio

Code written so far has been pasted below

         Dim AcroExchApp As Acrobat.CAcroApp
         Dim OldPdDoc As Acrobat.CAcroPDDoc
         Dim NewPdDoc As Acrobat.CAcroPDDoc
         Dim i As Integer
         Dim outputPageCount As Integer
         Dim inputPageCount As Integer
         AcroExchApp = CreateObject("AcroExch.App")
         OldPdDoc = CreateObject("AcroExch.PDDoc")
         NewPdDoc = CreateObject("AcroExch.PDDoc")
         i = OldPdDoc.Open("C:\CoreAPIOverview.PDF")
         AcroExchApp.Show()
         outputPageCount = NewPdDoc.GetNumPages()
         inputPageCount = OldPdDoc.GetNumPages()
         'i = OldPdDoc.DeletePages(1, inputPageCount - 1)
         'i = OldPdDoc.Save(Acrobat.PDSaveFlags.PDSaveFull, "c:\Test.Pdf")
         inputPageCount = OldPdDoc.GetNumPages()
         i = NewPdDoc.InsertPages(outputPageCount - 1, OldPdDoc, 10, 10, 0)
         outputPageCount = NewPdDoc.GetNumPages()
         i = NewPdDoc.Save(Acrobat.PDSaveFlags.PDSaveFull, "C:\Test.pdf")
         NewPdDoc.Close()
         OldPdDoc.Close()
         AcroExchApp.Exit()
         NewPdDoc = Nothing
         OldPdDoc = Nothing
         AcroExchApp = Nothing

This is VB.NET. While i can delete the unwanted pages from the old PDF 
and then save the remaining as the new PDF, the insertPages for adding 
the required pages to a new pdf doesn't work. what am i missing in this 
code. I am a newbie and i have tried googling to the max on this.

Thanks
0
Karthik
2/13/2005 1:02:56 AM
comp.text.pdf 5600 articles. 0 followers. ramon (1518) is leader. Post Follow

4 Replies
3380 Views

Similar Articles

[PageSpeed] 10

The code below works
         Dim oPDF As Acrobat.CAcroPDDoc
         Dim oPDF1 As Acrobat.CAcroPDDoc
         Dim szO As Integer

         oPDF = CreateObject("AcroExch.PDDoc")


         oPDF1 = CreateObject("AcroExch.PDDoc")
         szO = oPDF.Open("C:\CoreAPIOverview.PDF")
         szO = oPDF1.Create()
         szO = oPDF1.InsertPages(-1, oPDF, 0, 1, 1)
         oPDF1.Save(Acrobat.PDSaveFlags.PDSaveFull, "C:\TestPdf.pdf")
         oPDF1.Close()

         oPDF.Close()
         oPDF1 = Nothing

         oPDF = Nothing

The one i pasted is almost similar but i don't know why it doesn't work...

Karthik Seetharaman wrote:
> Mission: To extract some pages out of a PDF and create a new PDF
> 
> Tools available: Adobe Acrobat SDK for 6.0 and .NET studio
> 
> Code written so far has been pasted below
> 
>         Dim AcroExchApp As Acrobat.CAcroApp
>         Dim OldPdDoc As Acrobat.CAcroPDDoc
>         Dim NewPdDoc As Acrobat.CAcroPDDoc
>         Dim i As Integer
>         Dim outputPageCount As Integer
>         Dim inputPageCount As Integer
>         AcroExchApp = CreateObject("AcroExch.App")
>         OldPdDoc = CreateObject("AcroExch.PDDoc")
>         NewPdDoc = CreateObject("AcroExch.PDDoc")
>         i = OldPdDoc.Open("C:\CoreAPIOverview.PDF")
>         AcroExchApp.Show()
>         outputPageCount = NewPdDoc.GetNumPages()
>         inputPageCount = OldPdDoc.GetNumPages()
>         'i = OldPdDoc.DeletePages(1, inputPageCount - 1)
>         'i = OldPdDoc.Save(Acrobat.PDSaveFlags.PDSaveFull, "c:\Test.Pdf")
>         inputPageCount = OldPdDoc.GetNumPages()
>         i = NewPdDoc.InsertPages(outputPageCount - 1, OldPdDoc, 10, 10, 0)
>         outputPageCount = NewPdDoc.GetNumPages()
>         i = NewPdDoc.Save(Acrobat.PDSaveFlags.PDSaveFull, "C:\Test.pdf")
>         NewPdDoc.Close()
>         OldPdDoc.Close()
>         AcroExchApp.Exit()
>         NewPdDoc = Nothing
>         OldPdDoc = Nothing
>         AcroExchApp = Nothing
> 
> This is VB.NET. While i can delete the unwanted pages from the old PDF 
> and then save the remaining as the new PDF, the insertPages for adding 
> the required pages to a new pdf doesn't work. what am i missing in this 
> code. I am a newbie and i have tried googling to the max on this.
> 
> Thanks
0
Karthik
2/13/2005 2:01:23 AM
> The one i pasted is almost similar but i don't know why it doesn't work...

Let's look how it works manual. Open Acrobat and use Doc->Insert
Pages. You will get an error, because you don't have an open Doc/PDF,
where you can insert to.

In your second example you open a PDF and then you can insert. In your
first script you try to insert to nothing. So you have to include an
if statement. If the page you want to "insert" is the first (0) page,
then use pddoc.open else pddoc.insert.

HTH, Reinhard
0
ReFOB
2/15/2005 3:58:29 PM
Here is the link for you to vb.net add and delete pages from pdf. Hope this gives you a start on rasteredge page http://www.rasteredge.com/how-to/vb-net-imaging/pdf-delete/
0
lorretadt
5/20/2016 5:33:38 AM
On Friday, May 20, 2016 at 1:33:39 AM UTC-4, lorr...@gmail.com wrote:
> Here is the link for you to vb.net add and delete pages from pdf. Hope this gives you a start on rasteredge page http://www.rasteredge.com/how-to/vb-net-imaging/pdf-delete/

Here is the complaint you have earned: Don't try to sell your product by
replying to decade-old newsgroup postings.
0
rpresser
5/20/2016 3:27:18 PM
Reply: