2

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).

Thanks

0

1 Answer 1

2

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
            doc.print();
    }
    </script>
    <apex:form >
        <apex:commandButton onclick="printPDF('pdf');return false;" value="Print"/>
        <iframe src="/resource/1456133737000/example" id="pdf" style="display:none;"/>
    </apex:form>
</apex:page>

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

Attachents

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

https://c.eu6.content.force.com/servlet/servlet.FileDownload?file=id

whereas the page resides on:

https://c.eu6.visual.force.com/apex/PrintPDF

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

9
  • let me check. Although i have tried it. Feb 22, 2016 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, 2016 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, 2016 at 8:23
  • i tried exactly same code. Feb 22, 2016 at 9:08
  • 1
    @TusharSharma, I edited my answer to show a working example.
    – tobibeer
    Feb 22, 2016 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .