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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP code for opening pdf files

    I have many pdf files and i am embeding flexpaper for online book reading. Whenever a user clicks a link, a new windows opens in which embeded flexpaper pdf can be read.

    Below mentioned code is in the new window html which is opened by clicking "Read Online".Noew problem is that i have 100+ books for which i have to generate 100 Pages, which i don't want to, i want to pass filename in SWFFile : 'docs/Paperpdf.swf', dynamically in the link or through some sort of PHP code so that only file name changes in new window and i would not need to make 100+ pages.Kindly help

    <div id="documentViewer" class="flexpaper_viewer" style="width:770px;height:500px"></div>
    <script type="text/javascript">
    var startDocument = "Paper";
    $('#documentViewer').FlexPaperViewer(
    { config : {
    SWFFile : 'docs/Paperpdf.swf',
    Scale : 0.6,
    ZoomTransition : 'easeOut',
    ZoomTime : 0.5,
    ZoomInterval : 0.2,
    FitPageOnLoad : true,
    FitWidthOnLoad : false,
    FullScreenAsMaxWindow : false,
    ProgressiveLoading : false,
    MinZoomSize : 0.2,
    MaxZoomSize : 5,
    SearchMatchAll : false,
    InitViewMode : 'Portrait',
    RenderingOrder : 'flash',
    StartAtPage : '',
    ViewModeToolsVisible : true,
    ZoomToolsVisible : true,
    NavToolsVisible : true,
    CursorToolsVisible : true,
    SearchToolsVisible : true,
    WMode : 'window',
    localeChain: 'en_US'
    }}
    );
    </script>
    </div>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You simply change your name as you see fit. If it's a PHP file, then target a PHP file and add a querystring if needed. If it requires a swf mime, then you simply have your PHP file serve the swf header which is application/x-shockwave-flash from the looks of it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I think you didn't understood.
    1. External Link of 1.pdf -> External page with php code SWFFile : 'docs/A.swf'
    External Link of 2.pdf -> External page with php code SWFFile : 'docs/B.swf'
    .
    .
    so on for 100 pages. I need to build 100 pages with same flaxpaper code with the above mentioned line which changes

    What i want is to pass name of pdf file eg 1.pdf through variable to External page so that only 1 external page will be required with varying file names. Now how to do it ?
    Kindly dictate word by word as i do not know any language except html and css.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You'd have a single php file and accept a querystring on it. You would then serve it and read the file though:
    PHP Code:
    <?php

    $sSWF 
    = isset($_GET['swf']) ? $_GET['swf'] : 'ADefaultSwfFileNamehere';
    $sFile sprintf('docs/%s.swf'$sSWF);
    if (
    file_exists($sFile) && is_readable($sFile))
    {
        if (
    $fh fopen($sFile'r'))
        {
            
    header('Content-type: application/x-shockwave-flash');        
            
    fpassthru($fh);
            
    fclose($fh);
        }
    }
    Simple as that. Best to add something to deal with the else clause's that I haven't put in there, but no matter what it'd have to be a default swf of some kind (since this needs to be served as swf).
    Call it as: yourphpscript.php?swf=A for example.

    Edit:
    Wait, what's with the PDF's here? Is this something to do with this flexpaper?
    I presumed you are looking for a PHP solution to this, so dynamic wise that's all you need to do to serve a file with a given querystring. Otherwise, I haven't a clue what you're trying to do.

    Edit:
    Am I hung up on swf files for some reason here? What is it you're needing to do with the PDF's directly, just modify them? If so, you'll be needing the PDF library to deal with that: http://php.net/manual/en/book.pdf.php
    It does require a PECL installation in order to use it though. There may also be standard PHP user code available for download. This looks like one of them: http://sourceforge.net/projects/pdf-php/

    Last edited by Fou-Lu; 07-11-2013 at 08:40 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    - A bit of mistake in my previous post:
    Links on sample.htm ->
    Book1 (Link: /phpscript.php?swf=1)
    Book2 (Link: /phpscript.php?swf=2)
    Book3 (Link: /phpscript.php?swf=3)

    These swf should open in Flexpaper which is embeded in flexpaper.htm. The only part of code which should vary in flexpaper.htm:
    .
    .
    .
    SWFFile : 'docs/1.swf',
    .
    .
    .
    -> When i click on Book1 on sample.htm , flexpaper.htm should open with code : SWFFile : 'docs/1.swf'
    -> Likewise, When i click on Book2 on sample.htm , flexpaper.htm should open with code : SWFFile : 'docs/2.swf'

    In this way, only 1 php and 1 flexpaper.htm is required instead of many many pages.I hope i clarified my problem. Kindly give code and method to implement it.

    Sorry you disturbing you again and thank you for you previous reply and time.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Does it need to be .htm file?
    If not, the absolute easiest way to deal with it is to modify the flexpaper.htm and name it flexpaper.php. Then simply modify the swffile to be: 'docs/<?php echo (int)@$_GET['swf'];?>.swf', and then when you call it you would use flexpaper.php?swf=4 for example.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    chintoo123 (07-13-2013)

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Fou-lu, not to hijack this thread but can you briefly explain the type casting you did there? Is it for security purposed (ensuring a numerically named .swf is called) or otherwise?

    I'm guessing security, but I'd like to know for sure

    Thanks
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #8
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, you solved my problem. Thanks many time

  • #9
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can you tell me the code so that only one window opens at a time in external link and same external window updates each time any other link is clicked.

    Link 1 clicked - > External link
    Link 2 clicked - > swf file opens in previously opened external link
    Link 3 clicked - > swf file opens in previously opened external link
    .
    .
    .


  •  

    Posting Permissions

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