Autorotate Dynamic Images

I am using a dynamic image script to bring in a 14in x 20in pdf file and placing it on an 11x17 sheet with some other variables from the data mapper. The problem I am running into is that some of the pdfs can be portrait and some can be landscape.

Is there an easy way to bring in that file and autorotate the pdf? I will also need to figure out how to show the other variables in the right location depending on which orientation the pdf will be in.

Hi APoole,

You could change the PDF in Workflow first by rotating the landscape pages using Rod’s script here. You can modify the script so that it rotates portrait instead.

Regards,

S

In the Desiger you could use of the resource() command to fetch the width and height of the pdf. This can be used in User scripts and Control scripts. More information about this command is found in the online Help. See: resource()

I suggest to create two sections one for Landscape and one for Portrait (set the orientation accordingly). Use a Control Script to dynamically turn on or turn off the respective section based on the information retrieved from the PDF.

Subsequently set the image as section background via the Control Script. This is explained on the following page: Control Script set Section Background image

Use standard scripts to populate placeholders and elements in the section with data.

Below a sample Control Script which combines the above.

Hope this helps,

Erik

// Fetch information about the PDF
var path = 'C:/bb-letterhead.pdf';
var info = resource( path );
info.pages;  // Number of pages in the PDF (image)
info.width;  // Width of the current page in points.
info.height; // Height of the current page in points.

// Toggle the visibility of the sections
var printSections = merge.template.contexts.PRINT.sections;
var activeSection;
printSections['Landscape'].enabled = false;
printSections['Portrait'].enabled = false;

if(info.height >= info.width) {
    activeSection = printSections['Portrait'];
} else {
    activeSection = printSections['Landscape'];
}
activeSection.enabled = true;

// Set the background image to the section
activeSection.background.source = BackgroundResource.RESOURCE_PDF;
activeSection.background.allPages = true;
activeSection.background.url = path;

This worked beautifully! I was then able to change the .css for Print to make the PDF smaller to fit the page.

Thank you!

Great!

In the oncoming release (2018.1) you will be able to set the scale and angle of the respective section background via the User Interface (Section Background dialog) or programmatically via the Control Script.

Erik