Git Product home page Git Product logo

olconnect-singlerecordmixedorientationpdf's Introduction

How to insert the correct portrait or landscape PDF page to the corresponding Print Section in Connect Designer

It is assumed here that each record is a multi page with mixed portrait and landscape orientation.

Datamapper

  • Use a Repeat step to loop through each page of the PDF until no more elements.
  • With the Reapeat step, the "Target Type" of the Go To step should be set to "page"
  • Within the Reapeat step, Extract the current page width and\or height values. Example, to extract the current page width:
	steps.currentPageWidth;
  • This creates a detail table containing the width and\or height of each pages. The length of the detail table will be equal to the total number of pages in the record.

Connect Designer - Control Script

  • Add a control script in Connect Designer
        /* this script is for demonstration purposes only and is subject to the T&C of the MIT license.
        This script applies the correct portrait or landscape page background to the correct section.
        It is assumed that each record is multi page with mixed portrait and\or landscape orientation
        */

         let printSections = merge.template.contexts.PRINT.sections;
         let numClones = record.tables.detail.length;

          /* Disable both Sections*/
          printSections.Portrait.enabled = false;
          printSections.Landscape.enabled = false;
          /*for (var i = 0; i < printSections.length; i++) {
          printSections[i].enabled = false;
           }
           */
	   
           /* Get the first section (portrait or landscape) and enable it
           and apply the first page as its background
           */
	   
           let firstSection = record.tables.detail[0].fields.pageWidth > 215 ? printSections.Landscape : printSections.Portrait;
	   
           applyBackground(firstSection,1,1);
	   
        /* Loop through each of the remaining pages, get the page orientation,
        then clone the corresponding section and apply the corresponding page
        as the background of the cloned section
        */
	
        for(let i=1; i<numClones; i++){
        if(record.tables.detail[i].fields.pageWidth > 215){
            let landscapeClone = printSections.Landscape.clone();
                landscapeClone.name = "landscapeClone_" + i;
                applyBackground(landscapeClone, i+1, i+1);
                firstSection.addAfter(landscapeClone);
        }else{
            let portraitClone = printSections.Portrait.clone();
                portraitClone.name = "portrait_" + i;
                applyBackground(portraitClone, i+1, i+1);
                firstSection.addAfter(portraitClone);
	        }
         }
	 
	 
        function applyBackground(section, start, end){
        section.enabled = true;
        section.background.source = BackgroundResource.DATAMAPPER_PDF;
        section.background.allPages = false;
        section.background.start = start;
        section.background.end = end;
        }

olconnect-singlerecordmixedorientationpdf's People

Contributors

rodnnr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.