Some PDF tricks on Visualforce: Landscape, A4, page number and more | Techila
1281
single,single-post,postid-1281,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

Some PDF tricks on Visualforce: Landscape, A4, page number and more

tips-and-tricks-300x194

Some PDF tricks on Visualforce: Landscape, A4, page number and more

The beauty of Visualforce is simplicity. Remember when you were told the entire page renders as PDF if you just add renderAs=PDF to the Page tag.

Here is the trick, to render a page as PDF, we add a simple attribute to the <apex: page> tag


<apex: page renderAs=’pdf’>

This will render the entire page as PDF.

Now, say we need to add some extra features to the PDF. Like a page number in the footer or we need to render the page in landscape mode. To perform these tricks simply add the following code to your visualforce PDF page and see it bend to your command.

1. Rendering page as landscape


@page {

/* Landscape orientation */

size:landscape;

}


2. Rending page in different size


@page {

  size: 8.5in 11in;/* width height */

}


3. Rendering page in landscape A4


@page {

  size: A4 landscape;

}


4. Adding stuff in footer of the page


@bottom-right {

content: Some content;

}


5. Adding page number to the page


@page {

  size: 8.5in 11in;

  margin: 10%;

 

  @top-left {

    content: “Hamlet”;

  }

  @top-right {

    content: “Page ” counter(page);

  }

}

The other variations in box-model are top-left, top-center, top-right, bottom-left, bottom -right, bottom – center.

Hope this helps creating those awesome looking PDFs in visualforce.

  

Courtesyhttp://www.sforce.ninja/2011/04/some-pdf-tricks-on-visualforce.html

Author: techila

No Comments

Post A Comment