Hi, I need to know if it is possible not only to dowload the generated PDF on the fly, but to save it in the server folder (I am using Private Upload module). Please don't think this is an issue related to that module; if there is any way to save the PDF file in the server and keep track of it, I can then handle it, move it, create the corresponding entry in files table, etc.

Maybe this is a feature request. But for now I need a work-around because this is a very urgent issue to me... thank you.

Alex

CommentFileSizeAuthor
#21 print_pdf-801680-pdf-hook.patch1.24 KBbalian0303

Comments

danielbeeke2’s picture

paste: file_put_contents("sites/default/files/print/" . $filename, $pdf);
on line 170 of print_pdf.pages.inc
and make folder called print inside your files folder.

Greetings Daniel

alextronic’s picture

wow Daniel, thank you so much!
I will try that,
Alex

jcnventura’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Becker-and-Becker’s picture

Status: Closed (fixed) » Active

I seem to get a blank file (0 bytes) in the files/print folder when using dompdf, i have added the above code to line 170, but I dont get any output generated to the file. Please could you assist.

scottatdrake’s picture

Status: Active » Closed (fixed)

Just a note for the next person....

You can achieve the same result using the TCPDF library by adding the following lines to the end of the function _print_pdf_tcpdf in print_pdf.pages.inc (line 305 or so):

$output_dest = 'F';
$pdf->Output('sites/default/files/print/'.$filename, $output_dest);
scottatdrake’s picture

So... is there any function that would allow me to simulate clicking on the printpdf link for a given node? I've been wading through these controller functions for some time without success.

cbessire’s picture

Status: Closed (fixed) » Active

I added this line
file_put_contents("sites/default/files/print/" . $filename, $pdf);
on the line 170.
I get the same problem as 3degreesdesign... 0k bite file.
Is there a fixed
I'am using DOMPDF and I can't change

cbessire’s picture

Status: Active » Fixed

Found a trick to save to the server :

adding those lines juste after $dompdf->render(); (line 205)

$pdfoutput = $dompdf->output();
$filepath = "sites/default/files/print/" . $filename .".pdf";
$fp = fopen($filepath, "w");
fwrite($fp, $pdfoutput);
fclose($fp);

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chipway’s picture

Has anybody managed to save pdf files to server sites/default/files/print folder with wkhtmltopdf ?

Following #1 + #9, i can do it with dompdf, but i would like to do the same with wkhtmltopdf.

Thank you

Apfel007’s picture

sub

bogdan1988’s picture

Hi, everyone, I just want to propose you solution without hacking print-email-pdf. We can simply create appropriate directories and get pdf file content by file_get_contents() and then using file_put_contents() to put file in appropriate dir.

$date = date('d-m-Y');
    $file_path  = variable_get('file_public_path', conf_path() . '/files/webform');
    $path = $_SERVER['DOCUMENT_ROOT'] . base_path() . $file_path . '/' . $date;
    //here we will create directory to store order files
    if(file_prepare_directory($path,  FILE_CREATE_DIRECTORY)){
      global $base_root;
      $test =  $base_root . '/printpdf/' . $node->nid;
      $pdf = file_get_contents($test);
      $path .= '/' . $node->nid;
      if(!empty($pdf) && file_prepare_directory($path,  FILE_CREATE_DIRECTORY)){
        $path .= '/order.pdf';
        file_put_contents($path, $pdf);
      }
    }
PeterX-dupe’s picture

Version: 6.x-1.8 » 7.x-2.x-dev
Status: Closed (fixed) » Active

Hello Bogdan where and how I have to install the Snipsel. Greeting Peter

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Most of this functionality is already in the module.. There's a PDF cache mechanism that saves a copy of the PDFs in the filesystem.

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No further info in more than two weeks. Closing the issue.

yevgeny.ananin’s picture

Hi. Am I missing something? Is there a config setting to enable the cache mechanism that saves a copy of the PDFs to the filesystem? If not I'm going to give comment #13 a try.

EDIT:
Following the advice in comment #13 worked for me

5t4rdu5t’s picture

Issue summary: View changes

Here's a code snippet that works. Generates PDF file contents from a Drupal path and saves it to the temporary directory.

 // Get PDF contents
  $path = 'some/path/in/mywebsite';
  module_load_include('inc', 'print_pdf', 'print_pdf.pages');
  $pdf = print_pdf_generate_path($path, array(), NULL, '');
  if (!empty($pdf) ) {
    // Save temporary file
    $temp_file = file_directory_temp() . '/' . 'myFileName.pdf';
    $file_saved = file_put_contents($temp_file, $pdf);
    if ($file_saved) {
       // Do some more stuff...
    }
  }

Hope it helps someone...

gans2910’s picture

Hi,

I tried code from comment #18. It creates pdf and save it on server. But it create other html as well. Such as it prints other tabs like Edit, Delete, Likes. Also it prints console errors at the last page of pdf.

I also tried comment #13. But file_get_contents with printpdf url return nothing.

Any idea why this is not working?

Thanks,
gans

Johnny Koh’s picture

Hi All,

I'm trying #1 but the PDFs are not saving. Did I add the code wrongly?

// If cache is off or file is not cached, generate one from scratch
    if (empty($pdf)) {
      $pdf = print_pdf_generate_html($html, $meta, NULL, $paper_size, $page_orientation);
    }

    if (!empty($pdf)) {
      // A PDF was created, save it to cache if configured\
      if ($cachemiss) {
        if (file_unmanaged_save_data($pdf, $cachefile, FILE_EXISTS_REPLACE) == FALSE) {
          file_put_contents("sites/default/files/ServiceReport/" . $filename, $pdf);
          watchdog('print_pdf', 'Failed to write to "%f".', array('%f' => $filename), WATCHDOG_ERROR);
        }
      }
      return $pdf_filename ? print_pdf_dispose_content($pdf, $pdf_filename) : $pdf;
    
balian0303’s picture

StatusFileSize
new1.24 KB

I worked out out by introducing a hook.

sj.suraj’s picture

I am using dompdf for generating pdf in Drupal 7. its working very fine on localhost. But its not working on online server. There it is not generating page also. It just reload the page again. Anybody please help me.

tassaf’s picture

should be added in line 167

if (!empty($pdf)) {
+ file_put_contents("sites/default/files/test.pdf", $pdf);

Michael Langbein’s picture

Comment #13 by Bogdan is really the best solution.
Just make sure that the permissions for going to that link are set correctly - this is what I was struggling with at first :)