No announcement yet.

How to open a pdf

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to open a pdf

    With the php code:


    you can open a pdf-file. This works

    How to open a pdf-file by clicking on a text field in scriptcase?
    Ok I used de ajax event onclick. But there commes a messagebox with unreadable characters.

    So scriptcase reacts a little bit different
    Wo can help, please....


  • #2
    I think the issue is that the html header providing the pdf is not correct. But I wonder, are you using the readfile code in the ajax event?
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /


    • #3
      Hallo Albert,

      Let me go one step back. What I want is to connect a pdf-file with a scriptcase "administration". So every pdf I have in a map should get a set of properties (we call it metadata).
      I.e. 1235789.pdf has in the scriptcase database the properties: documenttype, documentdate, documentreference, documentauthor etc.
      To fill ( by hand) the record in scriptcase I should have the pdf open in a viewer. In the moment I think acrobat reader is ok for this. The view can be open on a second screen.

      In principle there are 2 steps:
      1. Automaticaly make a new record in the database when a new pdf (from a scanner or mf) is comming in the map, with the connection to this pdf
      2. To open the pdf by clicking on the record or one of the fields (with in the first an empty record) and put the data in on what you can see in the viewer in the record

      I am concentrating on the second step. I donot know how to do the programming in scriptcase.
      With the simple readfile statement I could do outside script case. But I am open for other ideas.

      @ Albert
      Ik zou dit alles ook in het nederlands kunnen doen. Uiteindelijk woon ik op een steenworp afstand van je vandaan....Zwolle
      Maar als je me hiermee kunt helpen, graag. Het afmaken van de applicatie met scriptcase zelf lukt me wel. Het is net dit stukje
      Groet Bert Steinebach.
      Last edited by ctmservice; 01-31-2013, 03:20 AM.


      • #4
        I'm not sure if I am giving a good answer to your question. What I tried was to store a pdf into the downloadarea directly and put it in the database. Then I provided a grid containing the pdf as document. I can download by clicking on the link.

        Bert, Ik heb geprobeerd de download vanuit de javascript te starten. Dat is me nog niet gelukt. Het lukt wel om een file die als display in een grid staat te laten linken zodat als je op de link klikt de pdf getoond wordt. Het hangt van je basis instellingen af of het document op popt of deel uitmaakt van je browser venster. Maar is dit wat je bedoelt? Maak anders een account aan op en stel de vraag daar, dan kunnen we in het nederlands kijken of we het probleem oplossen en de eindoplossing hier plaatsen.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development /


        • #5
          Another option is to add a buttton to your form of type javascript. The next javascript will open your pdf:

          javascript:nm_mostra_doc('0','myfile.pdf','form_do wnload');

          Provided that myfile.pdf is in the configurated directory.
          Albert Drent
          aducom software netherlands
          scriptcase partner, reseller, support and (turn-key) development


          • #6
            With the help of aducom (Albert Drent) we solved this issue. Thanks to him.
            Works very fine with a small php script in a button in a form.

            $file1 = 'c:/mymap/';
            $file2 = {docfile}; //de name of the field in the record of the database of the pdf i.e 12345.pdf
            $file = $file1.$file2;

            if (file_exists($file)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename='.basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));


            • #7
              To document this solution we have added this to the faq on
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development


              • #8
                My situation is a bit different.
                I want to have a grid with the file names stored in a database.
                When the user brings up the grid, I would like for the user to click on a row and bring up the pdf file.
                The example you provide does work with having a button at the top of the grid to bring one "generic pdf" file
                In my case every row needs to display a different pdf file or any type of file.
                I have the grid working by your example with one button at the top of the grid
                I also have a form that does display the pdf document however I need to display the document that is applicable to the file each row contains, does this makes sense????


                • #9
                  For 'any type' of file you I do NOT trust the apache dll and instead use the easier way (and better as I have found) is to use someting like below (adjust to your own need)

                  header("Content-Description: File Transfer");
                  header("Expires: 0");
                  header("Pragma: public");
                  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                  header("Cache-Control: private",false);
                  header("Content-Disposition: attachment; filename=\"" . urlencode($nm_nome_doc) . "\" filename*=UTF-8''" . urlencode($nm_nome_doc));
                  header("Content-Type: $ctype");
                  header('Content-Transfer-Encoding: binary');
                  header("Content-Length: ".filesize($trab_doc));

                  You have to change your php.ini tho to allow
                  And so you just get the file type via the php dll. This should also work for docx. OSX with safari (and on the ipod/ipad as well) still screws up various filedownloads because it doesnt recognize certain mime types.