Menu

Pdf content not visible in Adobe Reader

Help
2015-10-14
2015-10-14
  • Sanchit Puri

    Sanchit Puri - 2015-10-14

    Hi,

    I have created a PDF using TCPDF. The Pdf gets downloaded to my local system but when i open it on browser the content is visible but when i tried to open it using Adobe Reader in my system there is no content in pdf kindly help

     
  • Simon

    Simon - 2015-10-14

    Please share the PDF and the code.

     
  • Sanchit Puri

    Sanchit Puri - 2015-10-14

    PHP CODE

    function getPdf($html, $name, $img = false, $download = true, $facs_simile = false, $for_saving = false)
    {
    @ob_end_clean();

        $query = "SELECT lang_browsercode, lang_direction"
            . " FROM " . $GLOBALS['prefix_fw'] . "_lang_language"
            . " WHERE lang_code = '" . getLanguage() . "'";
        list($lang_code, $lang_direction) = mysql_fetch_row(mysql_query($query));
    
        if (strpos($lang_code, ';') !== false) {
            $lang_code = current(explode(';', $lang_code));
        }
        $lg = array();
        $lg['a_meta_charset'] = "UTF-8";
        $lg['a_meta_dir'] = $lang_direction;
        $lg['a_meta_language'] = $lang_code;
        $lg['w_page'] = "page";
        $this->setLanguageArray($lg);
    
        /**
         * Protection for the PDF
         *
         * print : Print the document;
         * modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
         * copy : Copy or otherwise extract text and graphics from the document;
         * annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
         * fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
         * extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
         * assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
         * print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
         * owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
         */
        if ($this->isEncrypted()) {
            $this->SetProtection(array('modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high'), '', $this->getPassword());
        }
    
        $this->getAliasNbPages();
    
        $this->AddPage();
        // set JPEG quality
        $this->setJPEGQuality(80);
    
        if ($img != '') {
            $this->setXY(0, 0);
            $this->Image($GLOBALS['where_files_relative'] . '/appLms/certificate/' . $img, 0, 0, ($this->CurOrientation == 'P' ? 206 : 298), 0, '', '', '', true);
            $this->setXY(0, 0);
        }
    
        if ($facs_simile) {
            //Put watermark  Author: Ivan
            $this->SetFont('dejavusans', '', 40);
            $this->SetTextColor(240, 240, 240);
            //$this->RotatedText(15, 50, 'F a c - s i m i l e', 270);
            $this->SetFont("dejavusans", "", 10);
            $this->SetTextColor(0, 0, 0);
        }
        $this->setXY(0, 0);
        //$this->UseCSS(true);
        $this->WriteHTML($html);
    
        $name = str_replace(
            array('\\', '/', ':', '\'', '\*', '?', '"', '<', '>', '|'),
            array('', '', '', '', '', '', '', '', '', ''),
            $name
        );
    
        // maybe there is a way to understand why ie6 doesn't use correctly the 'D' option, but this work so....
    
        if ($for_saving)
            return $this->Output(('"' . $name . '.pdf"'), 'S');
    
        $pdf = $this->Output(('"' . $name . '.pdf"'), 'S');
    
        session_write_close();
        //ini_set("output_buffering", 0);
        //Download file
        //send file length info
        header('Content-Length:' . strlen($pdf));
        //content type forcing dowlad
        header("Content-type: application/download\n");
        //cache control
        header("Cache-control: private");
        //sending creation time
        header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        //content type
        header('Content-Disposition: attachment; filename="' . $name . '.pdf"');
    
        echo $pdf;
        exit();
    }
    

    HTML Used In PDF

    Certificate Id:
    HCPC/GMC Number:
    Reference Number:

    CERTIFICATE OF COMPLETION

    This is certify that Mr/Mrs. John Deo has completed a online Training course. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

    Date: 25/09/2015

    PFA Document of PDF

     
  • Simon

    Simon - 2015-10-14

    I think it may in part be because you are using a font that you haven't embedded.

    Are you able to create test in PHP that isn't part of your application that replicates the fault?

     

Log in to post a comment.