2017-04-27 5 views
0

codeigniterでパスワードを保護したPDFファイルを作成することはできますか?電子メールで送信するPDFファイルを保護するためにパスワードを使用する必要があります。CodeigniterパスワードでPDFファイルを作成

これは誰でも知っていますか?メール用のhttps://mpdf.github.io/reference/mpdf-functions/setprotection.html#examples

<?php 

    $mpdf = new mPDF(); 

    // Encrypt the file and grant no permissions to the user to copy, print etc. 

    // The user will be able to open the file as no password is specified 

    // Owner cannot access full rights because no owner_password was set 

    $mpdf->SetProtection(array(), 'UserPassword', 'MyPassword'); 

    $mpdf->WriteHTML(' 
    Hallo World 
    '); 

    $mpdf->Output('filename.pdf'); 

    ?> 

この例のようにMPDFライブラリの使用では

+0

どのライブラリを使用してPDFを作成しましたか? –

+0

私は@BharatDangar – Antonio

+1

のライブラリを知りません。このhttps://mpdf.github.io/reference/mpdf-functions/setprotection.html#examples –

答えて

1

これ。

Example - Sending file as e-mail (and also to browser) 

<?php 

$mpdf = new mPDF(); 

$mpdf->WriteHTML($html); 

$mpdf->SetProtection(array(), 'UserPassword', 'MyPassword'); //set password 

$content = $mpdf->Output('', 'S'); 

$content = chunk_split(base64_encode($content)); 

$mailto = '[email protected]'; 

$from_name = 'Your name'; 

$from_mail = '[email protected]'; 

$replyto = '[email protected]'; 

$uid = md5(uniqid(time())); 

$subject = 'Your e-mail subject here'; 

$message = 'Your e-mail message here'; 

$filename = 'filename.pdf'; 

$header = "From: ".$from_name." <".$from_mail.">\r\n"; 

$header .= "Reply-To: ".$replyto."\r\n"; 

$header .= "MIME-Version: 1.0\r\n"; 

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 

$header .= "This is a multi-part message in MIME format.\r\n"; 

$header .= "--".$uid."\r\n"; 

$header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 

$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 

$header .= $message."\r\n\r\n"; 

$header .= "--".$uid."\r\n"; 

$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; 

$header .= "Content-Transfer-Encoding: base64\r\n"; 

$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 

$header .= $content."\r\n\r\n"; 

$header .= "--".$uid."--"; 

$is_sent = @mail($mailto, $subject, "", $header); 

$mpdf->Output(); 
+0

を参照してください。ありがとう。 – Antonio

関連する問題