OL Learn

PDF Datamapper input crop


Have a task where I must place an PDF into the designer, from the workflow.

Normally I just set the background on the Contexts->Print to use “From PDF Datamapperinput”.

In this case I only need some of the pdf/letter, cause I need to replace the rest og the letter with new text.

A variable in the datamapper, indicates how fare down on the page the page should be cropped horizontally. Can this be controlled by a script?

A Case could be that the page should only show the A4 pdf background from the top and 150mm down.

At the moment , I do not see how that would be possible other than by cropping the original PDF input. Unfortunately, that would require the use of an external library or application.

I will make a feature request to our R&D department and see if it gets accepted. The more customer request the feature, the more chance it has to make a future release.

But there is no guarantee.

How about something like this:

<p id="cropped">
    <img src="images/MyPDF.pdf" style="position:absolute;clip: rect(0, 100px, 200px, 0);" />

You could clean up that code a bit and even write JS code to make the cropping rectangle dynamic, but you get the idea.

Hi Phil or hameji

Do you know it this feature has yet been implemented ?
Just have another customer, where I need to remove the letterhead on page 2-N
The PDF arrives from the “pdf datamapper input” and i have to “blank” out the top 10 cm on page 2-N, to make the datamapping a lot easier.

The request has been made but it is yet to be implemented. If you want you can message me the customer name and I will add it to the list of requester.

Hope you can help in another way in this case.
Need to control up to 3 different sections depending on input from the datamapper.

At first I only needed to control 2 sections depending on the page index.
Now I need a to control a third section, depending on a variable in a detailed table and the page index.
Is that posible ?

Have a detailed table with the info, each record in the table is equal to a corresponing page.
record.Project[1] = Page 1 from the PDF datamapper input

Have a control script, put I’m missing the path with the “page.index = record.index” if it is posible

var Section000mm = merge.template.contexts.PRINT.sections.PageOffset000mm;
var Section105mm = merge.template.contexts.PRINT.sections.PageOffset105mm;
var Section120mm = merge.template.contexts.PRINT.sections.PageOffset120mm;
Section000mm.enabled = false;
Section105mm.enabled = false;
Section120mm.enabled = false;

//var PageIndex = record.fields[“RecordIndex”]; //Old datamapper with page.index
var PageIndex = record.fields.Project ??? //Page
var ProjectID = record.fields.Project ??? //ProjectID

var EvenPage = PageIndex % 2;

if (PageIndex == “1”) {
Section000mm.enabled = true; //Section = PageOffset000mm

} else if ((PageIndex != “1”) && (EvenPage == “1”)) && (ProjectID){
Section115mm.enabled = true; //Section = PageOffset105mm
} else if (!ProjectID){
Section120mm.enabled = true; //Section = PageOffset120mm
else {
Section000mm.enabled = false;
Section105mm.enabled = false;
Section120mm.enabled = false;

I don’t fully understand what you try to achieve but I believe you want to iterate over the records in the detail table. Perhaps the following is of some help:

var theSections = merge.template.contexts.Print.sections;
theSections["Section 1"].enabled = false;
theSections["Section 2"].enabled = false;
theSections["Section 3"].enabled = false;

for( var i = 0; i < record.tables['project'].length; i++ ){

	var projectId = record.tables.project[i].fields.ProjectID;
	var pageIdx = record.tables.project[i].fields.Page;

	// your logic here


I have in this example a 24 page input pdf
Some of the pages need to be cropped.
I have made a datamapper, with a detailed table (don’t know if that can be used at all)
The input PDF just passed through as a “overlay”
On page 1 from the input PDF, it should select a print section depending on the value in record.project [1]
The “for” sentence is not working.

Is the cropping only a matter of clipping the top area of your documents?

Yes right now I just use 3 print sections, depending on how much should be cropped.
Then on the print section, I just top offset the pdf.

Ok, I think there is alternative approach… admittedly it is a bit unconventional and an extension of what Phil suggested (use clip() in CSS). In essence you would only need a single section, the background of that section is set to the Data Mapper input.

Subsequently create a User Script that targets the tag. The script iterates over the detail records and dynamically adds a CSS rule to crop the images used for the background. One for each page (based on your detail table). Again a bit unconventional and perhaps non trivial but I think it will do the job.

Below my script (you may need to tinker the conditions a bit). The screen below shows the document in Design and Preview mode.


var projects = record.tables.project;
var css = "< style>";

for( var i = 0; i < projects.length; i++ ) {

	var pageIdx = projects[i].fields.Page;
	var projectID = projects[i].fields.ProjectID;
	if (pageIdx == 1) {
		// dont do a thing.
	} else if (( pageIdx > 1 ) && ( pageIdx % 2) && projectID ) {
		css += ".page_bleedbox:nth-child(" + pageIdx + ") .ol_pdf_datamapper_input { clip: rect(15mm,auto,auto,auto) !important; }";
	} else if ( ! projectID ) {
		css += ".page_bleedbox:nth-child(" + pageIdx + ") .ol_pdf_datamapper_input { clip: rect(20mm,auto,auto,auto) !important; }";
	} else {
	       // something else.
css += "< /style>";

results.append( css );

Will try it.
Where do you contol how big the bleed/clipp is, can’t see any numbers ind the script ?

In the picture in the end of the line it says clip : ???

Ah right… it is clipped by the content area of the browser ;). The sample clips the top 15mm of the image

1 Like

Will try it monday - have a nice weekend.

Just worked with the PDF.
Looks like it is not working as expected.
Needed to blank out the top so that the datamapper could not see the former text in the top.
The PDF looks allright, but the text is still there, så even though the pdf looks blank, it is not.
Must be the “bleedbox” who just blnaks it, but not removing the text.

Then the datamapper can’t skip the section - any idears. ?

Wasn’t aware of that requirement. The Designer does not remove the content from the PDF it only changes the viewable area. I wonder if shifting the page up would solve things, but I’m not sure. In that case you should be able to translate() instead of clip(). Other than that I ran out of ideas.

Tried this syntax, but It does not seem to do anything

Bleed - Working - But don’t remove text just makes it ivisible.
css += “.page_bleedbox:nth-child(” + pageIdx + “) .ol_pdf_datamapper_input { clip: rect(122mm,auto,auto,auto); !important; }”;

Move - does not work:
css += “.page_bleedbox:nth-child(” + pageIdx + “) .ol_pdf_datamapper_input { transform: translate(0,122mm); !important; }”;

Also tried:
css += “.page_bleedbox:nth-child(” + pageIdx + “) .ol_pdf_datamapper_input { transform: translateY(-105mm); !important; }”;

Try the following;

css += “.page_bleedbox:nth-child(” + pageIdx + ") .ol_pdf_datamapper_input { transform: translate(-50%, -50%) translateY( -105mm) !important; } ";

But note that it will move the PDF output of view but not remove the text.