ashraful006
ashraful006

Reputation: 21

How to use PDF_get_option() method to get font name?

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","");

I got a deprecation warning from php saying that I should use pdf_get_option() instead of pdf_get_parameter(). But how can I convert this pdf_get_parameter() to pdf_get_option()?

I need a method that will return me the font name of $mypdf.

Upvotes: 0

Views: 198

Answers (2)

Rainer
Rainer

Reputation: 2185

nice that you could find the solution yourself.

Another quick note: If you have found a deprecated warning for a PDFlib function, it is recommended to replace it even if the functionality still works in the version you are using. This is because the deprecated function may no longer be available when updating.

The current PDFlib 9 and 10 packages include a PDFlib Migration Guide which describes all necessary changes in detail.

You can also find the latest PDFlib 10 Migration Guide on the PDFlib Web site pdflib.com.

for this particular question you would find the explanation in chapter 2.1 table 2.3:

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

A sample usage is also available in the PDFlib cookbook "font/font_info".

/* 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, "");
}

Upvotes: 1

ashraful006
ashraful006

Reputation: 21

Found the solve. pdf_get_option() wont give me the font name. All I have to do is use pdf_info_font() and then use pdf_get_string() to get the fontname.

Upvotes: 2

Related Questions