Step by step - Learn how to use callas productscallas pdfChip What is new in 1.1Additional info when placing PDF pages (# of pages, page geometry)

Additional info when placing PDF pages (# of pages, page geometry)

pdfChip 1.1 introduces the possibility to determine information about imported PDF pages, namely:

  • number of pages of the PDF file from which a page has been imported (see cchip.getPDFPageCount(obj) below)
  • complete page geometry information for each of the pages (see cchip.getPDFPageBox(obj, box) below)

This capability makes it possible to find out essential information about PDF pages to be imported without having to preprocess such PDF file or without having to have prior knowledge about such a PDF file. It is nonetheless required to first import at least one page – if in doubt, import the first page – of the resp. PDF. Using JavaScript it is then possible to adjust the settings for the imported PDF page, or to import additional PDF pages and set or adjust their page geometry dependent settings as needed.

cchip.getPDFPageCount(obj) 

cchip.getPDFPageCount(obj)  returns the number of pages in the PDF file, of which a page has been referenced in the src attribute of an <image> element. The parameter obj must be a reference to that <image> element.  One way to retrieve that reference to the <image> element is the use of a function call such as document.getElementById("my_pdf_id"), where "my_pdf_id" is the ID property of that element.

Example for cchip.getPDFPageCount(obj) 

The example shown below simply logs the number of page in the imported PDF to the console (which will show up on stdout) by using cchip.getPDFPageCount(obj).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Retrieve number of pages in imported PDF</title>
<script>
    function cchipPrintLoop(){
        var obj = document.getElementById("my_pdf_id");  
        cchip.log( '# of pages: ' + cchip.getPDFPageCount(obj) );
        cchip.printPages();
    }
</script>
</head>
<body>
    <div>
        <img id="my_pdf_id" src='sample.pdf#page=1' height="100%" width="100%" /> 
    </div>
</body>
</html>

Output (on stdout) from running the above example with an imported PDF file of 17 pages:

JsCChipObject::log: # of pages: 17

cchip.getPDFPageBox(obj, box)

cchip.getPDFPageBox(obj, box)  returns the width and height for the PDF page referenced in the src attribute of an <image> element. The parameter obj must be a reference to that <image> element.  One way to retrieve that reference to the <image> element is the use of a function call such as document.getElementById("my_pdf_id"), where "my_pdf_id" is the ID property of that element.

Example for cchip.getPDFPageBox(obj, box)

The example shown below illustrates the use of cchip.getPDFPageBox(obj,box).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<title>Retrieving number of pages for an imported PDF</title>
<script>
    function cchipPrintLoop(){
      var obj = document.getElementById("my_pdf_id");  
      function printBox( box ) {
          cchip.log( box + " box: " + JSON.stringify( cchip.getPDFPageBox(obj, box) ) );
      }
      printBox("trim");
      printBox("crop");
      printBox("bleed");
      printBox("media");
      printBox("art");
      cchip.printPages();
    }
</script>
</head>
<body>
	<div>
      <img id="my_pdf_id" src='example.pdf#page=7' height="100%" width="100%" />
	</div>
</body>

Output (on stdout) from running the above example:

JsCChipObject::log: trim box: {"height":467.7445983886719,"width":381.3650207519531}
JsCChipObject::log: crop box: {"height":472.8420104980469,"width":385.918212890625}
JsCChipObject::log: bleed box: {"height":450,"width":375}
JsCChipObject::log: media box: {"height":487.5,"width":390}
JsCChipObject::log: art box: {"height":472.8420104980469,"width":385.918212890625}