Re: How to make a "Auto View" and a "Download" Link for PDF?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jun 21, 2008 at 10:08 AM, Michelle Konzack <
linux4michelle@xxxxxxxxxxxxxxx> wrote:

> ************************************************************************
> *       Do not Cc: me, because I READ THIS LIST, if I write here       *
> *    Keine Cc: am mich, ich LESE DIESE LISTE wenn ich hier schreibe    *
> ************************************************************************
>
> Hello,
>
> I generate PDFs on the fly and I like to setup TWO links on the HTML/PHP
> page for the SAME PDF:
>
>    1)  View
>    2)  Download
>
> I have seen this on other Websites, but can not figure out HOW this  was
> done.
>
> Suggestions?
>
> Thanks, Greetings and nice Day/Evening
>    Michelle Konzack
>    Systemadministrator
>    24V Electronic Engineer
>    Tamay Dogan Network
>    Debian GNU/Linux Consultant
>
>
> --
> Linux-User #280138 with the Linux Counter, http://counter.li.org/
> ##################### Debian GNU/Linux Consultant #####################
> Michelle Konzack   Apt. 917                  ICQ #328449886
> +49/177/9351947    50, rue de Soultz         MSN LinuxMichi
> +33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)
>

I use the dompdf class and ran into the same issue when dealing with that
PoS IE. It wouldn't handle the direct stream from the class so I did a check
for the browser and if its IE then save the file and force a file
download...anything else it just streams from the class to the browser.

function createPDF($html,$thisFileName,$hash)
{

  require_once("includes/dompdf_config.inc.php");

// Turn off all error reporting
//error_reporting(0);

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();

// The next call will store the entire PDF as a string in $pdf

  $pdf = $dompdf->output();

// You can now write $pdf to disk, store it in a database or stream it
// to the client.

//check if IE,since it doesn't like the stream, so we save it to disk and
then stream the saved file
  $browserCheck = browserDetection();

  if ($browserCheck)
  {
      if (!is_dir("../data/$hash"))
      {
        mkdir("../data/$hash");
      } // end is_dir check

// save the file
      if(!file_put_contents("../data/$hash/$thisFileName", $pdf))
      {
        echo "failed to write new pdf file";
      }
// force the download
      showPDF("../data/$hash/$thisFileName");
  }else{
      $dompdf->stream("$thisFileName");
  }// if user agent
}//end function createPDF


-- 

Bastien

Cat, the other other white meat

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux