San Diego: PDFGenerationAPI No Longer Respects CSS Paged Media

John104
Tera Contributor

I noticed that the changes to the PDFGenerationAPI between Rome and San Diego seem to include ignoring any CSS Paged Media that you pass to the convertToPDF method.

For example, if you use the following template:

<style>
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  img,
  picture,
  canvas,
  svg {
    display: block;
    max-width: 100%;
  }

  p,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    overflow-wrap: break-word;
    margin-bottom: 1em;
  }

  @page {
    size: letter portrait;
    margin: 1in;

    @top-left {
      content: "Page - "counter(page);
    }
  }

  @page :first {
    margin-top: 1.75in;

    @top-left {
      content: "";
    }

    @top-center {
      content: element(runningPageHeader);
    }
  }

  #pageHeader {
    height: 1.16in;
    position: running(runningPageHeader);
  }

  #pageHeader img {
    height: 1.14in;
  }
</style>
<div id="pageHeader"><img src="https://dev113776.service-now.com/throw-me-a-frickin-bone-dr-evil-meme.png" /></div>
<p>Dr. Evil&#39;s image should appear in the header.</p>
<p>Page margins should be 1&#34;.</p>
<p> </p>
<p>The</p>
<p>Dr.</p>
<p>Evil</p>
<p>image</p>
<p>should</p>
<p>only</p>
<p>appear</p>
<p>on</p>
<p>the</p>
<p>first</p>
<p>page</p>
<p>because</p>
<p>of</p>
<p>the</p>
<p>CSS</p>
<p>Paged</p>
<p>Media</p>
<p>Query</p>
<p>that</p>
<p>allows</p>
<p>you</p>
<p>to</p>
<p>differentiate</p>
<p>the</p>
<p>first</p>
<p>page</p>
<p>&#64;page {<br /> size: letter portrait;<br /> margin: 1in;<br /><br /> &#64;top-left {<br /> content: &#34;Page -
  &#34; counter(page);<br /> }<br />}</p>
<p>&#64;page :first {<br /> margin-top: 1.75in;<br /> <br /> &#64;top-left {<br /> content: &#34;&#34;;<br /> }<br />
  &#64;top-center {<br /> content: element(runningPageHeader);<br /> }<br />}</p>

Then you run convertToPDF you will notice that the generated PDFs look different. In Rome, the Paged Media styles are enforced providing the pages margins and custom headers. However, in San Diego the Paged Media styles are ignored and the margins revert to the default and headers are not shown.

This seems like a pretty glaring bug. Has anyone else experienced this?

1 ACCEPTED SOLUTION

Jeffrey Siegel
Mega Sage

I have a fix for this From ServiceNow's support team:

 

This is a current issue in San Diego, but it is fixed in the Tokyo release. In the meantime, below is the work around.

It is possible to enable the older Code for: sn_pdfgeneratorutils.PDFGenerationAPI(); 

by setting the system property:  com.snc.pdfgenerator.html2pdf.api.version to value 1. (For San Diego the default setting is "2").

 

 

This fixed it for me!!

View solution in original post

5 REPLIES 5

Jeffrey Siegel
Mega Sage

I have a fix for this From ServiceNow's support team:

 

This is a current issue in San Diego, but it is fixed in the Tokyo release. In the meantime, below is the work around.

It is possible to enable the older Code for: sn_pdfgeneratorutils.PDFGenerationAPI(); 

by setting the system property:  com.snc.pdfgenerator.html2pdf.api.version to value 1. (For San Diego the default setting is "2").

 

 

This fixed it for me!!