5

I am using the html2canvas library to render the page with a view to rendering the canvas as a PDF. I am saving the canvas as an Attachment fine. The direct link to the attachment looks like this:

enter image description here

without any margin or padding. But when I render it as a PDF there is always a blank first page like so:

enter image description here

I tried adding the margin attribute to the @page but it had no effect. Is there any way to prevent this blank page from appearing? Here's the VF code, the controller just sets the Attachment ID.

<apex:page controller="toPdf" renderAs="pdf"  applyBodyTag="false" applyHtmlTag="false" showHeader="false" cache="false">

<html>
   <head>
    <style>
    @page{
       size: A4 landscape;
       margin: 0in;
    }
   </style>
</head>
<body>
    <apex:image value="/servlet/servlet.FileDownload?file={!attId}"  width="1024px"/>
</body>
</html>
</apex:page>
  • I've encountered the same problem. I was able to shift the blank page to the end of the printout by tinkering with the ".page-break" section of my CSS, but I could not get rid of the page break. – Jagular May 15 '14 at 20:53
  • Do you mean page-break-before: avoid? – George S. May 15 '14 at 21:45
  • 1
    I'm currently using "page-break-after:always;". I'll have to experiment with "avoid" to see what happens. – Jagular May 16 '14 at 14:10
  • Hello, thanks for the fix ! Could you please also tell me all the 'actions' (buttons/something) which you added to reach the PDF page from the 1st HTML calendar/page? – aniltilanthe Feb 5 at 11:01
  • Also the image is not so good in the renderAs=pdf ! it looks a bit blurry in the PDF page. But when I print the PDF page, it looks great as the original good quality image ! – aniltilanthe Feb 5 at 11:03
5

I ended up using the following on the apex:image styleClass:

position: absolute;
top: 0;

and it did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.