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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 18th, 2019, 01:14 PM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
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 01:26 PM..
Reply With Quote
  #2  
Old November 18th, 2019, 02: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,481
Default Re: Inserting PDF File inside a Composition

You have this line in the rule:
Code:
 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:
Code:
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:
Code:
 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:
Code:
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:
Quote:
\\ServerName\Resources\;/Volumes/Resources/
__________________
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)});

Last edited by Dan Korn; November 18th, 2019 at 02:53 PM..
Reply With Quote
  #3  
Old March 2nd, 2020, 02:09 PM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
Default Re: Inserting PDF File inside aa Coposition

Dan,
I am using this rule and need to make a variation on it where the first 22 pages go into the text body page and the rest of the text (22 pages) goes into the overflow text body page. I have a center spread between the pages that will have advertisements in it so the text PDF file needs to be split in half. I tried doing a page count of 22 pages but I get the validation error of:

line 9: SyntaxError: missing : after proerty id

I don't thing the var pages is correct and is causing the SyntaxError.

Rule:
var pathName = "/Users/macpro1/Desktop/InkJet Layout_2-21-20/";
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 pages = Math.min(x.countPages, 22);
{
x.pagenumber = pages;
pdfString += x.value + '<p>\n';
}
Print("Result is: " + pdfString);
return pdfString;


Like usual, I'm probably over-complicating it.
__________________
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
Reply With Quote
  #4  
Old March 2nd, 2020, 04:28 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,481
Default Re: Inserting PDF File inside aa Coposition

So, a few things.

First, if you're posting code, it's a lot more readable if you put it into code formatting blocks, like in my posts. It's easy to do. Just click the "Go Advanced" button underneath the box you're typing into, then, after you copy-and-paste in the code, select it, then click the # button above the box where you're typing. (You can do all kinds of other formatting in that "Advanced" mode too.)

Second, I think you're on the right track with:
Code:
var pages = Math.min(x.countPages, 22);
That will limit the number of pages you're inserting to 22, if the resource has more than that.

But you still need an actual "control" variable in the "for" statement on the line right below that. It's not just "for (pages)", it's what you had in your original post, but instead of:
Code:
for (var pgnbr = 1; pgnbr <= x.countPages; pgnbr++)
It's now:
Code:
var pages = Math.min(x.countPages, 22);
for (var pgnbr = 1; pgnbr <= pages; pgnbr++)
Or just:
Code:
for (var pgnbr = 1; pgnbr <= Math.min(x.countPages, 22); pgnbr++)
Though, in this case, I think having the separate line to capture that "pages" variable is easier to understand, but that's just a preference.

So, putting it all back together:
Code:
var pathName = "/Users/macpro1/Desktop/InkJet Layout_2-21-20/";
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 = '';
var pages = Math.min(x.countPages, 22);
for (var pgnbr = 1; pgnbr <= pages; pgnbr++)
{
    x.pagenumber = pgnbr;
    pdfString += x.value + '<p>\n';
}
Print("Result is: " + pdfString);
return pdfString;
Third, I don't really know for sure whether that code will do what you want without seeing more of the job. Going back to your description of what you're trying to do:
Quote:
Originally Posted by ReminderVDP View Post
I am using this rule and need to make a variation on it where the first 22 pages go into the text body page and the rest of the text (22 pages) goes into the overflow text body page. I have a center spread between the pages that will have advertisements in it so the text PDF file needs to be split in half.
I'm not sure what you've already done in your template here. I hope you're not going through a painstaking process of adding 22 Body pages to your template. When you say you have a "center spread," what does that mean? Do you mean you're imposing 44 pages onto a larger sheet? Or are you simply trying to insert a different kind of page between the 22nd and 23rd pages of the PDF resource? This is a case where a picture (of the desired output) might be worth a thousand words.
__________________
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)});

Last edited by Dan Korn; March 2nd, 2020 at 04:33 PM..
Reply With Quote
  #5  
Old March 3rd, 2020, 06:11 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
Default Re: Inserting PDF File inside aa Coposition

Thanks Dan. I did not create 22 pages for text. I have one body page and an overflow page. Currently, the text is 44 pages and flows between cover pages in the output PDF. We are trying to add a center spread area with advertisements for the customer so the layout would be:


