Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 28th, 2017, 12:15 PM
draco66 draco66 is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 70
Default Limit Pages & Odd Page Insert Blank

I have a template that basically pulls files from a library or used an uploaded file to create a new document. The code below is used to create the new document from a selection of static and uploaded files. It works fine.

What I would like to add to the code is a way to limit the number of pages that are added to the new document for any given file. For example, let say that someone uploads a document with 40 pages in it. We only want to allow up to 12 pages of any document to be included in the new composed file. So we want to allow the first 12 pages of any PDF and then disregard any pages after that.

The second thing that would be beneficial - if a file we are adding to the composed document has an odd number of pages, add a blank to make it even. That way the next document we add will not start on the back page of the previous document.

I hope that makes sense. It was harder describe than I thought.

Here is the code:

Code:
var firstPage = 'First';
var lastPage = 'Last';
var firstGraphic = 'graphic';
var lastGraphic = 'graphic_last';

var isUpload = /UPD-/.test(Field("SKU"));
var path = "c:/library/" + (isUpload ? "uploadPDF" : "staticPDF") + "/";
var fileName = (isUpload ? Field("Order Number") + "_" + Field("SKU") : Field("Product Name")) + ".pdf";
var result = [];

if(Field("SKU").match(/(_14_)/))
 {
  firstPage += 'L';
  lastPage += 'L';
  firstGraphic += '2';
  lastGraphic += '2';
}

//Print an address page at beginning of each order
if (FieldChanged("Order Number"))
{
  if (Field("Cost Center") == "102" || Field("Cost Center") == "103" || Field("Cost Center") == "104")
  FusionPro.Composition.SetBodyPageUsage("address1", true);
}
{
  if (Field("Cost Center") == "105")
  FusionPro.Composition.SetBodyPageUsage("address2", true);
}
{
  if (Field("Cost Center") == "106" || Field("Cost Center") == "107" || Field("Cost Center") == "108")
  FusionPro.Composition.SetBodyPageUsage("address3", true);
}
FusionPro.Composition.SetBodyPageUsage(firstPage, true);
FusionPro.Composition.SetBodyPageUsage(lastPage, true);
var file = CreateResource(path + fileName, 'graphic');
var pages = file.countPages;

for (var i = 1; i < pages; i++)
  (file.pagenumber = i) && result.push(file.content);

file.pagenumber = pages;
FindTextFrame(firstGraphic).content = result.join('<p>');
FindTextFrame(lastGraphic).content = file.content;
Reply With Quote
  #2  
Old November 28th, 2017, 01:16 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Limit Pages & Odd Page Insert Blank

Quote:
Originally Posted by draco66 View Post
What I would like to add to the code is a way to limit the number of pages that are added to the new document for any given file. For example, let say that someone uploads a document with 40 pages in it. We only want to allow up to 12 pages of any document to be included in the new composed file. So we want to allow the first 12 pages of any PDF and then disregard any pages after that.
You can limit the number of pages to 12 like this:
Code:
var pages = Math.min(file.countPages, 12);
That will set the 'pages' variable to the lower of the two values.
Quote:
Originally Posted by draco66 View Post
The second thing that would be beneficial - if a file we are adding to the composed document has an odd number of pages, add a blank to make it even. That way the next document we add will not start on the back page of the previous document.
Assuming you're using overflow pages, you can specify that you want the last added page to be even. But judging by your code, it looks like you may want the last page in the PDF to print in a different text frame (lastGraphic)? So, I'm also going to assume that if you have an odd number of pages, you want the content of 'lastGraphic' to be blank rather than containing the last page?
Code:
var file = CreateResource(path + fileName, 'graphic');
var pages = Math.min(file.countPages, 12);

for (var i = 1; i <= pages; i++)
  (file.pagenumber = i) && result.push(file.content);

var lastPage = result.length % 2 ? '' : result.pop();
FindTextFrame(firstGraphic).content = result.join('<p>');
FindTextFrame(lastGraphic).content = lastPage;
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old November 29th, 2017, 11:04 AM
draco66 draco66 is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 70
Default Re: Limit Pages & Odd Page Insert Blank

Thank you for your input on this one. I will look this over and give it a try in the next couple of days.

I'll let you know how it works out.
Reply With Quote
  #4  
Old November 30th, 2017, 06:22 AM
draco66 draco66 is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 70
Default Re: Limit Pages & Odd Page Insert Blank

Today I tested just the odd page part of the code as we are ready to implement that but not the limited page count just yet.

I updated my code as you had suggested and it does make the page count even, but it does so by eliminating the odd page from the file.

For my test I used a 5 page document. The composed file contained only 4 pages of that document. It dropped page 5 to make it even rather than adding a blank to the end.
Reply With Quote
  #5  
Old November 30th, 2017, 06:31 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Limit Pages & Odd Page Insert Blank

Can you share your updated code? It sounds like you didn't change the < to a <= in the for loop. But it would be easier to determine what's going on if I could see what you're using.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #6  
Old November 30th, 2017, 06:47 AM
draco66 draco66 is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 70
Default Re: Limit Pages & Odd Page Insert Blank

You are 100% correct. I missed <=. I changed it and it is working fine.

I shouldn't work on code before my third cup of coffee.

Sorry about that.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.