6

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>
5
  • 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
    Commented May 15, 2014 at 20:53
  • Do you mean page-break-before: avoid?
    – George S.
    Commented May 15, 2014 at 21:45
  • 1
    I'm currently using "page-break-after:always;". I'll have to experiment with "avoid" to see what happens.
    – Jagular
    Commented May 16, 2014 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? Commented Feb 5, 2019 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 ! Commented Feb 5, 2019 at 11:03

1 Answer 1

6

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

position: absolute;
top: 0;

and it did the trick.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .