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


Thread Tools Search this Thread Display Modes
Old November 18th, 2019, 02:14 PM
ReminderVDP ReminderVDP is offline
Regular Contributor
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 119
Default Inserting PDF File inside a Composition

I've been using this rule to insert magazine text pages inside a composition of a book cover. So the front cover is Body Page 1, Inside front cover is Body Page 2, the PDF I want to insert is next and then the Back Inside Cover and Back cover are the other Body Pages. Easy enough.

The PDF files I want to insert are on a new server and for some reason, it is not finding the PDF I want to insert. The only thing I changed from the last template was the pathName field because the files are in a different location. I've double checked the names in the path and the file name and everything is correct.

I'm stumped. Can someone see if they see anything that would not allow me to find the PDF in this rule when I validate it? Only thing I could think of is the server permissions.

This is the Error message:
***Error*** (uncaught exception: Error: Graphic not found: magazine-97.pdf)

var pathName = "//ServerLocation/Resources/";
var FullResourcePath = 'magazine-' + Field("MagIDShort") + ".pdf"; //change to match your data file field
var x = new FusionProResource(FullResourcePath, "graphic", 1);
if (!x.exists)
ReportError("Graphic not found: " + FullResourcePath);
var pdfString = '';
for (var pgnbr = 1; pgnbr <= x.countPages; pgnbr++)
x.pagenumber = pgnbr;
pdfString += x.value + '<p>\n';
Print("Result is: " + pdfString);
return pdfString;
Bryan Mathes, Print Production Specialist
FusionPro Designer 10.1.11, FusionPro Producer (Server) API 10.1.11
Mac OSX 10.12.6
Mac Pro 2.8 GHz Quad Core Intel Xeon

Last edited by ReminderVDP; November 18th, 2019 at 02:26 PM..
Reply With Quote
Old November 18th, 2019, 03:37 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,430
Default Re: Inserting PDF File inside a Composition

You have this line in the rule:
 var pathName = "//ServerLocation/Resources/";
But I don't see where you're using that pathName variable after declaring and setting it. The fact that you don't see the path in the error message is also a clue that you're not actually using it.

I would think you would want the next line to be something like:
var FullResourcePath = pathName + 'magazine-' + Field("MagIDShort") + ".pdf";
Though, instead of hard-coding the path in the rule, you could set it in the Search Path box on the Advanced tab of the Composition Settings dialog.

After that, you need to make sure the path is in the correct format, which depends on the platform (Windows or Mac). I guess my question to you is, are you composing this job locally, on your Mac, or are you composing it on Windows, via Producer?

If you're composing on Mac, then you probably want a path that starts with "/Volumes/". And, on Mac, you need to make sure that you're actually connected to the server. You probably need to do a "Connect to Server" (Command-K) in the Finder, then connect to the remote server with SMB or a similar protocol. I would make sure you can see one of the files in question in the Finder, then drag it into a Terminal window to get the actual POSIX path, which, again, I would expect to start with "/Volumes/".

If you're composing on Windows, then you probably want a UNC path, which starts with two backslashes; but backslashes need to be escaped in JavaScript, so that string would need to start with four backslashes, something like this:
 var pathName = "\\\\ServerName\\Resources\\";
Again, it might be easier to just define the Search Path in the Composition Settings, where you don't have to worry about escapes for JavaScript. Although, even easier than that would be to specify a Search Path for the Queue in the FusionPro VDP Producer Configuration.

If you want to make this work both for local Mac compositions, and for remote Windows (Producer) compositions, then you can write the code something like this:
var pathName = "\\\\ServerName\\Resources\\"; // Windows UNC path
if (FusionPro.isMac)
    pathName = "/Volumes/Resources/"; // need to connect to the server in the Finder first
var FullResourcePath = pathName + 'magazine-' + Field("MagIDShort") + ".pdf";
Or, even easier than that, remove the path from the rule completely, and define BOTH Search Paths in the Composition Settings, with a semicolon between them, like so:
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

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)});

Last edited by Dan Korn; November 18th, 2019 at 03:53 PM..
Reply With Quote

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 06:23 AM.

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