0

我正在使用 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;
//==============================================================
//==============================================================
//==============================================================
?>
4

6 回答 6

0

因此,只需在成功回调中延迟结果分配

  setTimeout(function(){
      $('.result').html(data);
      $("#imgSpinner1").hide();
  },2000);
于 2013-06-26T08:34:08.407 回答
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..
于 2013-06-26T09:14:21.907 回答
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>
于 2013-06-26T08:49:24.823 回答
0

这是一个简单的方法,,,只需在WriteHTML之前添加这个脚本,,,

.....
.....
$mpdf->SetProtection(array(), 'enang', 'sumarna');


//place before this
$mpdf->WriteHTML(utf8_encode($html));

笔记:

  1. enang 是用户密码
  2. sumarna 是管理员/所有者密码

这对我来说很好

于 2021-07-08T22:59:22.520 回答
0

以下将起作用

$mpdf->SetProtection(array('print', 'copy'), $user_password, $owner_password); 
于 2016-04-11T18:04:42.033 回答
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');
于 2018-08-13T09:14:32.977 回答