CLI - -mergeimpose

Hi,

I haven’t seen a category just for CLI, so I’m posting it here.

I was wondering if there is a more comprehensive documentation for “mergeimpose” besides what we get from “pdfToolbox --mergeimpose” list of commands.

I searched the online documentation but I only got results for things like “Add Pages” and “Split and Reorder”.

We have a new project that requires batching pdfs together then imposing them. Some of these pdfs need to be duplicated, then merged and imposed.

My boss is adamant about doing it via CLI so we can dynamically generate the imposition scheme to feed to the CLI.

I’m trying to find out if:

  1. Is mergeimpose the best option for this?
  2. Does the imposition instructions sent to mergeimpose have to be runlist + sheetconfig?
  3. I have a profile that already does the imposition we want (discussed in: Crop marks not showing if slot is empty). Is it possible to use the Javascript from this imposition with mergeimpose (instead of runshit/sheetconfig)?
  4. Then having a documentation I could follow would be very helpful.

Thanks for the help.

Hi Adrian,

In short, the command --mergeimpose is just a shortcut for --mergepdf and --impose in one call which have to be a runlist + sheetconfig. But the runlist could be also a Javascript (--impose js_booklet.runlist.js js_empty.sheetconfig 1-24_A5_1-2.pdf).

If you have already a (complex) process plan, you could also think about to use the step Add files for merging.

What is the best option is difficult to say and depends on the conditions/preferences. Can it only be one CLI call or can/must it be profile based etc.?

From the short description without data, my personal choice would be a ProcessPlan because you are more flexible in regard to change/prepare something before the final imposition. But it could become very complex. :wink:

@Rene Can --mergeimpose accept runlist.js?

Yes, because it just uses --impose internally.

Just as an administrative note - it’s totally fine to post CLI related questions here.

If there is enough demand (or desire :)) to have a separate group, I can certainly do that, but I’d like to avoid having a long list of groups without any activity!

Great, Is there an example file that gives the full runlist object schema? (excluding all the logic to build the object)

For now, only what is available in the documentation, like:

from chapter 30. Imposition

1 Like

I’m having a very difficult time converting my process plan with a script that works in Desktop version to a runlist to use with --mergeimpose.

So, I would like to start by sending an object to my process plan and use Add Pages for now. Just so I can get it running.

Is it even possible to do this? Send CLI command with a process plan (that has Add Pages as the first step), a JSON with a list of files as a variable, but no actual pdf?

The test object I have in a .json file is:

{
  "allocations": {
    "ITM_123456": 6,
    "ITM_123457": 2,
    "ITM_123458": 12
  },
  "stats": {
    "slots_per_sheet": 21,
    "cols": 7,
    "rows": 3,
    "empty_slots": 1,
    "orientation": "Landscape",
    "print_run": 417,
    "slot_efficiency": "91%",
    "print_efficiency": "95%",
    "wasted_prints": 340
  }
}

This works if I hardcode the JSON in the variable (batchData) section of the process plan.
I have a loop in Add Pages to iterate through the files:

const rootDir = "/Users/adrian/Desktop/batch-impositions/tests/pdfs/"

//const fileList = app.vars.fileList;
const batchData = app.vars.batchData;
const allocations = batchData.allocations;

for (const fileName in allocations) {
    if (Object.hasOwnProperty.call(allocations, fileName)) {
        const count = allocations[fileName];
        // Append the file 'count' number of times
        for (let i = 0; i < count; i++) {
            conf.append.push({
                // Append '.pdf' to the fileName here, as requested
                path: rootDir + fileName + '.pdf',
            });
        }
    }
}

conf;

But if I remove the hard coded variable and just create a text variable “app.requires(“batchData”,”“, “Batch Data”);”
that evaluates to a boolean


and CLI (–listvariables) doesn’t recognise any variables needed.

Any guidance would be greatly appreciated.

When you create a variable with “app.requires”, it only exists during the process plan. You’re essentially telling pdfToolbox on the fly that a variable will be needed, which causes the Desktop to ask for it if it doesn’t exist yet.

So, to have this work in the CLI, just use:

--setvariable=batchData:1

(You said boolean, so 0 or 1 are usually the safest bet). This should work.

If you want to be able to use the “listvariables” command in CLI for example to figure out what variables are needed, you need to create the simple variable in pdfToolbox Desktop and make sure it’s used in the Process Plan before you export it. (even just putting it in the description of the Process Plan would accomplish that).

Hi @AdrianC

Is it even possible to do this? Send CLI command with a process plan (that has Add Pages as the first step), a JSON with a list of files as a variable, but no actual pdf?

No, without actual PDF it is not possible but you could use a Blank.pdf and remove the first page after merging.

For the time being, I’m only concentrating on using the CLI and “Add Files” … please find below a process plan which uses your idea of loop and data:
http://www.callassoftware.com/downloads/tmp/forum_addfiles.zip

If I use the following command (please use valid path for the files):
pdfToolbox AddFiles.kfpx Blank.pdf --setvariable=BatchData_Vars.json --setvariable=rootDir:/Users/rgutschmidt/Desktop/batch-impositions/

In order to work it in Desktop as well would need further changes (or use static data inside the Variable) and I would probably provide a Variable with a path to the JSON and read the content which is always a bit complicated in pdfToolbox context. But let me know if you want to see an example.

It has left me no peace :wink: Here is an example which works in CLI and Desktop and requires 2 variables; the rootPath and the JSON file - JSON file is this time your original data and not the pdfToolbox import data syntax.

Example:
pdfToolbox AddFiles_Vars.kfpx Blank.pdf --setvariable=JSON:/Users/rgutschmidt/Desktop/batch-impositions/BatchData.json --setvariable=rootDir:/Users/rgutschmidt/Desktop/batch-impositions

http://www.callassoftware.com/downloads/tmp/forum_addfiles_var.zip

1 Like

Thank you all for your help.

I just noticed the merge process adds bookmarks to the pdf.

Is it possible to get the page index of a bookmark? In other words, is it possible to add a page to an imposition (imposition.addPage) using the bookmark to calculate the pageIndex?

I am not aware that the merging (AddFiles) adds bookmarks - a short test shows that only the bookmarks of the input PDF are present.

Anyway, the only way - I know - to work with bookmarks and get informations is the QuickCheck with the following configuration: "$.aggregated.bookmarks: true"

But even if it the case for merging, please double check if the information in the bookmarks still correct.

The merged test file I got has a bookmark for each of the pdfs that were merged:

I was curious about getting page index of a bookmark in case we run into a situation where we need to merge documents with different number of pages and need to do something to one of the merged documents after the merge. In that case, it would be easier to just get the bookmark page number to start working from that page index.

I’ll try the QuickCheck. I’ll also add this to the feature request… One can hope :slight_smile: