Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question how to use LPR command in javascript

    I am trying to use the LPR command inside a javascript to print a PDF file directly to the printer. Want just a simple webpage with a button which will print test.pdf when clicked.

    lpr -S xxx.xxx.xxx.xxx -P print -o l C:\Users\xxxxxx\Desktop\test.pdf

    I know very little when it comes to javascript. If you know of a better way to use the lpr command, please let me know.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    lpr is a command-line command and is not valid Javascript syntax.

    If you embed the pdf in your webpage and reference the object id, you should be able to do it.

    e.g. in your HTML:

    Code:
    <object id = "examplePDF" type="application/pdf" data="example.pdf" width="500" height="500">
    in your javascript:

    Code:
    <script>
    var pdf = document.getElementById("examplePDF");
    pdf.print():
    </script>

    Another way:-

    Code:
    <iframe src="document.pdf" id="PDFtoPrint"></iframe>
    <input type="button" value="Print" onclick="document.getElementById('PDFtoPrint').focus(); document.getElementById('PDFtoPrint').contentWindow.print();">
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 11-03-2010 at 08:09 PM.

  • Users who have thanked Philip M for this post:

    smaftei (11-04-2010)


  •  

    LinkBacks (?)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •