Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 22nd, 2008, 09:21 AM
Admin's Avatar
Admin Admin is offline
Administrator
 
Join Date: Oct 2007
Posts: 331
Default Inserting Multi-page PDF variable graphics

This sample job shows how multiple variable PDF graphic files, each of an unknown page-count, can be inserted into a FusionPro template as inline graphics into a text frame. This sample includes all sample files and heavily commented JavaScript that shows how this logic is created.

To accomodate the varying and unknown page count as well as number of PDF graphics to be inserted in each record, the advanced "Automatic Page Insertion" option in FusionPro is used. This option, also called "Page Overflow" is a function of a variable text frame. Designed initially to accomodate varying text content length, the functionality also allows for multiple graphic file insertions and is a great solution when each data record requires an unknown and possibly extremely variable set of variable graphics.

Pay special attention to the variable frame settings especially the size of the frames and the settings in the "Paragraph" dialogue (inside of the variable text editor).
Attached Files
File Type: zip Insert.zip (162.9 KB, 953 views)
__________________
Forum Administrator
PTI Marketing Technologies, Inc.
Reply With Quote
  #2  
Old April 17th, 2009, 10:32 AM
woolfstudio woolfstudio is offline
Forum n00b
 
Join Date: Mar 2009
Posts: 1
Default Re: Inserting Multi-page PDF variable graphics

I'm not able to get this to work. I'm on a mac, so I changed the path in the "PDF Graphic Insertion Rule" to 'Macintosh HD:Path:". When I compose, all I get is the first page. I don't get the pages that are to be overflowed. I am needing to do a project similar to this -- any suggestions?
Reply With Quote
  #3  
Old February 3rd, 2010, 12:32 PM
KayEll's Avatar
KayEll KayEll is offline
Junior Community Member
 
Join Date: Jan 2009
Posts: 40
Default Re: Inserting Multi-page PDF variable graphics

Help!

I am trying to get this sample to work on my computer as well. I downloaded the job and changed the path in the script to:

'Macintosh HD:Users:kay: Desktop:Avalanche_tests:Insert PDF Graphics Inline: Docs'

(There are NO spaces in front of the Ds, but if I type here it gives me an emoticon.)


I can only get the first page of the doc to compose and it is not pulling the PDFs from the folder "Docs".

1) Is my path typed incorrectly? I thought on a Mac the separators were colons. But I tried / and \\ also jsut in case.

2) Is this the only part of this script that I should need to change to get this to work?


Thanks for any help. I have a job very similar to this and I feel if I can get THIS sample to work, I can figure out my job as well.


********************************
I'll paste the original JS here in case that helps:


//This rule will examine the input data to find a list of PDF files
//that are to be inserted in the template.

//Each PDF is of varying and unknown page count. Therefore, this script
//will determine that page count and reference each page in each PDF.

//The resulting tagged markup will include the variable <graphic> tag to reference
//the PDF pages and include as inline images in the template.

//This text rule in inserted into a large text frame on a Body page. That frame
//is set to Overflow to a frame on an overflow page.


//First, declare the variables and initiate them with values.

FieldName = '';
PDFfileName = '';
pagesInPDF = 0;
markupToReturn = '';
pathToAllPDFs = 'C:\\Work\\Printable\\Insert PDF Graphics Inline\\Docs\\';
pathToPDF = '';
PDFresourceRef = '';


//There are 3 fields in this sample - Doc1, Doc2, and Doc3. We will loop through
//each field name with a simple for loop. The following variable sets the counter
//for that loop.
//For example, if you have 25 fields instead of 3 with the PDF file names in them,
//such as "Doc1" through "Doc25" you would set the following to 25.

FieldsToInspect = 3;



//This is the main loop that parses through all of the fields for a given record.

for (fieldCounter = 1; fieldCounter <= FieldsToInspect; fieldCounter++)
{
FieldName = 'Doc' + fieldCounter;
PDFfileName = Field(FieldName);
pathToPDF = pathToAllPDFs + PDFfileName;

//Create a new resource that references this
PDFresourceRef = CreateResource(pathToPDF ,'graphic' ,'no');

//Find out how many pages it has
pagesInPDF = PDFresourceRef.countPages;

//return PDFresourceRef.name;

//This is the secondary loop for this script.
//It will loop through and create markup for each page in the PDF.
for (pageLoop = 1; pageLoop <= pagesInPDF; pageLoop++)
{
markupToReturn += '<graphic file="' + PDFresourceRef.name + '" pagenumber = "' + pageLoop + '" position="afterline"/>';

markupToReturn += '<P>';
}





}

//remove the last <P>
markupToReturn = Left(markupToReturn, markupToReturn.length - 3);


return markupToReturn;



Thanks,

KayEll
__________________
Fusion Pro VDP Creator 9.3.26
Fusion Pro Expression 3.1.8
Acrobat Pro 11.0.0
InDesign CC 2014 and 2015
Mac OS X 10.10.4
Reply With Quote
  #4  
