Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

How do I print a Bill, or an Invoice on a custom object on the click of a button.

Things I've thought of

  • Printable view : it does not give me the control to change the formatting
  • Visualforce Page : gives me the styling but how do I automate the printing without multiple clicks?
  • AppExchange Apps : I tried a couple of freebies, but they Don't work when I took a test drive

Thanks for the help !!

share|improve this question
    
Rendering a Page as a PDF could be useful for giving you more control over the print layout. –  Daniel Ballinger Aug 16 '12 at 10:24
    
We found the the Quotes by SalesForce app was sufficient for our needs. did you try it? I don't thin it fits the "one click" though –  Saariko Aug 16 '12 at 10:48

4 Answers 4

up vote 2 down vote accepted

This is the best solution I could think of and it requires a Visualforce page:

<apex:page >
    <script>      
        window.onload = function() { 
            window.print();
        }
    </script>
    <h1>Congratulations</h1>
    <p>This is your new invoice!</p>
</apex:page>

This will render as:

Immediate print

When you close the print popup, you get this:

Screen capture

The <h1> and the <p> tag were put in there purely as test data. The way this works, the page will load and the window.onload event will fire, which will immediately request for the page to be printed. Unfortunately, this will not be a PDF version, but using CSS Media Types, you can style this page using the @media print annotation. Let's take a quick look at that in action:

<apex:page >
    <script>      
        window.onload = function() { 
            window.print();
        }
    </script>
    <style>
        @media print{
            h1{
                font-size:120px;
            }
            p{
                font-size: 70px;
            }
        }
    </style>
    <h1>Congratulations</h1>
    <p>This is your new invoice!</p>
</apex:page>

which will render as:

Print with Large Font

However, when you click cancel, the page will view as:

Non printed page

Notice how the display of the text changed in the first load in the print preview, yet the page itself didn't change. That is the power of @media print. Using Visualforce, HTML, CSS, and Javascript, you can definitely get this all to work. You can strip it down and basically do whatever you want.

The easy thing to then do in order to make this a single click is to simply create a custom button that points to your Visualforce page. The Visualforce page itself will handle all the rest.

share|improve this answer

One of the most popular solutions is Conga Composer by AppExtremes. I've used it successfully for several applications. Their support is excellent as well.

share|improve this answer
    
Conga was made to solve this exact issue and it works very nicely. –  Eric Wu Aug 17 '12 at 19:50

So if I understand correctly, you want to render a view (lets say a PDF) and have that PDF print out without having to download the pdf first and print it manually?

while I don't have a packaged solution, you could achieve a one click solution by putting together a print server on your network that is customized for receiving print requests from the web.

The flow would look a bit like this:

  1. person clicks button, a pdf is rendered.
  2. the pdf is sent (encoded) to a third party service that then sends the print request to your printer.
  3. your publicly available web printer or software on an attached computer would receive the request and start printing the pdf.

you could cut step 2 out if you had a print server on your network that would just wait for print requests from the web.

share|improve this answer

I haven't tried this personally, and am somewhat skeptical that this would work, but you could try:

  1. Create a PDF Visualforce page (See Daniel Ballinger's comment)
  2. Invoking window.print() on the VF page
  3. Creating a custom visualforce button on the object's page layout that opens the VF page.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.