Jump to content

Inserting PDF File inside a Composition


ReminderVDP

Recommended Posts

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;

Link to comment
Share on other sites

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:

\\ServerName\Resources\;/Volumes/Resources/
Edited by Dan Korn
Link to comment
Share on other sites

  • 3 months later...

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.

Link to comment
Share on other sites

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:

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:

for (var pgnbr = 1; pgnbr <= x.countPages; pgnbr++)

It's now:

var pages = Math.min(x.countPages, 22);
for (var pgnbr = 1; pgnbr <= pages; pgnbr++)

Or just:

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:

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:

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.

Edited by Dan Korn
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

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;

Link to comment
Share on other sites

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:

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:

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;

Edited by Dan Korn
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • 3 years later...

hello,

Sorry if this is a repeat questions...

Is there a way it can resize the PDFs through the rule so that it fits in the provided frame if its too large? We have PDF's that are all different sizes and telling it to do a max size if 8.5" would save us a lot of time on manually resizing.

Thank you!

Edited by Jen
misspelling
Link to comment
Share on other sites

42 minutes ago, Jen said:

Is there a way it can resize the PDFs through the rule so that it fits in the provided frame if its too large? We have PDF's that are all different sizes and telling it to do a max size if 8.5" would save us a lot of time on manually resizing.

In the code from the previous posts, in the pages loop, you can set:

   x.height = HundredthsOfPointsFromText("8.5 in");

That will set each page to be 8.5 inches in height, resizing the width proportionally as needed.

Note that this doesn't exactly match your requirements, to be a maximum size and resize only if it's too large.  If you want to do that, you can first check the size of the graphic by doing this:

var tm = new FusionProTextMeasure;
tm.CalculateTextExtent(x.content);
if (tm.textHeight > HundredthsOfPointsFromText("8.5 in"))
  x.height = HundredthsOfPointsFromText("8.5 in");

Als, note that you could approach this job in a completely different way.  Instead of using inline graphics repeating into an overflowing text frame, you could just have a single page in the job, with a graphic frame on it, and repeat the record the same number of times as the number of pages in the PDF you're bringing in (plus any other pages), then you can set the scaling on the graphic frame.

Link to comment
Share on other sites

  • Dan Korn changed the title to Inserting PDF File inside a Composition

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...