Monday 3 June 2013

Using CSS in pdf for page numbering with API 28.0 (@page CSS properties)

Generating PDF in salesforce is very easy with renderAs="pdf" attribute of apex page tag.For those of you needing sample on how to achieve this ,the below link points in right direction to get started and create some professional documents using some CSS power and Visualforce tags

http://wiki.developerforce.com/page/Creating_Professional_PDF_Documents_with_CSS_and_Visualforce

With API 28.0 my designed visualforce pages stopped showing the pagenumbers and other CSS attributes using style with @page annotations .

Here is the code that i tried in sample page to figure the issue with less code



  
  


This code yielded a pdf with no page number and hence conclusion that the @page CSS style properties are not working in API 28.0
Now the question arises like why it works in API 27.0 and not in API 28.0 .To understand this i read enhancements that came in API 28.0 on visualforce .I inserted html tag at start in API 27.0 and found again that @page attribute was not working.Hence injection of html above the head tag creates the issue .

To remove the issue i used the API 28.0 feature to stop the injection of html tag. Here is the working code



  
  

Setting applyHtmlTag as false stops the injection of the html tag and hence the page again started working as expected in API 28.0

7 comments:

  1. Great work! I experienced the same issue and thanks to your help I have the solution!

    ReplyDelete
    Replies
    1. Glad that it helped !!Whats the feedback on blog?

      Delete
  2. Hi Mohit,

    For me its not working ...

    ReplyDelete
    Replies
    1. Which release your vf is in?Please post so i can help at this issue

      Delete
  3. Hello Mohit,

    This is not working for me in version 29 of API. It was working fine for version 26, but I lost the page formating after update to last version.

    I think that Salesforce dev team is not mature. They always change the API but never change the documentation in time. Developing Salesforce applications has been a lot of time Googling for issues and how to deal of Bugs (as the classic CommandButton and apex:param bug).

    Suggestions?

    ReplyDelete
    Replies
    1. Can you please post the code to help you?You can always keep lower version and deploy .

      Delete

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...