我正在使用mpdf库创建pdf文件。我想在创建PDF文件后对其进行密码保护。我在mpdf网站上找不到任何选项。如果有任何选择,请告诉我。我用于mpdf的下面的代码。
<?php
$html = "This a test password protected pdf";
//==============================================================
//==============================================================
//==============================================================
include("MPDF56/mpdf.php");
/*$mpdf = new mPDF('', // mode - default ''
'', // format - A4, for example, default ''
0, // font size - default 0
'', // default font family
15, // margin_left
15, // margin right
16, // margin top
16, // margin bottom
9, // margin header
9, // margin footer
'L'); // L - landscape, P - portrait*/
$mpdf=new mPDF('c','A4','','',1,1,1,1,0,0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
// LOAD a stylesheet
$stylesheet = file_get_contents('./pdf_additional_files/style.css');
$mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
$mpdf->WriteHTML($html,2);
$mpdf->Output('mpdf.pdf','I');
exit;
//==============================================================
//==============================================================
//==============================================================
?>
答案 0 :(得分:0)
因此,只需在成功回调中延迟结果分配
setTimeout(function(){
$('.result').html(data);
$("#imgSpinner1").hide();
},2000);
答案 1 :(得分:0)
尝试以下脚本并进行更改
<script>
// Wrap this function in a closure so we don't pollute the namespace
(function worker() {
var randomnumber=Math.floor(Math.random()*11)
//this will start showing your loader
$('.result').show();
$.ajax({
type: "POST",
url: "data.php?limit1=0&limit2="+randomnumber,
beforeSend: function() {
$("#imgSpinner1").show();
},
success: function(data) {
setTimeout(function(){
$('.result').html(data);
$("#imgSpinner1").hide();
},2000);
},
complete: function() {
//this will hide your loader
$('.result').hide();
// Schedule the next request when the current one's complete
setTimeout(worker, 5000);
}
});
})();
</script>
答案 2 :(得分:0)
You have to load the image and display while processing.
<script>
// Wrap this function in a closure so we don't pollute the namespace
(function worker() {
$('#result').htmt('<img id="imgSpinner1" src="../images/ajax-loader.gif" />');
var randomnumber=Math.floor(Math.random()*11)
$.ajax({
type: "POST",
url: "data.php?limit1=0&limit2="+randomnumber,
beforeSend: function() {
$("#imgSpinner1").show();
}, `enter code here`
success: function(data) {
$('#result').html('');
setTimeout(function(){
$('.result').html(data);
$("#imgSpinner1").hide();
},2000);
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 5000);
}
});
})();
</script>
<div id="result"></div>
<?php
$user_ids = mysql_query("select user_name from customer_details limit ".$_REQUEST['limit1'].",".$_REQUEST['limit2']."");
$rows = array();
while ($row_user_names = mysql_fetch_assoc($user_ids))
{
$rows[] = $row_user_names;
}
echo json_encode($rows);
?>
I hope this will help for you..
答案 3 :(得分:0)
以下内容可行
$mpdf->SetProtection(array('print', 'copy'), $user_password, $owner_password);
答案 4 :(得分:0)
Example #1
<?php
$mpdf = new \Mpdf\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());
$mpdf->WriteHTML('Hello World');
$mpdf->Output('filename.pdf');
Example #2
<?php
// Encrypt the file and grant no permissions to the user
// The user will need to use "UserPassword" to open the file
// Owner has full rights using the password "MyPassword"
$mpdf->SetProtection(array(), 'UserPassword', 'MyPassword');
// Encrypt the file and grant permissions to the user to copy and print
// No password is required to open the document`enter code here
// Owner has full rights using the password "MyPassword"
$mpdf->SetProtection(array('copy','print'), '', 'MyPassword');
答案 5 :(得分:0)
这里有一个简单的方法,,,在WriteHTML之前加上这个脚本,,,
event.preventDefault();
注意:
这对我来说很好