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

Creating an Action Wizard Tool to Batch Replace Page(s)

New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hi all,

 

I wonder if somebody could assist me!

 

My goal:

 

I have about 750 pdf files in Folder A (Old) -  they are all named 3435.pdf, 3436.pdf, 3437.pdf etc.

 

I have the same 750 pdf files in Folder B (New) with identical names, they have been updated with new information (these files are all map images).

 

I dont want to simply overwrite the pdfs in Folder A with Folder B as I will lose all the interactive elements that I have already setup. What I want to do is use the equivalent of the Organize  Pages > Replace tool to replace 3435.pdf (Folder A) with 3435.pdf (from Folder B). Which would leave me with updated files in Folder A containing all the new map image from Folder B, but with all the interactive elements still persisting.

 

From what I understand it is not possible to do this without javascript within the action wizard, however with my little knowledge of javascript I am tripping up trying to create this tool, so far I have come up with the following code, would someone be able to shed any light on wether I am close or a million miles away from my end goal?

 

// Name of current file
var sFileName = this.documentFileName; // get the file name

// This represents Current Map.pdf
this.replacePages({
nPage: 1,
cPath: "D:\2021_Mapbook\ += sFileName", // I am trying to concatenate the current file name to the new folder path so that it will replace this pdf with the pdf  with the latest pdf of the same name
nStart: 1,
nEnd: 1
});

 

Thanks for any assistance, hopefully this makes some sense!

 

TOPICS
Edit and convert PDFs , JavaScript

Views

1.4K

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

FYI - currently when I try to run this script in the debugger window it is giving me the following error;

 

NotAllowedError: Security settings prevent access to this property or method.
Doc.replacePages:8:Document-Level:1

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

What is the path of Folder B?

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hi Bernd,

 

So I have it working for a single pdf if I provide the exact file path which would be this;

 

/* Replace Page */

var sFileName = this.documentFileName; // get the file name

// This represents Current Map.pdf
this.replacePages({
nPage: 0,
cPath: "D:\\2021_Mapbook\\3530.pdf",
nStart: 0,
nEnd: 0
});

 

But I wanted to try and have the wizard run through all the files by concatenatiing the current file name (sFileName) to the cPath, like this;

/* Replace Page */

var sFileName = this.documentFileName; // get the file name

// This represents Current Map.pdf
this.replacePages({
nPage: 0,
cPath: "D:\\2021_Mapbook\\+=sFileName",
nStart: 0,
nEnd: 0
});

 

this gives me an error;


RaiseError: This file cannot be found.
Doc.replacePages:10:Batch undefined:Exec
===> This file cannot be found.

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

D:\\2021_Mapbook\\ is the path to folder B

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Use this:

"D:\\2021_Mapbook\\" + sFileName

 

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

So I think I have it now;

 

/* Replace Page */

var sFileName = this.documentFileName; // get the file name
var mapBook = "D:\\2021_Mapbook\\"

// This represents Current Map.pdf
this.replacePages({
nPage: 0,
cPath: mapBook + sFileName,
nStart: 0,
nEnd: 0
});

 

The only problem is after I run this wizard I get this and a blank PDF screen, if I close the pdf and open it, it seems to have done what I wanted (replace the page) but why does it give that blank screen?

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

The error causes an issue as it happens after the first pdf is replaced so it breaks out of the batch process that the wizard is trying to do (multiple pdfs)

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Dont worry, I think I figured that out, realised it was the save command as part of the wizard that was causing it so instead used javascript to save it and didnt get that issue anymore.

 

For anybody coming behind me, this was what I used to get it working (see image attachment);

 

2 seperate javascript proccesses;

 

'Main Script'

/* Replace Page */

var sFileName = this.documentFileName; // get the file name
var mapBook = "D:\\2021_Mapbook\\"

// This represents Current Map.pdf
this.replacePages({
nPage: 0,
cPath: mapBook + sFileName,
nStart: 0,
nEnd: 0
});

 

Save Script;

/* Put script title here */
this.saveAs("D:\\Mapbook_OldtoNew\\" + this.documentFileName);

 

This worked without any of the stream errors I was getting by using the built in 'Save' command in the wizard. Hope this helps someone out.

 

Thanks,

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

*** Adjustment to save - original was not preserving interactive links ***

Save Script;

/* Put script title here */

app.execMenuItem("Save");

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

LATEST

What interactive links does you mean?

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 ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Looks like there is a error in one of the files.

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