2

I have a page that will be rendered as a PDF and the bottom of page will contain Button as Send which will send a PDF to account's email.Is it possible to render a part of a Visualforce page as PDF.

3

Instead of duplication of the page, as suggested by one of the answers, I would suggest to add some parameter to url called render (for example).

Then, in page definition, you can use next construction:

<apex:page 
renderAs="{!IF(ISNULL($CurrentPage.parameters.render),'',$CurrentPagePage.parameters.render)} 
... />

Then about sections. Lets say you have some outputPanel or another block that you don't want to display on PDF. You can easily do:

<apex:outputPanel layout="none" rendered="{!IF($CurrentPage.parameters.render = 'pdf',false, true)} />

Using that approach, you can hide/show sections based render type on demand.

Then, as a result, if you open your page as /apex/Mypage?<some params>&render=pdf - it would be rendered as pdf, and if /apex/MyPage?<some params> - it would be rendered as html

0

As far as I know it's only possible to display the whole page as a PDF using the "renderas=PDF" attribute of the apex:page tag. So you can't display only part of the page, since apex:page is always the root.

What you could do is display a VF page where the user has two options (two buttons or links): Preview Send (they see the PDF) or Actually Send (the email/PDF is sent).

0

Duplicate the same page and only leave the part that you want as PDF. Then from the first page via the button redirect to your other page which will contain renderAs="PDF"

  • As an alternative to duplicating the page, there is PageReference.getContentAsPdf that "Returns the page in PDF, regardless of the <apex:page> component’s > renderAs attribute". – Keith C Mar 23 '16 at 11:09
  • That will return the whole page though, he needs only a section – Boris Bachovski Mar 23 '16 at 11:13
  • 2
    ... meant to say "and include conditional rendering". – Keith C Mar 23 '16 at 11:15
  • @KeithC The conditional rendering would need to make the sendPDF button conditional since you can't render active content in a PDF document. – crmprogdev Mar 23 '16 at 12:43
0
the bottom of page will contain Button as Send which will send a PDF to account's email

A PDF cannot be rendered with active content. As others have said, you'll need to rerender the portion of the page you want to send in a new window and attach it to an email.

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.