Front Cover
Text: pages 1-22
Center Spread of ads
Text: pages 23-44
Back cover


I'll give this a try and see if it works.
__________________
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
Reply With Quote
  #6  
Old March 9th, 2020, 09:22 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
Default Re: Inserting PDF File inside aa Coposition

Dan,
This worked. I'm taking it one step further and want to figure out a way to split the number of pages in half, no matter how many there are in the text PDF. Above, I knew I had a text document 44 pages and I told it to use the first 22. What can I put in the pages variable if I don't know the total amount of text pages?


This is what I have right now and it finds the middle page of the text PDF, 22, but I can't get it to add the rest of the pages after page 22. It will only add that page. I would need it to start on page 23 of the text which I could add a +1 in the pages line. I think it's the page number variable causing the problem in this code though.


Code:
var pathName = "/Users/macpro1/Desktop/InkJet Layout_2-21-20/";
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 = '';
var pages = Math.min(x.countPages/2)
for (var pgnbr = pages; pgnbr <= pages; 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
Reply With Quote
  #7  
Old March 9th, 2020, 09:51 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,481
Default Re: Inserting PDF File inside aa Coposition

Quote:
Originally Posted by ReminderVDP View Post
This is what I have right now and it finds the middle page of the text PDF, 22, but I can't get it to add the rest of the pages after page 22. It will only add that page. I would need it to start on page 23 of the text which I could add a +1 in the pages line. I think it's the page number variable causing the problem in this code though.
So again, it's very challenging for me to try to visualize exactly what you're doing without the template files.

Do you mean there's a second rule to insert "Text: pages 23-44" as in your description?

Since I can't actually run the code in your template context, I'm basically guessing, but I think that second rule would look something like this:
Code:
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 = '';
var halfPages = Math.floor(x.countPages/2);
for (var pgnbr = halfPages + 1; pgnbr <= x.countPages; pgnbr++);
{
    x.pagenumber = pgnbr;
    pdfString += x.value + '<p>\n';
}
Print("Result is: " + pdfString);
return pdfString;
Or, maybe you have a single rule that does everything, something like:
Code:
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 = '';

// First half of "Text"
var halfPages = Math.floor(x.countPages/2);
for (var pgnbr = 1; pgnbr <= halfPages; pgnbr++);
{
    x.pagenumber = pgnbr;
    pdfString += x.value + '<p>\n';
}

// Center Spread of ads
var ads = new FusionProResource(AdsResourcePath, "graphic", 1);
for (var pgnbr = 1; pgnbr <= ads.countPages; pgnbr++);
{
    ads.pagenumber = pgnbr;
    pdfString += ads.value + '<p>\n';
}

// Second half of "Text"
for (var pgnbr = halfPages + 1; pgnbr <= x.countPages; pgnbr++);
{
    x.pagenumber = pgnbr;
    pdfString += x.value + '<p>\n';
}
Print("Result is: " + pdfString);
return pdfString;
__________________
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)});

Last edited by Dan Korn; March 9th, 2020 at 10:06 AM..
Reply With Quote
  #8  
Old March 10th, 2020, 09:47 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
Default Re: Inserting PDF File inside aa Coposition

Dan,
That would be a second rule for the second half of the text. When I validate it, it only gives me page 23 as a result. It doesn`t include the rest of the pages after page 23.
__________________
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
Reply With Quote
  #9  
Old March 10th, 2020, 11:25 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,481
Default Re: Inserting PDF File inside aa Coposition

Quote:
Originally Posted by ReminderVDP View Post
Dan,
That would be a second rule for the second half of the text. When I validate it, it only gives me page 23 as a result. It doesn`t include the rest of the pages after page 23.
We've reached the limit of the help I can provide without the context of the template. I need the see the job files to diagnose this further.
__________________
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 March 10th, 2020, 11:33 AM
ReminderVDP ReminderVDP is offline
Regular Contributor
 
Join Date: Jan 2013
Location: King of Prussia, PA
Posts: 128
Default Re: Inserting PDF File inside aa Coposition

I think that rule I was working in got corrupted somehow. I put your code in a new Rule and it works. No matter what I changed the page number to in the rule I was using, it showed page 23. Seems to be working with the new rule now. Thanks for your help.
__________________
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
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 04:36 AM.


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