Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Open PDF in a predetermined window size

  1. #1
    Join Date
    Dec 2011
    Location
    Perdido beach, AL
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Open PDF in a predetermined window size

    Hello Everyone, Happy Holidays...

    Is there a way to force the opening of a PDF file (assume there is a link on the page to open the file) into a smaller window? When selecting a link on a test page to open the pdf in a new window, the file opens in a window that I would rather be much smaller.

    Here is a basic link to open a pdf in a new window... Can I force that window to be smaller?

    <a target="_blank" href="a_pdf_file.pdf">Open PDF File</a>

    Any suggestions would be appreciated.

    Steve
    Perdido beach, AL

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Not with HTML alone. You can if you add a little javascript:

    Code:
    <a target="_blank" href="a_pdf_file.pdf" onclick="open(this.href, this.target, 'width=600, height=450, top=200, left=250'); return false;">Open PDF File</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can open a window and have the browser go to the location of the PDF. However, many browsers won't have a built in PDF viewer, so it will just open in their default PDF application after they get the "save as" dialog. There's nothing you can do to control that, but if they do open PDFs in their browser, what John suggested will work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    John's solution doesn't seerm to work in Firefox. It opens the PDF in a full size window on my machine.
    This wors with me:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <title>PDF predetemined size</title>
    
    <script type="text/javascript">
    function pdf(div)
    {close_div=div
    document.getElementById(div).innerHTML="<div style='position: absolute; left: 100px; top: 70px; right: 100px; bottom: 100px; border: 1px solid black'><div style='position: relative; float: right; cursor: pointer; top: 5px;z-index:1000;background:white' onclick='document.getElementById(close_div).innerHTML=&quot;&quot;'>CLOSE&nbsp;<\/div><iframe src='a_pdf_file.pdf' style='position: absolute; width: 100%; height: 100%' frameborder='0'><\/iframe><\/div>"
    }
    </script>
    
    </head>
    
    <body><div>
    <div id="some_div"></div>
    
    <a href="javascript: void(0)" onclick="pdf('some_div')">include PDF</a><br>
    
    </div></body>
    
    </html>
    Arie Molendijk.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by molendijk View Post
    John's solution doesn't seerm to work in Firefox. It opens the PDF in a full size window on my machine.
    That's browser configuration:

    Tools > Options > Tabs > Open new windows in a new tab instead

    I think any, certainly most can do that. If you uncheck that item, the code from my post works in Firefox.

    I just tried your method. It didn't open in the iframe, it opened in the reader, no browser window at all. Even if it had opened in the iframe, it wouldn't have been in a separate browser window.

    The bottom line with this sort of thing is like djr33 says, it depends upon how the browser is configured. And upon the OS - how it's configured to display PDF. The PDF file itself might have some control over where it will allow itself be loaded.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The PDF file itself might have some control over where it will allow itself be loaded.
    I've never heard of that.

    The OS can affect it, although it's really the browser+OS. For example, on a Mac firefox has no PDF plugin (not that I'm aware of), but Safari uses a native in-browser viewer. On a PC, adobe acrobat reader works in most browsers.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jscheuer1 View Post
    The PDF file itself might have some control over where it will allow itself be loaded.
    Quote Originally Posted by djr33 View Post
    I've never heard of that
    I haven't specifically either. I said might. The PDF format is constantly evolving and I did have a professional version of Acrobat once a long while back. It's pretty amazing, even back then the amount of control one could have over the document.

    All of this sort of points to the fact that with PDF and windows (an iframe is also technically a type of window), the browser and other circumstances have more control over the presentation than the designer does.

    The beauty of PDF is that almost everyone can see it and save it. It's great for manuals and other sorts of documents that need to be shared across platforms and referenced in detail. But it's not a presentational tool. You can take your best shot at its presentation. But if you want your content to look and feel a certain way, and it can be represented in HTML, that's the better way to go.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Got it!
    You can use the solution I proposed above, except for the iframe's url.
    You have to put:
    Code:
    ...<iframe src='http://docs.google.com/gview?url=http://your_path/a_pdf_file.pdf&embedded=true'
    Arie.
    EDIT: Your should also make some changements regarding the position of the CLOSE button. Here's a working demo example:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <title>PDF predetemined size</title>
    
    <script type="text/javascript">
    function pdf(div)
    {close_div=div
    document.getElementById(div).innerHTML="<div style='position: absolute; left: 100px; top: 70px; right: 100px; bottom: 100px; border: 1px solid black'><div style='position: relative; float: right; cursor: pointer; top: 30px;left:-17px; z-index:1000;background:white' onclick='document.getElementById(close_div).innerHTML=&quot;&quot;'>CLOSE&nbsp;<\/div><iframe src='http://docs.google.com/gview?url=http://mesdomaines.nu/pdf/pdf1.pdf&embedded=true' style='position: absolute; width: 100%; height: 100%' frameborder='0'><\/iframe><\/div>"
    }
    </script>
    
    </head>
    
    <body><div>
    <div id="some_div"></div>
    
    <a href="javascript: void(0)" onclick="pdf('some_div')">include PDF</a><br>
    
    </div></body>
    
    </html>
    Last edited by molendijk; 12-29-2011 at 08:10 PM.

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    (My comment here is a bit off topic...)
    it's not a presentational tool. You can take your best shot at its presentation. But if you want your content to look and feel a certain way, and it can be represented in HTML, that's the better way to go.
    In my experience, PDFs actually are much more stable than HTML for presentation. If you have a PDF that looks one way on one computer, then it will almost always look the same way on another computer. Once in a while there are issues with that, but usually you can avoid that by setting certain options when creating the PDF, such as whether to embed the core fonts or use the system defaults. At least in my case when I'm used to dealing with foreign character sets (eg, Chinese or Arabic) for publishing linguistics papers, PDFs are the only reliable way to go, compared with word documents for example. On the other hand, HTML is probably a close second, but browser variations make it less stable. PDFs are limited to one resolution (paper size, usually), so HTML is a little better in that sense.
    What difficulties have you had with specifying presentation properties in a PDF? Or do you mean that it's hard to create the PDF in the first place? That's generally true, unless you can export from your program directly as a PDF, in which case it usually looks identical to what you're creating the document in (such as MS Word). Or a "PDF Printer" can be added to your system so that anything you could print can also be converted to a PDF and saved; that's built in on a Mac, but available for PCs.

    Of course if you're making a website, it's always best to use HTML when you can and only use PDFs when you intend for your visitors to download and print or download and save a document. It's also important when you need exact formatting so that everyone has the same document (for example, for a page count reference--- "see page 5").
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I meant (as was the original question) the presentation of the PDF by the browser. Of course, if you embed the fonts and take other precautions, the PDF will look virtually the same to all users. You cannot control what the browser will do or if the user even has a PDF reader installed. If what Arie proposes works as advertised, that gives you more control, but you will have to be satisfied with an iframe. However, this business with iframe gave me an idea. If what Arie says works, you could launch a javascript modal window like FancyBox and have the iframed PDF in it. Browser peculiarities would be minimized and it would look like a separate window. It would be tied to the parent page though, and still relies upon the user having a PDF reader installed that the browser will use in the iframe. This last perhaps not, if the Google PDF/iframe interface obviates that requirement.
    Last edited by jscheuer1; 12-29-2011 at 05:57 AM. Reason: add thoughts for a modal
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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