zh:tips:pdfexport
将DokuWiki页面输出为PDF
一些用户建议,采用某种方式将HTML和wiki页面转换为PDF文件。
Current pdf export plugins:
You can also see:
共同的修改
为了输出网页到PDF,您需要添加一个按钮到您的wiki。无论您是使用何种PDF转换器,您都需要执行以下修改:
- 编辑“lib/tpl/main.php”,添加一个 Export to PDF 按钮, 如下:
<div class="bar" id="bar_top"> <div class="bar-left" id="bar_topleft"> <?php tpl_button('edit')?> <?php tpl_button('history')?> <?php print html_btn('exportpdf',$ID,'', array('do' => 'export_pdf')) ?> <!-- inserted line --> </div>
如果你想要的按钮显示在底部边条中,使用编号= “ bar_bottom ”
- 添加一个新的字符串到
inc/lang/en/lang.php
(或你使用的其他语言):
$lang['btn_exportpdf'] = 'Export to PDF';
- 为了显示上述“exportpdf”的PDF图标 ,请在“inc/html.php”文件中执行以下操作:
找到这一行:
$ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
然后用下面的代码进行替换:
//这使得插入的图标显示在菜单栏中 if ($name=="exportpdf"){ $ret .= '<input type="image" src="../lib/images/fileicons/pdf.png" value="'.htmlspecialchars($label).'" '; }else{ $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" '; }
html2ps PHP 脚本
通过PHP脚本使用html2ps只需要更改和添加很少的DokuWiki源代码。
- 安装html2ps.(运行这个php脚本你需要事先安装ghostscript或 libpdf)
- 添加上述的Export to PDF按钮.
- 在“inc/actions.php”文件的“act_export”子程序中,添加:
if ($act == 'export_pdf') {header("Location: ".DOKU_BASE .'html2ps/html2ps.php?URL='.urlencode(wl($ID, '',true)) .'&pixels=1024&media=A4&ps2pdf=2&output=0&cssmedia =screen&renderimages=1&scalepoints=1&leftmargin =10&rightmargin=10&topmargin=10&bottommargin=10'); exit; }
插曲
如果你想删除wiki的格式结构并发送的原始HTML格式到PDF文件,用如下方法编辑代码:
urlencode(wl($ID, '', true))
⇒
urlencode(wl($ID, '', true).'&do=export_html')
您还可以更改html2ps命令的其他选项,这些内容可以在html2ps网站上找到。我的建议是加上“renderlinks=1”和“method=fastps”(使用ghostscript生成PDF时)。
html2ps的其他话题
如果你的WIKI使用https协议, 那么去html2ps的补丁代码.
问题
这似乎只与网页允许匿名的读取有关。
*有人想知道我可以在哪里找到html2ps.php文件?。它不提供这个软件包。 谢谢。
zh/tips/pdfexport.txt · 最后更改: 2012-07-18 23:03 由 Klap-in