首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用PDF_get_option()方法获取字体名称?

如何使用PDF_get_option()方法获取字体名称?
EN

Stack Overflow用户
提问于 2022-11-06 05:32:38
回答 2查看 24关注 0票数 0
代码语言:javascript
运行
复制
function nvpdf_WrapString($my_pdf,$string,$width,$width_in_chars = "") {

    // known problem: can only be called after the pdf document has been
    // started, font size set, etc as it relies on the pdf being in the
    // page scope to use pdf_stringwidth (see PDFLib manual p.83).
    // returns an array: 1st level column
    //                   2nd level data string broken up into lines that fit the column
  $string = str_replace('\n', "\n", $string);
  $inlines = explode("\n",$string);
    $outlines = array();

    $font_size = PDF_get_option($my_pdf, "fontsize", "");
    $font_name = pdf_get_parameter($my_pdf, "fontname", 0);
    $font_id = PDF_load_font($my_pdf, $font_name, "host","");

我收到了来自php的反对警告,说我应该使用pdf_get_option()而不是pdf_get_parameter()。但是如何将这个pdf_get_parameter()转换为pdf_get_option()呢?

我需要一个方法,将返回我的字体名称的$mypdf。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-11-06 06:30:01

找到解决办法了。pdf_get_option()不会给我字体名。我所要做的就是使用pdf_info_font(),然后使用pdf_get_string()来获取fontname。

票数 2
EN

Stack Overflow用户

发布于 2022-11-07 07:34:05

很高兴你能自己找到解决方案。

另一个简短的注意事项是:如果您已经为PDFlib函数找到了一个不推荐的警告,那么建议您替换它,即使该功能在您正在使用的版本中仍然有效。这是因为在更新时,不推荐的函数可能不再可用。

当前的PDFlib 9和10包包括一个PDFlib迁移指南,其中详细描述了所有必要的更改。

您还可以在PDFlib 网站pdflib.com上找到最新的网站pdflib.com

对于这一特定问题,你可以在第2.1章表2.3中找到解释:

代码语言:javascript
运行
复制
deprecated parameter:
ascender, ascenderfaked, capheight, capheightfaked, descende, 
descenderfaked, fontencoding, fontname,fontmaxcode, xheight, xheightfaked

deprecated since: 
PDFlib 7 

replacement method and option:
PDF_info_font( ) with same-named keywords; for the numerical 
values fontsize=1 must be supplied;
parameter fontencoding: use keyword encoding

PDFlib烹饪书信息“中也提供了一个示例用法。

代码语言:javascript
运行
复制
/* Get the font name: use "api" to get the font name used by PDFlib.
 * (use "acrobat" for the Acrobat font name or use "full" for
 * retrieving the full font name)
 */
$p->fit_textline("fontname (api):", $x, $y-=$yoffset, "");

$info = $p->info_font($font, "fontname", "api");
if ($info > -1) {
    $fontname = $p->get_string($info, "");
    $p->fit_textline($fontname, $xindent, $y, "");
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74333500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档