Old February 3rd, 2010, 02:09 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Inserting Multi-page PDF variable graphics

Your signature mentions "Windows XP Version 2002," but you're obviously on a Mac. It would be useful to know the exact version of Mac OS X you're running.

At any rate, on either platform, you definitely need a trailing directory separator at the end of the path in that particular rule, so that in this line:
Code:
pathToPDF = pathToAllPDFs + PDFfileName;
It properly builds the path with the last separator. Otherwise, it's going to build a path such as:
'Macintosh HD:Users:kay:Desktop:Avalanche_tests:Insert PDF Graphics Inline:DocsMyGraphicName', which is surely wrong (it should be something like:
'Macintosh HD:Users:kay:Desktop:Avalanche_tests:Insert PDF Graphics Inline:Docs:MyGraphicName' - note the difference that last colon makes).

So, I would try adding a single colon at the end of the path specification:
'Macintosh HD:Users:kay:Desktop:Avalanche_tests:Insert PDF Graphics Inline:Docs:'

If that still doesn't work (or even if it does), you probably should be using the newer POSIX-style paths on Mac instead of the old-style HFS paths. So I would try a path like this:
'/Users/kay/Desktop/Avalanche_tests/Insert PDF Graphics Inline/Docs/'
Note the trailing slash at the end.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #5  
Old February 4th, 2010, 01:34 PM
KayEll's Avatar
KayEll KayEll is offline
Junior Community Member
 
Join Date: Jan 2009
Posts: 40
Default Re: Inserting Multi-page PDF variable graphics

Dan, Yes I very recently moved my FP to my Mac and forgot to update my signature. I am using OS X 10.5.8, FP Desktop 6.0P, and Acrobat 9.

Thanks for the tip, your fix worked perfectly! I didn't realize I needed that last separator.

I also didn't have my text boxes extending all the way to the edge of the PDF, so that was another problem.

So, I have this sample working now, and my sample as well after I renamed all my PDFs to Doc1 and Doc2, but I think my eventual data and PDFs will be coming to me in a different manner. My fields will have the different document names as the header (ie: Kitchen, Bath, Bedroom) and the value will simply be a yes or a no if they require that document. They can have 1, 2 or all 8 documents if they desire. I'm not 100% sure how I will need to alter this to fit that. Or if I should just have them make their data fit this existing script. I can probably have them send me the data however I want.

Thanks for your help! Much appreciated.
KayEll
__________________
Fusion Pro VDP Creator 9.3.26
Fusion Pro Expression 3.1.8
Acrobat Pro 11.0.0
InDesign CC 2014 and 2015
Mac OS X 10.10.4
Reply With Quote
  #6  
Old June 21st, 2010, 08:23 AM
ehigginbotham ehigginbotham is offline
Junior Community Member
 
Join Date: Jun 2009
Posts: 34
Default Re: Inserting Multi-page PDF variable graphics

I can't seem to get it to work either, and have tried every variation that I can think of for the path.

pathToAllPDFs = 'C:\Documents and Settings\ehigginbotham\Desktop\Insert PDF Graphics Inline\Docs:';

windiows xp
fp: 6.2

thanks
Eric
Reply With Quote
  #7  
Old June 21st, 2010, 10:54 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Inserting Multi-page PDF variable graphics

Quote:
Originally Posted by ehigginbotham View Post
I can't seem to get it to work either, and have tried every variation that I can think of for the path.

pathToAllPDFs = 'C:\Documents and Settings\ehigginbotham\Desktop\Insert PDF Graphics Inline\Docs:';
Whenever you're having a problem like this, it helps to do a very basic bit of debugging. If you simply add a line like this to your rule:
Code:
Print(pathToAllPDFs);
And then do a composition and look in the log (.msg) file, it should become immediately obvious what the problem is. Or you can just add this line temporarily while you're in the Rule Editor and click Validate:
Code:
return pathToAllPDFs;
I'll bet that it returns this: "C:Documents and SettingsehigginbothamDesktopInsert PDF Graphics InlineDocs:". So that's obviously not right.

Why do all the backslashes get removed? Because the backslash is a special character in string literals in JavaScript:
https://developer.mozilla.org/en/Cor...ing_Characters

