Inserting PDF Page Range

Posted by: ontheroaderic

Inserting PDF Page Range - 12/22/14 12:34 PM

Working on a large number of product tags and I want to break the document into manage chunks for the cutter. I have a PDF with 2340 pages. I want to structure my PSM doc as follows:
Layout 1 - Divider
Layout 2 - Pages 1-300 of PDF
Layout 3 - Divider
Layout 4 - Divider
Layout 5 - Pages 301-600 of PDF

Is there a way to do this? Seems like I could add an expression to the PAGE NUMBER property of that object, but I haven't figured out what. I could also divide the PDF into 300 page chunks, but I'd still have the same issue of wanting PSM to print all 300 pages of the PDF and then the next layout. I could probably accomplish by making a PSM document with a layout for every page in the PDF but that's no fun.
Posted by: Anonymous

Re: Inserting PDF Page Range - 12/23/14 10:10 AM

ontheroaderic,

I'm not sure I understand exactly what you want to achieve.

Could you please detail more? You mentioned that your PDF has 2340 pages, yet in your layouts you stop at page no 600.

Do you need all 600 or 2340 pages per record?

Regards,
Posted by: ontheroaderic

Re: Inserting PDF Page Range - 12/23/14 10:13 AM

Sorry, should have added "and so on" there at the end . . . I want the pattern to repeat until all 2340 pages have been printed and have divider sheets every 300 pages.
Posted by: Anonymous

Re: Inserting PDF Page Range - 12/23/14 12:12 PM

ontheroaderic,

Since it seems you are not running any data file with it, then I would suggest this:

  • In Preferences, under Program, set the Items without database with the number of pages your PDF contains(2340).

  • Set the first layout to be your PDF.

  • Edit Expression Page Number. Use this number function:
    Code:
    RECORD_NR()


  • Set your second layout as a blank page or with a text object. This will be your divider, unless you have a specific page you want to display.

  • In the second layout's properties, set the action expression like this:
    Code:
    IF(MOD(RECORD_NR(),300)=0,Print,Skip)


By doing so, it will print your first 300 then a blank page, then another 300 followed by another blank page.

Hope this helps.
Regards,
JF
Posted by: Shift

Re: Inserting PDF Page Range - 05/16/21 08:04 AM

Is it possible to do this while linked to a database?

I have a folder full of PDF's that can be between 1 to 250 pages.

I have to add certain fields onto page 1, but pages 2 onward are always static.

My data includes the fields I need to add, plus the file name and total page count.

Or would the only way of doing this be to create 250 sperate print/skip layouts?
Posted by: sellis

Re: Inserting PDF Page Range - 06/10/21 12:09 PM

Set the items without database to 2340 as per PDF page count. this can be fount in the menu Edit -> Preferences, Program settings.

create All layers and from the Layout/Edit condition Menu...

Layer 1 - Divider - expression = IF(RECORD_NR() =1,Print,Skip)
Layer 2 - Pages 0001 - 0300 - expression = IF(RECORD_NR() >= 1 AND RECORD_NR()<= 300, Print,Skip)
Layer 3 - Divider - expression = IF(RECORD_NR() =300,Print,Skip)
Layer 4 - Divider - expression = IF(RECORD_NR() =300,Print,Skip)
Layer 5 - Pages 0301 - 0600 - expression = IF(RECORD_NR() >= 301 AND RECORD_NR()<= 600, Print,Skip)
Layer 6 - Divider - expression = IF(RECORD_NR() =600,Print,Skip)
Layer 7 - Divider - expression = IF(RECORD_NR() =600,Print,Skip)
Layer 8 - Pages 0601 - 0900 - expression = IF(RECORD_NR() >= 601 AND RECORD_NR()<= 900, Print,Skip)
... Continue until all pages accounted for.

On all the Layout's with 'pages xxxx-xxxx', you'll need to edit the page number expression, by right clicking on PDF in main view, selecting Edit Expression -> property 'Page Number' and setting the page number to RECORD_NR().

Once this has been setup, you can utilise over and over again just replacing each layout with the new PDF and altering the items without database to the final page quantity.

hope that helps.

Cheers
Posted by: Shift

Re: Inserting PDF Page Range - 06/16/21 06:25 AM

This works when the job is not linked to any data, is it possible to do this when linked to a database?

I have a job that has multiple PDF's of varying pages, but I only need to place personalisation on page 1.

Data example:

Filename Pages Title Surname
Doc1.pdf 200 Mr Sample
Doc2.pdf 121 Mr Sample2
Doc3.pdf 235 Mr Sample3
Doc4.pdf 86 Mr Sample4
Doc5.pdf 111 Mr Sample5

I have the filename and page count (as well as the fields I need for personalisation).

