function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jhelblingjhelbling 

Rendering a page in PDF with different margin on last page

Hi all,

 

Using a VF Page and the renderas property set to "PDF", I can correctly create a PDF. Using the following in the <style> tag allows me to set the margin for my PDF :

 

@page { 
  size: letter portrait;
  margin-top: 50px;
  margin-bottom: 300px;
}

 

My question is : is there a way to have a different margin-bottom only for my last page ?

 

Thank you very much.

sherodsherod

Sadly, no, I don't think so.

 

CSS2/3 have a @page:left @page:right and @page:first selectors, but no @page:last.

 

You might want to consider CongaMerge which can generate PDFs from Word templates and will be able to do this.

jhelblingjhelbling

As a workaround I tried the following :

 

<div style="position:fixed; top:1px>
  some text
</div>
<div style="position:relative; top:1px>
  <apex:repeat> .... </apex:repeat>
</div>
<div style="position:fixed; bottom:1px>
  some text
</div>

 

As you can see my second div has its position set to relative. This is because of the repeat element, if I fix this div the repeat is not able to provide more than one page in PDF (I had the confirmation by SFDC Support).

 

However when I try to use an approach like the above, I get the following error : PDF generation failed. Check the page markup is valid.

 

If I modify my first DIV (only the first ... and not the last one) in order to use a relative position, it then works ...

 

Does anybody have an idea why I can fix my first DIV, but only the last one ?

 

Thank you very much.