• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

doc.InsertPages(0, PDDoc, i, 1, ture) always return false and fail to insert target PDF(pdf can be edit, no any protection)

New Here ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

For below spltePDF function(from Adobe forum), it works fine for most of PDFs, but for some PDF (pdf is editable, no any protection, no image) can't be inserted by .InsertPages() function and return false, but he the PDDoc2.DeletePages function works welll. who can tell why?

Function SplitPDF(MyPath As String, strFileName As String) As Integer

Dim PDDoc As Acrobat.CAcroPDDoc, newPDF As Acrobat.CAcroPDDoc
Dim PDPage As Acrobat.CAcroPDPage
Dim thePDF As String, PNum As Long
Dim NewName As String
Dim i As Integer
Dim Result As Variant
Dim Filename As String
'...

If VBA.Right(VBA.Trim(MyPath), 1) <> "\" Then
  MyPath = MyPath + "\"
End If

thePDF = MyPath & strFileName

Set PDDoc = CreateObject("AcroExch.pdDoc")

Result = PDDoc.Open(thePDF)
If Not Result Then
   MsgBox "Can't open file: " & Filename
   Exit Function
End If

'...
PNum = PDDoc.GetNumPages

For i = 0 To PNum - 1
    Set newPDF = CreateObject("AcroExch.pdDoc")
    newPDF.Create
    NewName = VBA.Left(strFileName, VBA.Len(strFileName) - 4) & "_SplitPage_" & (i + 1) & "_of_" & PNum & ".pdf"
    'newPDF.InsertPages -1, PDDoc, i, 1, 0
    'startPage, _pdDoc, startPage, numpage, 0
   
  
   If newPDF.InsertPages(0, PDDoc, i, 1, 0) = False Then
  
    Set PDDoc2 = CreateObject("AcroExch.pdDoc")
    Result = PDDoc2.Open(thePDF)
    PDDoc2.DeletePages 0, i - 1
    PDDoc2.DeletePages i + 1, PNum - 1
    PDDoc2.Save 1, MyPath & NewName
    PDDoc2.Close
    Set PDDoc2 = Nothing
   Else
   'PDDoc.Save 1, MyPath & NewName
    newPDF.Save 1, MyPath & NewName
    newPDF.Close
    Set newPDF = Nothing
    Set PDDoc = Nothing
  
   End If
  
Next i

SplitPDF = PNum

End Function

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

The parameters you're supplying to the method are incorrect. Read its documentation very carefully.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

What can you see at the properties of this documents?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2020 Nov 16, 2020

Copy link to clipboard

Copied

LATEST

I realise this is two years old now but I have the same problem. The code above seems to me to be written in accordance with the documentation. In my case, insertPages fails without inserting any pages. I'm using C# and have this:

 

var pdf = new Acrobat.AcroPDDoc();
pdf.Open(f.FullName); // some PDF file with many pages

var pdfNew = new Acrobat.AcroPDDoc();
pdfNew.Create();
pdfNew.InsertPages(1, pdf, 0, 2, 0); // tried various parameters here

Console.WriteLine(pdfNew.GetNumPages()); // always returns zero

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

Why do you post this in the forum for Acrobat Javascript? You don't use Javascript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

It is JavaScript, actually. The VBA object can execute JS code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

Actually, I think you're right. They seem to be using methods of the VBA object itself, instead of running JS code.

In that case this question should be asked over at the Acrobat SDK  forum.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines