How do I save a PDF locally on the server?

I have tried about a hundred times to get this tight but at best I am left with a mangled PDF (logo issues mostly) . I just want to take a PDF Manager record and turn it into a PDF and save that PDF locally on the server.  I can download the PDF Manager record from the module and it looks fine and I just what that file on the Servers HDD.

I tried this code (edited - I might have missed something but this is the jist of it)

$template = $this->get_PDF_html($pdf_template);
          $base_module = $template['type'];

          if ($record_id != '') {
               $bean = BeanFactory::retrieveBean($base_module, $record_id);

          $object_arr = array();
          $object_arr[$base_module] = $bean->id;

          if ($base_module === 'Contacts') {
               $object_arr['Accounts'] = $bean->account_id;

          $search = array(
.*?</script>@si',// Strip out javascript
               '@<[\/\!]*?[^<>]*?>@si',        // Strip out HTML tags
               '@([\r\n])[\s]+@',            // Strip out white space
               '@&(quot|#34);@i',            // Replace HTML entities

          $replace = array(
               ' ',

          $text = preg_replace($search, $replace, $template['html']);
          $pdf_html_parser = new templateParser();
          $parse_html = $pdf_html_parser->parse_template($text, $object_arr);
          $file = $this->create_PDF($parse_html, $record_module);

     public function get_PDF_html($pdf_id)
          $html = '';
          $page_break = '<div style="page-break-before:always">&nbsp;</div>';
          $is_first_page = true;
          $template = array();
          $pdf_template = new PdfManager();
          $template['id'] = $pdf_template->id;
          $template['name'] = $pdf_template->name;
          $template['type'] = $pdf_template->base_module;
          $template['html'] = $pdf_template->body_html;
          return $template;

     public function create_PDF($html, $name)
          $tcpdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
          $name = str_replace(' ', '_', $name);
          $date = date('Y-m-d');
          $file_info['file_path'] = "upload/" . $name . '_' . $date . ".pdf";
          $file_info['file_name'] = $name . '_' . $date . ".pdf";
          $tcpdf->writeHTML($html, true, false, true, false, '');
          $tcpdf->Output($file_info['file_path'], "F");
          return $file_info;

This code gives me a PDF but it does not look like the PDF I download from the app menu.  Dos anyone have a clue how I would do this?

Parents Reply Children
No Data