【问题标题】:html2pdf is not recognizing space and not able to add marginhtml2pdf 无法识别空间并且无法添加边距
【发布时间】:2011-02-01 23:15:49
【问题描述】:

我有一个没有样式属性的 html 页面。我使用的 HTML 标记是“中心、换行标记、粗体标记”。HTML 页面不包含任何表格。这是一个简单的文档。我需要以下帮助:-

  1. 在 pdf 文件的所有边添加 1 英寸的边距。
  2. 我想以两个制表符的空间开始每个段落。 (“&nbsp”在 html 文件中生成空间,但不在 pdf 文件中。)

我正在使用的代码:--

ob_start();
// start buffering and displaying page
echo 'All the content i m fetching according my requirements';
$file_name_string=substr($guid, 0, 8);
$file_name=$file_name_string.".htm";
file_put_contents($file_name, ob_get_contents());
// end buffering and displaying page
ob_end_flush();
$output_file=$file_name_string.".pdf";
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->SetFont('Arial','B',12);
$pdf->AddPage();
$fp = fopen($file_name,"r");
$strContent = fread($fp, filesize($file_name));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output($output_file);

【问题讨论】:

    标签: php css pdf-generation fpdf html2pdf


    【解决方案1】:

    使用

    $pdf->SetMargins(20,18);
    

    添加边距。我自己使用这个库在一个非常繁忙的电子商务网站上做各种各样的废话。我会看一下我的代码,看看我是否可以提出段落缩进的解决方案。

    我想补充一点,这个库非常适合它的功能,但有时它的局限性非常令人沮丧。

    【讨论】:

      猜你喜欢
      • 2014-03-20
      • 2021-06-29
      • 1970-01-01
      • 2013-06-23
      • 2018-03-25
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 2021-09-06
      相关资源
      最近更新 更多