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
blakeLLblakeLL 

Reduce Margins on Render As PDF

I have a Visualforce page rendering as PDF. I have two problems:

 

1) One of the pages has text that fits completely on the page, but for whatever reason the page wraps to a new blank page. How can I make the pdf stop after that last element.

 

<table width="100%" cellspacing="0" cellpadding="0" class="signaturebox1">
<tr>
<td colspan="2" width="46%" class="signatureheading1">
Authorized Agent for LetterLogic, Inc.:<br /><br />
</td>
<td>&nbsp;</td>
<td colspan="2" width="46%" class="signatureheading1">
Authorized Agent for {!opportunity.account.name}:<br /><br />
</td>
</tr>
<tr>
<td class="signatureline1">Signature<br /><br /></td>
<td class="signatureline1">Date<br /><br /></td>
<td>&nbsp;</td>
<td class="signatureline1">Signature<br /><br /></td>
<td class="signatureline1">Date<br /><br /></td>
</tr>
<tr>
<td class="signatureline1bot">Name</td>
<td class="signatureline1bot">Title</td>
<td>&nbsp;</td>
<td class="signatureline1bot">Name</td>
<td class="signatureline1bot">Title</td>
</tr>
</table>
</apex:page>

 

2) I would like to reduce the margins of at least that page to be more like 0.25 inches or 0.50 inches. Seems like the default is 0.75 inches. The PDF is cutting off the text.

 

Thank you!

prageethprageeth

Hello Blake;

I am not very much clear about your first question. However you can change the page margin by adding following part at the top of your page. 

If I have correctly understood your first question, it also would be fixed by changing the page margin.

 

<apex:page renderAs="pdf" standardController="Opportunity">

<head>

<style>

@page{

margin:0.25in;

}

</style>

</head> 

 

 

 

JPlayEHRJPlayEHR

Thanks prageeth! This is exactly what I needed.

Kent ManningKent Manning

Hi Blake,

 

There is a great resource on setting PDF document properties at: www.antennahouse.com/CSSInfo/CSS-Page-Tutorial-en.pdf. Download the PDF and use it as a reference.  It really helped me when I had to render a visualforce page as a PDF on A4 paper size.



thunksalotthunksalot

Thanks so much for posting the link to that guide, Blake.  It is really helpful!

umesh atryumesh atry
this css  page-break-inside: avoid;, page-break-before: avoid; works only when you need to iterate on componet. if you are using inline pre-built css into page then you have to check following css related to body tag. like this:

body { box-sizing: border-box; height: 11in; margin: 0 auto; overflow: hidden; padding: 0.5in; width: 8.5in; }

here  i am using width and height with auto value.