3 Replies Latest reply on Oct 24, 2012 1:43 PM by Zolotoj

    Load a PDF and Print it Without User Seeing the PDF

    ml_webmonk

      I have a client who has a need to allow users via a web browser to print PDFs wihtout gaining direct access to them.  Ignoring all the flaws in this logic , I am new to Flex and am having difficulty determining if this is possible.  So, here are the details:

       

      1) This is a web browser application.

      2) The files reside on a server.

      3) The user will view a list of available PDF files in their browser.

      4) There will be a print icon next to each one.

      5) When they click on the print icon we need to pull in the PDF from the server and initiate a print, all without the user seeing the PDF.  So once they click the print icon the next thing they see is thier browser's print dialog box.

       

      I have 1-4 done, I just need help with the most important one, #5.

      So, can Flex (without AIR) load a PDF in without displaying it and print it?

       

      I am using Flash Builder 4.6, if it matters.

       

      Thanks in advance for any input.

        • 1. Re: Load a PDF and Print it Without User Seeing the PDF
          Zolotoj Level 3

          Well, that's going to be difficult. Before everything else, a silent printing in general, is not what Browser is all about. A print dialog is thrown by the browser when a user selects a print option. Same thing if an application is trying to print using built into it conventional methods of printing - you get Print dialog. It gets even harder if you want to print PDF files silently. You will need to make sure that a file is available to print in case it's generated on the fly. The following code will print your PDF without dialogs to a selected (var printer) printer:

          var WshShell = new ActiveXObject("WScript.Shell");

          var fs = new ActiveXObject("Scripting.FileSystemObject");

          var fi = "AcroRd32.exe /N /T " + '"c:\\temp\\' + "filename" + '" ' + printer;

          WshShell.Run(fi, 0, false);

          As you notice, the file is on the local system. Or you can try printing over the network.

           

          This code will be a part of a JS function in your html wrapper. You will call this function from Flex using ExternalInterface.

          AcroRd32.exe is an Adobe free PDF reader.  I would suggest starting from the end - have a file on the local system and working on everything esle.

           

          HTH

          • 2. Re: Load a PDF and Print it Without User Seeing the PDF
            ml_webmonk Level 1

            Thank you for the response.  I know the requirements to print without the user viewing the PDF in a web browser goes against convention.  But it is the client's requirement.  I do not fell the solution you gave will work for me because this is a linux system.  Plus, to call the application to print, you have to tell it the filename, which the user could see and gain direct access to if they view the HTML.

             

            Just to make sure your term "silent" printing does not confuse things, the user will be clicking on a print icon and we will be initiating the print of the PDF and they can manage the print via the print dialog box that appears.  There is nothing "silent" about it.  We simply do not want them to see it, so the term "blind" print might be suitable.

             

            That said, someone suggested that StageView could be used to load the PDF, then place the stage into a PrintJob and print it.  However, that is an AIR implementation and this is a we application, so with my limited understanding, that will not work.

            • 3. Re: Load a PDF and Print it Without User Seeing the PDF
              Zolotoj Level 3

              As you have mentioned, yuo are running it as a web application. So, no, you cannot load PDF into the app. Plus, I am positive that the print quality and stuff will not be as a good as printing by using native to PDF engines.

              File name was an example. You can use variables for that. Unfortunately, I dont know if you can do scripting on Linux system.