Save pdf files in folder using TCPDF I have installed Print module and also TCPDF library to generate PDF files. However, Print module can just create PDF files to download, but not to save in server folder. I have tried to change method _print_pdf_tcpdf in Print module, so files can be saved in server folder. I have changed _print_pdf_tcpdf function  as follows:

I have changed line 

$pdf-&gt;Output($filename, $output_dest);


to this line: 

$pdf-&gt;Output($filename, 'F');


But this code throws error: 

TCPDF ERROR: Unable to create output file: https://mywebsite/sites/default/files/aaa.pdf


I have set permissions for sites folder to write. Another modules can write into this folder, so I dont think the problem is in permissions. 
Can anybody help
where can be problem?
I've made a couple of TCPDF implementations myself in Drupal. As Clive suggested, you shouldn't use URIs in TCPDF's output() method, instead you'll want to provide absolute filepaths.

This code has always worked for me:

// Change the path to whatever you like, even public:// will do or you could also make use of the private file system by using private://
$path = drupal_realpath('public://folder/folder2/folder3');

// Supply a filename including the .pdf extension
$filename = 'file.pdf';

// Create the full path
$full_path = $path . '/' . $filename;

// Output PDF
$pdf-&gt;Output($full_path, 'F');


EDIT: As Clive mentioned in the comment, drupal_realpath() is deprecated. Here's an alternative:

// Change the path to whatever you like, even public:// will do or you could also make use of the private file system by using private://
$uri = 'public://folder/folder2/folder3';
$stream = file_stream_wrapper_get_instance_by_uri($uri);
$path = DRUPAL_ROOT . '/' . $stream-&gt;getDirectoryPath() . '/' . file_uri_target($uri);

// Supply a filename including the .pdf extension
$filename = 'file.pdf';

// Create the full path
$full_path = $path . '/' . $filename;

// Output PDF
$pdf-&gt;Output($full_path, 'F');


Just make sure you're always providing an absolute path for TCPDF.