如何使用pdflib库设置自定义元标记?
问题描述:
我正在使用pdflib库在php中生成pdf。我可以用这个库创建pdf,但不能为pdf生成自定义元标记。如何使用pdflib库设置自定义元标记?
任何人都可以帮我解决这个问题,这样我就可以为我的pdf生成meta标签。
谢谢!
答
标准文档信息标签是Subject, Title, Creator, Author, Keywords, Trapped
。
您使用它们这种方式(至少在PDFlib中7):
PDF_set_parameter($p, "hypertextencoding", "unicode"); PDF_set_parameter($p, "hypertextformat", "utf8"); PDF_set_parameter($p, "usehypertextencoding", "false"); PDF_set_parameter($p, "textformat", "utf8"); PDF_set_info($p, "Creator", $Creator); PDF_set_info($p, "Author", $Author); PDF_set_info($p, "Title", $Title); PDF_set_info($p, "Subject", $Subject); PDF_set_info($p, "Keywords", $Keywords);
,并定义用户定义的标签,使用:
PDF_set_info($p, "MyCustoMKey", $MyCustomValue);
用户自定义标签不能:CreationDate, Producer, ModDate, GTS_PDFXVersion, GTS_PDFXConformance, ISO_PDFEVersion
。
这足以让定制标签变成pdf。但是,如果你硬是要他们为XMP,你可以自动填充您的自定义信息使用选项autoxmp=true
调用PDF_begin_document()
时XMP:
if (PDF_begin_document($p, $pdf_output_file, "autoxmp=true") == 0) { die("Error: " . PDF_get_errmsg($p)); }
我已经测试在实际代码上面,可以确认,它的作品。
替代方案(和更复杂一点)是this。
这个例子使用utf8,由于全球化,现在优选utf8。因此,使用文件编辑器(UltraEdit,Textmate等)或使用命令行工具iconv将您的php文件转换为使用utf8作为mime编码。
看起来像这就是我要找的 – Smit 2012-01-17 16:23:03
试试这个,让我知道你是否有任何困难。 – Smit 2012-01-17 16:23:58