Last active
February 25, 2024 22:33
-
-
Save the-last-byte/13a98d2b99c8bbc1e5f0db6fb97c218e to your computer and use it in GitHub Desktop.
VisualForce PDF with Background Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page renderAs="advanced_pdf" | |
applyBodyTag="false" | |
standardStylesheets="false" | |
showHeader="false" | |
sideBar="false" | |
showChat="false" | |
applyHtmlTag="false"> | |
<html lang="en"> | |
<head> | |
<title>SOME TITLE</title> | |
<style type="text/css" media="print"> | |
@page { | |
/* Set your page size */ | |
size: A4 portrait; | |
/* Position the background in the top left corner of every page */ | |
@top-left-corner { | |
content: element(background_image); | |
} | |
} | |
/* Style the background image. Here is is matching the size of the A4 page */ | |
/* Note that the position running is essential */ | |
div.background_image { | |
position: running(background_image); | |
display: block; | |
top: 0; | |
left: 0; | |
width: 21cm; | |
height: 29.7cm; | |
} | |
/* Here the background is being set to fill each page. Place any content */ | |
/* within this style and the parent html div to meet your requirements. */ | |
div.background_image img { | |
display: block; | |
width: 100%; | |
height: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- This is the background image - pulled from a static resource --> | |
<div class="background_image"> | |
<apex:image value="{!URLFOR($Resource.Public_Images, 'Letter_background.jpg')}"> | |
</apex:image> | |
</div> | |
<!-- Add your content here --> | |
</body> | |
</html> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps are as follows: