I have a small requirement is there any way in which we can print Attachments in custom VF page store under any record(ex: Account.)

My Requirement is display a table and give a link to print. When user click on the link we should open a Popup of print module.

I am able to give user this Open View Options

But they want this

Print Popup.

Can anyone please confirm if this is possible in Salesforce or using any third party tool or any Java WS(Means any way if possible).



The answer to Print PDF directly from JavaScript might spare your users the second click. After a little testing, this works for me:

<apex:page >
    <script type="text/javascript">
    function printPDF(pdfId) {
        // Get iframed document
        var doc = document.getElementById(pdfId);
        doc = doc.contentWindow || doc;

        // Not ready to print?
        typeof doc.print === 'undefined' ?
            // Wait some
            setTimeout( function(){printPDF(pdfId)},1000) :
            // Ok, print
    <apex:form >
        <apex:commandButton onclick="printPDF('pdf');return false;" value="Print"/>
        <iframe src="/resource/1456133737000/example" id="pdf" style="display:none;"/>

Note: In the above example I am referencing a pdf uploaded as a static resource.


Unfortunately, this won't work with attachments, since salesforce hosts them on a different (sub)domain, in my case:


whereas the page resides on:


Since the page and the embedded / iframed content are not on the same domain, javascript cannot execute any functions of those contents.

  • let me check. Although i have tried it. Feb 22 '16 at 7:48
  • not working doc.print = 'undefined' is always undefined. or if i try window.print(); then it will print blank pages. Feb 22 '16 at 8:05
  • In the above code, so long as doc.print is undefined it sets a new timeout. So, what exactly did you try?
    – tobibeer
    Feb 22 '16 at 8:23
  • i tried exactly same code. Feb 22 '16 at 9:08
  • 1
    @TusharSharma, I edited my answer to show a working example.
    – tobibeer
    Feb 22 '16 at 10:02

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.