pdftk and cat command

abonsey
Member
Posts: 140
Joined: Fri May 24, 2013 5:10 pm

pdftk and cat command

Post by abonsey » Mon Mar 26, 2018 10:13 pm

I'm using pdftk elsewhere within my flows so I know it works but I'm trying to build a cat command.
The requirement is to have an input file (A.pdf) that is 100 pages long that uses the cat command to insert (B.pdf which is a single page) after every page in A.pdf before saving it out.

Is this possible? Does anybody have an example string of the cat command working?

Thanks for any help

Andrew

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Mon Mar 26, 2018 11:21 pm

The app Duplicate pages PRO can do that for you.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

abonsey
Member
Posts: 140
Joined: Fri May 24, 2013 5:10 pm

Re: pdftk and cat command

Post by abonsey » Mon Mar 26, 2018 11:49 pm

Getting an error "application not available on Switch Server"

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Tue Mar 27, 2018 6:36 am

It is using PDFToolkit to do the job so you have to have that installed. In some cases you have to tell Switch where the Pdftk files are.
Read the manual, it will tell you how to do it.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

abonsey
Member
Posts: 140
Joined: Fri May 24, 2013 5:10 pm

Re: pdftk and cat command

Post by abonsey » Tue Mar 27, 2018 3:25 pm

I already have PDFtk installed and running successfully within other flows so I know it works OK.
Any other ideas?

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Tue Mar 27, 2018 3:39 pm

In the app you can right click in the app section to the right on your screen and there select "Set path to application..." Doing so you will tell the app where it can find the pdftk.exe. And it must be pdftk server that you have on your system.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Tue Mar 27, 2018 3:53 pm

On Windows the App expect the pdftk server to be in this path: \Program Files (x86)\PDFtk Server\bin\pdftk.exe

If it is not you have to tell Switch and the App where to find it with the "Set path to application..." that you find by right clicking the app icon in the app list.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

abonsey
Member
Posts: 140
Joined: Fri May 24, 2013 5:10 pm

Re: pdftk and cat command

Post by abonsey » Thu Mar 29, 2018 6:06 pm

Trying the cat command with something like this but it fails.
A=100page PDF
B=1page PDF
Output file should have B inserted into A after EVERY page.

A="%1" B="C:\Users\switch\Desktop\Blank.pdf" cat A1-end B1 output "%2"

Any ideas why it won't work?

TIA

Arthur
Member
Posts: 93
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: pdftk and cat command

Post by Arthur » Fri Mar 30, 2018 12:33 pm

For this particular scenario we're using Quite HotFolders where it's a proverbial doddle to achieve that. You can tell it to insert a blank page at whatever intervals you want, whatever size of a blank you want, how many blanks you need etc plus so much more... Worth considering, we've been using it for years and never failed to deliver

Zoranj
Member
Posts: 105
Joined: Tue Sep 20, 2016 7:37 pm
Location: Canada

Re: pdftk and cat command

Post by Zoranj » Fri Mar 30, 2018 4:35 pm

abonsey wrote:Trying the cat command with something like this but it fails.
A=100page PDF
B=1page PDF
Output file should have B inserted into A after EVERY page.

A="%1" B="C:\Users\switch\Desktop\Blank.pdf" cat A1-end B1 output "%2"

Any ideas why it won't work?

TIA
I think it's doing exactly what you are telling it to do, your resulting PDF is probably 101 pages pdf.
Using your method, you would have to change B to 100 pages too, to get your desired result.
Knowing this you can either split your pdf and try to merge it with injected page, or pre-create B with different page counts and pick one to merge at appropriate time, or use some app, like Jan's suggestion, or Arthur's suggestion...
I am sure there are other methods, but this should be enough for you to figure it out.

PBMY_Vincent
Newbie
Posts: 6
Joined: Thu Aug 16, 2012 11:49 am

Re: pdftk and cat command

Post by PBMY_Vincent » Fri Jan 22, 2021 12:24 pm

Hi Peeps,

I too face this similar issue, but with the [shuffle] command. Running the command at command prompt does work.

Below is the setting i use, the job end up in problem folder due to exit code = 1 :

Name Execute command
Description
Execution mode Concurrent
Command or path C:/Program Files (x86)/PDFtk Server/bin/pdftk.exe
Arguments A="C:\Switch-Template\playingCardFront_v01.pdf" B="%1" shuffle A B output "%2"
Output File at path
Copy input job Yes
Output extension Automatic
Fail if exit code is Nonzero
Fail if stdout contains
Fail if stderr contains


Thanks in advance!

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Fri Jan 22, 2021 12:27 pm

Please use the app Execute Command Friend and make a command file to use instead. In your case a Bat-file.

It will make it work for you.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

PBMY_Vincent
Newbie
Posts: 6
Joined: Thu Aug 16, 2012 11:49 am

Re: pdftk and cat command

Post by PBMY_Vincent » Sun Jan 24, 2021 11:48 am

Bummer! I'm stuck with switch v12, so no Appstore for me.

I've try to create a script package to execute the command but end up with exit code ="-1"

Still pondering what did wrong.

*playingCardFront_v01.pdf is store at the same location as PDFtk.exe

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	//pdftk A=fronts.pdf B=back_x1500.pdf shuffle A B output print_job.pdf
	var jobFolder = job.createPathWithName(job.getNameProper(), true);	
	var pdfFilename = jobFolder + "/" + job.getNameProper() + ".pdf";
	s.log(1, pdfFilename);
	var appPath = "C:\\Program Files (x86)\\PDFtk Server\\bin\\pdftk";
	var fronts = "playingCardFront_v01.pdf";
	var backs = job.getName();
	command = appPath+" "+"A="+fronts+" "+"B="+backs+" shuffle A B "+" output "+pdfFilename;
	var exitCode = Process.execute(command);
	s.log(1, command);
	s.log(1, exitCode);
}



freddyp
Advanced member
Posts: 576
Joined: Thu Feb 09, 2012 3:53 pm

Re: pdftk and cat command

Post by freddyp » Mon Jan 25, 2021 2:31 pm

Version 12 est ex Medio Aevo, sic ego respondebit in latinum. Variabilis "backs" est solum nomen (job.getName()), sed debet esse completum viam (job.getPath()). Non oblivisci notas!!

Code: Select all

"B='"+backs+"' shuffle ...

jan_suhr
Advanced member
Posts: 408
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: pdftk and cat command

Post by jan_suhr » Mon Jan 25, 2021 2:45 pm

Here is an BAT-file example on how to run pdftk from the Execute Command.

Play around with it. The B-file has to be in a specific folder in this case and you have to setup the Switch flow to put that copy in a folder and rename it before it ends up in that folder.

Code: Select all

set inputfile=%1
set outfile=%2
pdftk.exe A=%inputfile% B="C:\for_switch\insert_first_page\background.pdf" cat B1 A1-end output %outfile%
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

Post Reply