Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save PDF file in server #164

Closed
mohamedtijani opened this issue Feb 1, 2017 · 5 comments
Closed

Save PDF file in server #164

mohamedtijani opened this issue Feb 1, 2017 · 5 comments

Comments

@mohamedtijani
Copy link

The 'F' option of the Output () method to save to the server does not work
version html2pdf 4.5.1

@SohanTirpude
Copy link

Yeah, same issue in version 4.5.0 also. Throwing 500 error.

@titostoerfall
Copy link

Workaround for this is:
[ ... ]
$html2pdf->writeHTML($content);
$pdfTest = $html2pdf->Output('', true);
file_put_contents('test.pdf', print_r($pdfTest, true));
[/...]

regards

@spipu
Copy link
Owner

spipu commented May 17, 2017

what is exactly the error ?

@wnunez09
Copy link

wnunez09 commented Jun 12, 2017

help handler, can modify for your need:

#Generic Function:
function GenPDF($html) {
	$pdf = new FPDF();
	$pdf->AddPage();
	$pdf->SetFont('Arial', 'B', 16);
	$pdf->Cell(40, 10, $html);
	$pdf->Output();
}
#Inicializa el Archivo PDF y sus Variables
function InitPDFSistem() {
	$P           = [];
	$P['CONT']   = ''; #Content
	$P['FNAME']  = 'File name '; #Filename
	$P['VIEW']   = 'P'; #Formatview P=Portrait, L=Landscape
	$P['PSIZE']  = 'LETTER'; #Page size
	$P['LANG']   = 'en'; #Lang
	$P['TITTLE'] = 'Tittle'; #Tittle
	$P['AUTOR']  = 'Autor'; #Autor
	$P['F']      = 0;
	$P['out']    = true; #output param
	return $P;
}
#generate to disk
function GenPDF2List($P) {
	try {
		$html2pdf = new HTML2PDF($P['VIEW'], $P['PSIZE'], $P['LANG']);
		if ($P['F']==0) {
			#no se cambia el font
		}elseif($P['F']==1) {
			$html2pdf->setDefaultFont("dot_matrix2");
		}
		$html2pdf->pdf->SetAuthor($P['AUTOR']);
		$html2pdf->pdf->SetTitle($P['TITTLE']);
		$html2pdf->writeHTML($P['CONT']);
		$P['DOC'] = $html2pdf->Output($P['FNAME'], $P['out']);
		return $P;
	} catch (HTML2PDF_exception $e) {
		echo $e;
	}
}
#generated to send via email
function GenPDF2Mail($P) {
	try {
		$html2pdf = new HTML2PDF($P['VIEW'], $P['PSIZE'], $P['LANG']);
		$html2pdf->pdf->SetAuthor($P['AUTOR']);
		$html2pdf->pdf->SetTitle($P['TITTLE']);
		$html2pdf->writeHTML($P['CONT']);
		$P['DOC'] = $html2pdf->Output($P['FNAME'], $P['out']);
		return $P;
	} catch (HTML2PDF_exception $e) {
		echo $e;
	}
}

Usage in other Function page:
to Disk:

#Open FTP DIALOG Server
	function OpenFTP($FTP) {
		$FTP['conn'] = ftp_connect(FTP_HOST, FTP_PORT);
		return $FTP;
	}
	#FTP Loggin
	function LoginFTP($FTP) {
		$FTP['LR'] = ftp_login($FTP['conn'], FTP_USER, FTP_PASSWORD);
		return $FTP;
	}
	#Set mode Connection 
	function SetModeFTP($FTP) {
		ftp_pasv($FTP['conn'], FTP_MODE);
		return $FTP;
	}
	#FTP Conection ready checker
	function CheckifReadyFTP($FTP) {
		if ((!$FTP['conn']) || (!$FTP['LR'])) {
			$FTP['chk'] = false;
		} else {
			$FTP['chk'] = true;
		}
		return $FTP;
	}
	#Close FTP Connection
	function CloseFTP($FTP) {
		ftp_close($FTP['conn']);
	}
	#Upload Star FTP Handle
	function StartFTP() {
		$FTP        = [];
		$FTP['SMG'] = '';
		$FTP        = $this->OpenFTP($FTP);
		$FTP        = $this->LoginFTP($FTP);
		$FTP        = $this->SetModeFTP($FTP);
		$FTP        = $this->CheckifReadyFTP($FTP);
		if ($FTP['chk'] == true) {
			$FTP['SMG'] = 'Conneccion Correcta Lograda';
		}
		return $FTP;
	}
	#Upload file from memory handler
	function UpVFileFTP($fpname,$filecontent) {	
		$fp1 = fopen('php://temp', 'r+');
		fwrite($fp1, $filecontent);
		rewind($fp1);
		$FTP       = $this->StartFTP();
		$conn      = $FTP['conn'];
		
		$iFile['sDir']='/u/user/intlu/linux/';
		
		$fileout=$iFile['sDir'].$fpname;
		$upload = ftp_fput($conn, $fileout, $fp1, FTP_BINARY);
		if (!$upload) {
			$FTP['SMG'] ="¡Fail upload FTP!";
		} else {
			$FTP['SMG'] ="Succesfull Upload";
		}
		$this->CloseFTP($FTP);
		return $FTP;
	}

to E-Mail(phpMailer):

$mail->AddStringAttachment($eMailAtachment, $eMailAtachmentName . '.pdf', "base64", "application/pdf");

You need Define all Variable that you see on this code...

spipu added a commit that referenced this issue Jun 14, 2017
@spipu
Copy link
Owner

spipu commented Jun 14, 2017

it has been fixed on master branch.

It was a TCPDF error with relative path. I add some protection to avoid it

@spipu spipu closed this as completed Jun 14, 2017
icebird93 pushed a commit to EduBase/html2pdf that referenced this issue Jun 18, 2018
aaryarajojuH added a commit to aaryarajojuH/spipu that referenced this issue Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants