OL Learn

Dynamic background(s) from PDF

I have a COTG app where a variable amount of pages are printed into it. The customer makes annotations and we output a PDF. I’m trying to make the PDF page the background image and then add the annotation on top of that. But I’m not getting the background image just blank. If I change background.url to use one in images (doh.jpg) every page has that image. Any idea why this isn’t putting the PDF page as the background image?

var pdfDoc = 'file:///C:/_PlanetPress/Temp/' + record.fields.uid + '_Rotate0.pdf';

var numPages = resource(pdfDoc).pages;
var pageName = 'Orginal_Form';
logger.info('num pages is ' + numPages);

for(var i = 1; i<= numPages; i++)
{
  var clone = printSections[pageName].clone();
  var pdfResourcePage = pdfDoc + '?page=' + i;
  logger.info(pdfResourcePage); // output is  file:///C:/_PlanetPress/Temp/0109DTS0U2LLWEB_Rotate0.pdf?page=1, page2, page3...
  clone.background.source = BackgroundResource.RESOURCE_PDF;
  clone.background.url = pdfResourcePage;
  //clone.background.url = 'images/doh.jpg';  //works add's this image to all pages
  clone.background.position = MediaPosition.FIT_TO_MEDIA;
  clone.name = pageName+'-'+i;
  clone.enabled = true;
  printSections[pageName].addAfter(clone);
  

}

I bolded the changes in the code below. Hope that works for you! :smiley:

for(var i = 1; i<= numPages; i++)
{
var clone = printSections[pageName].clone();
//var pdfResourcePage = pdfDoc + ‘?page=’ + i; commented out!!!
clone.background.source = BackgroundResource.RESOURCE_PDF;
clone.background.url = pdfDoc;
clone.background.start = i;
clone.background.end = i;
clone.background.position = MediaPosition.FIT_TO_MEDIA;
clone.name = pageName+’-’+i;
clone.enabled = true;
printSections[pageName].addAfter(clone);
}

Perfect!! Thanks for the help

Jerry