in reply to Open generated PDF in new tab/new page in HTML::Mason

I wanted WWW page to open generated PDF in separate Acrobat window, but didn't succeeded
It would be helpful if you described how it is not working. What do you get back, a blank page or a page full of garbage or does the server just hang?

The best you can do is to generate and return a PDF document with the proper HTTP headers. What the client does with the document (opens Acrobat or whatever) depends on how the client is configured. You won't be able to invoke commands on the client's machine with system.

Make the following checks:

  1. Use wget -S http://your/url to see if you are generating the right HTTP headers. You should be sending Content-Type: application/pdf.
  2. Also with wget make sure you are returning a valid PDF file.
  3. Finally, see how the client's browser is configured to handle PDF files. Acrobat should automatically take over handling PDF files when it is installed, but perhaps it got changed.

To open the print dialog, you could put your document in an <iframe> and specify an onload handler for it:

<html> <head> <script> function doit() { window.print(); } </script> </head> <body> <iframe src="your pdf url here" onload="doit()"></iframe> </body> </html>

Replies are listed 'Best First'.
Re^2: Open generated PDF in new tab/new page in HTML::Mason
by grizzley (Chaplain) on May 11, 2008 at 16:56 UTC

    It would be helpful if you described how it is not working. What do you get back, a blank page or a page full of garbage or does the server just hang?

    When I run following command in console:

    perl -le "system 'c:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.ex +e', 'D:\www\my.pdf'"
    Acrobat opens and displays my.pdf as expected. Then I add % system 'c:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe', 'D:\www\my.pdf'; in HTML file and load in browser. The page gets displayed correctly, but there is no additional Acrobat window with my.pdf. I am not sure if I can expect browser to open Acrobat window in such way... Anyway, Javascript suggested by Gangabass leads me in another direction and there will be place for 'normal' headers and standard redirection.

    ++ for the trick with iframe - it works. How to use it when I return 'application/pdf' in HTTP header?

      Then I add % system 'c:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe', 'D:\www\my.pdf'; in HTML file and load in browser.
      You are doing this in your Mason file, right? This will run Acrobat on your server, not the client's machine.
      ++ for the trick with iframe - it works. How to use it when I return 'application/pdf' in HTTP header?
      You have to create a URL which returns your PDF file. You then specify that URL as the src= parameter to the iframe. For instance, try this in the above example HTML document:
      <iframe src="http://www.niso.org/publications/rp/RP-6-2008.pdf"></ifra +me>