At the moment I have a document with over 300 layouts to achieve this.

If it is possible to do this with 2 layouts while linked to data (Layout 1 have the personalisation and layout 2 printing the rest of the pages, then moving onto the next record and doing the same) it would be a much simpler and safer solution to what I currently have.
Posted by: Sander vd Berg

Re: Inserting PDF Page Range - 06/19/21 08:49 AM

With two layouts:

I assume the second layout has an image with the Page Number expression set to "PAGE_NR() - 1". Select that layout and set the Number of Copies expression to "VAL([Pages])".

That should be all you need to do. The "PAGE_NR() - 1" expression is reevaluated for each layout copy.
Posted by: Sander vd Berg

Re: Inserting PDF Page Range - 06/22/21 11:58 AM

Sorry for replying to my own post. I received an email for a reply but the thread still hasn't been updated.

Thanks for pointing out what the issue is, I understand now. The expression for the image is actually the tricky part, the expression I gave only works for the first record. What you need is a running total that you can subtract from "PAGE_NR() - 1".

There are two solutions that come to mind (without altering the data):

1. Use a custom SQL query

This only works if your data has an order column. If it has an ID field that starts at 1 and increments every record you can do:

Database > Select Table > Custom (double-click)
Code:
SELECT (SELECT SUM(Pages) FROM [Test.csv] as A WHERE A.ID < B.ID) AS RunningTotal, * FROM [Test.csv] AS B


Note that the filename of the data file needs to be hardcoded (without a path). The query above assumes the filename is Test.csv.

2. Create a custom macro

Create a folder called "Macro" in the PSM installation folder (this requires admin rights) with a file (any name) with extension ".js" and the following content:

Code:
function psmGetFunctionDescriptor(index) {
    return index == 0 ? "NUMBER NUMBER RUNNING_TOTAL(NUMBER{Record},NUMBER{Pages})" : "";
}

var total = 0;

function psmRUNNING_TOTAL(record, pages) {
	if (record == 1) total = 0;
	var previous = total;
	total += pages;
	return previous;
}


You should then have access to a RUNNING_TOTAL function that you can call passing RECORD_NR() and VAL([Pages]). This only works if you are creating output starting with record 1, since that is the "reset" trigger of the running total.
Posted by: Sander vd Berg

Re: Inserting PDF Page Range - 06/22/21 12:41 PM

Ugh.. I'm really overthinking this.

PAGE_NR has an optional boolean argument that determines if it should reset after each record. So just forget my previous comment and instead of "PAGE_NR() - 1" do "PAGE_NR(True) - 1".
Posted by: Shift

Re: Inserting PDF Page Range - 06/23/21 09:36 AM

Thanks for the help.

It seems to be working fine with the SQL query, which is great.

PAGE_NR(True) doesn't seem to work however. I think it is treating each copy as a new record, so only ever print out that many copies of page 1.

Again, thanks for the macro, however i think is an issue with it.

The Macro is printing the first document fine, and page 1 of the second document fine, but then all the pages return a blank.

I noticed that when creating the expression, each change I made changes the "Expression result:". Just pressing Ctrl A or adding a space adds to the result.

I'm happy the SQL query is working, it has saved me having to create hundreds of layouts.

Again, thanks for your help.
Posted by: Sander vd Berg

Re: Inserting PDF Page Range - 06/23/21 10:08 AM

Looking over the macro I suppose if the function is called again with the same combination of values (record and pages) it should return a cached result instead of adding to the total again.

I can't explain why PAGE_NR(True) didn't work. According to the documentation it should reset after each record. If it resets after each layout copy that would be a nasty bug.

Anyway, glad the SQL worked for you!
Posted by: sellis

Re: Inserting PDF Page Range - 07/27/21 12:01 PM

Yes you can bring in a PDF dynamically.
Attach the data file which has the filename, page count and name. Also drag and drop the first PDF into the main layout.

Add further layouts to the 'layout list' to accommodate the highest PDF page count in the list of PDF files.
Set the image name by right clicking on the image in layout 1 and edit expression for image 1. Now drop the field in that contains the PDF name making sure there is the file extension '.pdf' on the end. (If the image doesn't appear, make sure the 'Image Folder' in the properties list points to the directory where the PDF files are.).

Now edit expression for each layout 'image x' dropping the PDF field name in. Now edit the 'Image x.Page number for each image in each layout and set the page number to expression 'LAYOUT_NR()' this will make sure all PDF pages are printed for each PDF.

Last part...

Edit condition for each layout to 'IF(LAYOUT_NR()<=VAL([FIELD WITH PAGE COUNT]),Print,Skip). This will stop printing the layouts that will exceed the PDF page count.

Hope that helps.