Page 1 of 1

A script to create a text file from job-folder information

Posted: Mon Oct 01, 2012 2:45 pm
by JimmyHartington
Hi



I have a scripting challenge.



My goal is to insert bookmarks into a pdf, which have been merged by Switch. Before the merge, the pdf-files are a job-folder.



To insert the bookmarks I plan to use Coherent PDF (www.coherentpdf.com/). This program can insert bookmarks based on a text-file, which could look like this:

0 "First chapter" 1

0 "Second chapter" 11

0 "Last chapter" 42



The 0 defines the level. The text inside "" the name of the bookmark and the last number is to which page number the bookmark has as destination.



My resulting file should then be one pdf, where the bookmarks destination are the first page of each individual file before the merge.

In this example my starting files are named:

001-First chapter.pdf (pagecount 10)

002-Second chapter.pdf (pagecount 31)

003-Last chapter.pdf (pagecount 46)



I can do a bit of javascript, so I think I have an idea of how it should work, but just not how to write the code. Let my try to explain.

The script should look at the pdfs in the job-folder. Loop through all of them to create a text file, where each pdf creates a new line.

The first line should be like:

0 "[Job.NameProper:After=-]" 1



Second line, where the number should be replaced with the pagecount of the first-file +1:

0 "[Job.NameProper:After=-]" number



Third line, where the number should be replaced with the number from the second line + the second files pagecount:

0 "[Job.NameProper:After=-]" number



And it should go through all the files in the job-folder.



So in my example the resulting text file should look like this.

0 "First chapter" 1

0 "Second chapter" 11

0 "Last chapter" 42



The text-file should the be saved with the job-folder name.



Later on I would then use the execute command to make Coherent PDF add to bookmarks to my file from the created text-file.



I have looked at the forum and made a script, which just creates a single text-file of each pdf, but there are no adding up of the pagecount.

I used this as the source of the script: http://www.crossroads-world.com/en/Home ... posts&t=32



I hope this makes sense and somebody can help, or then please contact me.

A script to create a text file from job-folder information

Posted: Tue Oct 02, 2012 10:48 am
by JimmyHartington
With my limited scripting skills, I would imagine creating an array based on the files in the job-folder.

So I get an array containing the Filename and one containing the pagenumber.

Then with a loop and the correct caluculation on the page number, which outputs the result to a new line in the text file.



Is this the completely wrong route?

Is it at all possible to extract the info for all files in a job-folder?

A script to create a text file from job-folder information

Posted: Tue Oct 02, 2012 2:14 pm
by dkelly
Look at the Dir and FileStatistics Javascript classes. Your code can open the directory, read file list and request FileStatistics for each PDF to obtain page counts.



Dwight Kelly

Apago, Inc.

dkelly@apago.com