You can work around this in several ways, which I'll present in order from least to most recommended:
  1. As in the sample, double up all backslashes to "escape" them, that is, to let the JavaScript interpreter know that they're literal backslash characters and not modifiers for the characters following them, like so:
    Code:
    pathToAllPDFs = 'C:\\Documents and Settings\\ehigginbotham\\Desktop\\Insert  PDF Graphics Inline\\Docs\\';
  2. Replace the backslashes with forward slashes, like so:
    Code:
    pathToAllPDFs = 'C:/Documents and  Settings/ehigginbotham/Desktop/Insert  PDF Graphics Inline/Docs/';
    All modern versions of Windows allow forward slashes in place of back slashes in file paths. (The only exception is at the beginning of a UNC path such as "\\server\share\filename".)
  3. Don't specify a path in the JavaScript code at all, and specify a Search Path for the job instead. Change the line in the rule to this:
    Code:
    pathToAllPDFs = "";
    And then go into the Composition Settings dialog, on the Advanced tab, and enter the path in its normal format (with single backslashes, or you can use forward slashes) in the Search Path box. The call to CreateResource will automatically look for the graphics along the specified Search Path. This is much more forgiving than doing it in code because you don't have to worry about the trailing slash, and if you have multiple rules and change the location of your graphic resources, or run the job on a different machine, you can simply change the single search path setting for the job. You can also include multiple search path locations by delimiting them with semicolons and all those paths will be searched.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #8  
Old June 21st, 2010, 10:59 AM
ehigginbotham ehigginbotham is offline
Junior Community Member
 
Join Date: Jun 2009
Posts: 34
Default Re: Inserting Multi-page PDF variable graphics

I had figured out the / instead of \ thing through luck. lol I am actually using this rule for a template in marcom central, do you know if the 3rd option will work if the paths to the images are on the web? I know this is actually a question for that forum, but this rule was so similar I started here.

thanks for your help
Reply With Quote
  #9  
Old June 21st, 2010, 11:19 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Inserting Multi-page PDF variable graphics

Quote:
Originally Posted by ehigginbotham View Post
I had figured out the / instead of \ thing through luck.
Luck is fine, but debugging is better. Thus my suggestion to use Print and return statements to find out what's really going on in different places in your rules.
Quote:
Originally Posted by ehigginbotham View Post
lol I am actually using this rule for a template in marcom central, do you know if the 3rd option will work if the paths to the images are on the web? I know this is actually a question for that forum, but this rule was so similar I started here.
If you're in the MarcomCentral environment, then the Search Path is set up automatically in the composition to point to the locations of the files you upload through the Manager to your image libraries. So you don't need to specify the path anywhere from your end for any online compositions. You'll still need the path for offline compositions and Previews on your local machine, though.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #10  
Old June 21st, 2010, 02:09 PM
ehigginbotham ehigginbotham is offline
Junior Community Member
 
Join Date: Jun 2009
Posts: 34
Default Re: Inserting Multi-page PDF variable graphics

Now that this rule is working, I need to use it in conjunction with a rule that will make the total page count of a book divisable by 4. Here is the rule I have so far. Any suggestions.

//Letter Page
if ((Field("ZIP")) == "")
{
FusionPro.Composition.SetBodyPageUsage("Directory file",false);
}else{
FusionPro.Composition.SetBodyPageUsage("Directory file",true);
}

if (Field("Page 1 y or n") == "y")
{
FusionPro.Composition.SetBodyPageUsage("70",true);
}else{
FusionPro.Composition.SetBodyPageUsage("70",false) ;
}
if (Field("Page 2 y or n") == "y")
{
FusionPro.Composition.SetBodyPageUsage("71",true);
}else{
FusionPro.Composition.SetBodyPageUsage("71",false) ;
}

if (Field("Page 3 y or n") == "y")
{
FusionPro.Composition.SetBodyPageUsage("72",true);
}else{
FusionPro.Composition.SetBodyPageUsage("72",false) ;
}

// place each field into an array
// then count the number of pages in each pdf and add them together
//if there are any static pages in the booklet
// adjust the starting number of the PAGECount here.
// since we have no static pages in this booklet, keep the PAGECount at 0

var PAGECount=86;
var PicPages=4;
PAGEArray = [ Field("ZIP"),Field("Page 1 y or n"),Field("Page 2 y or n"),Field("Page 3 y or n") ]

for (i = 0 ; i < PAGEArray.length ; i++)
{
if (PAGEArray[i] != "")
{
var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
PicPages = Pic.countPages;
PAGECount+=PicPages;
}

}

//divide pagecount + 10 by 4
//if remainder is 1, you will need all 3 blank pages
//if remainder is 2, you will need 2 blank pages
//if remainder is 3, you will need 1 blank page
if (PAGECount % 4 == 1)
{
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 1", "true");
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 2", "true");
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 3", "true");
}

else if (PAGECount % 4 == 2)
{
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 1", "true");
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 2", "true");
}

else if (PAGECount % 4 == 3)
{
FusionPro.Composition.SetBodyPageUsage("Intentiona l Blank 1", "true");
}
Reply With Quote
Old July 27th, 2010, 03:15 PM
invaricconsulting
This message has been deleted by invaricconsulting.
Old July 27th, 2010, 03:26 PM
invaricconsulting
This message has been deleted by invaricconsulting.
Old July 27th, 2010, 03:30 PM
invaricconsulting
This message has been deleted by invaricconsulting.
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 09:28 PM.


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