伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: PDF_findfont

来源:网络转载 浏览:27183次 时间:2024-05-23
PDF_fit_image » « PDF_fill
  • PHP 手册
  • 函数参考
  • 非文本内容的 MIME 输出
  • PDF
  • PDF 函数

PDF_findfont

(PHP 4 >= 4.0.5, PECL pdflib >= 1.0.0)

PDF_findfont — Prepare font for later use [deprecated]

说明

PDF_findfont ( resource $p , string $fontname , string $encoding , int $embed ) : int

Search for a font and prepare it for later use with PDF_setfont(). The metrics will be loaded, and if embed is nonzero, the font file will be checked, but not yet used. encoding is one of builtin, macroman, winansi, host, a user-defined encoding name or the name of a CMap. Parameter embed is optional before PHP 4.3.5 or with PDFlib less than 5.

This function is deprecated since PDFlib version 5, use PDF_load_font() instead.

add a note

User Contributed Notes 9 notes

up down 0 Shamun Toha10 years ago <?php
/*
* This is an example of my first PDF test
* Worked by NuSphere PHPed
* Manualy downloaded library from
* http://pecl4win.php.net/ext.php/php_pdf.dll
*/

/*
* Stage - 1
* Resource create for PDF library
*/
$pdf = PDF_new();

/*
* Stage - 2
* Save where? Path to create the file.
*/
pdf_open_file($pdf, "c:\heloworld.pdf");

/*
* Stage - 3
* Page diemention (A4)
*/
pdf_begin_page($pdf, 595, 842);

/*
* Stage - 4
* path of your TTF font directory
* can also use pdf_load_font();
* http://uk3.php.net/manual/en/function.pdf-findfont.php
*/
$fontdir = "C:\WINDOWS\Fonts";
pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf");
$arial = PDF_findfont($pdf,"arialMyName","host",0 );

/*
* Stage - 5
* Set font size and font name
*/
pdf_setfont($pdf, $arial, 10);

/*
* Stage - 6
* print text
*/
pdf_show_xy($pdf, "Hellow World? ",50, 750);
pdf_show_xy($pdf, "Test 1, 2, 3, 4 working. ", 50,730);

/*
* Stage - 7
* end page
*/
pdf_end_page($pdf);

/*
* Stage - 8
* close and save file
*/
pdf_close($pdf);

?>

Output as pdf:
###################################
#
#   Hellow World?
#   Test 1, 2, 3, 4 working.
#
###################################
up down 0 R. Christiaanse13 years ago If you get the following error,

"PDFlib error: [2518] PDF_findfont: No file specified with outline data for font ..."

you might try the following:

1. Take care the environment variable PDFLIBRESOURCE is correctly set.
  
   You can set it like this: putenv("PDFLIBRESOURCE=C:\phpdev\php\pdf-related\pdflib.upr");
  
2. Take care the resource variabele used by PDFLib is correctly set.

   You can set it like this: pdf_set_parameter($pdf, "resourcefile", "C:\phpdev\php\pdf-related\pdflib.upr");
  
3. Take care the resource file and fonts can be found by adjusting your local include path.

   You can set it like this: ini_set('include_path', 'C:/phpdev/php/pdf-related');
  
4. Take care the paths in the PDFLIB resource file are correct

   Open pdflib.upr in a text editor and modify the path entry (read the comments):
  
   Example: /C:/phpdev/php/pdf-related
  
5. Leave the optional parameter 'embed' out:

   Like this:

   if ($font = pdf_findfont($pdf, "Helvetica", "host", 0))
     pdf_setfont($pdf, $font, 12);
    
   Or this:
  
   if ($font = pdf_findfont($pdf, "Helvetica", "host"))
     pdf_setfont($pdf, $font, 12);

I hope this could be of help to you...
up down 0 sebastien at galliot dot com14 years ago Display UTF-8 string with your PDFlib and true type font
<?php 

/*  UTF-8 : Unicode encoded string with PDFlib & Php
    
*/
$pdf = pdf_new();
if (!pdf_open_file($pdf, ""))
   exit;

PDF_begin_page($pdf, 600,800);

// set the textformat parameter to utf8
pdf_set_parameter($pdf, "textformat", "utf8");  

// path of your TTF font directory
$fontdir = "/path/to/font/directory/";

// Open few .TTF (true type font) 
// be sure that your font file contains enough character for your language

pdf_set_parameter($pdf, "FontOutline", "ArialUnicode=$fontdir/ARIALUNI.TTF");
pdf_set_parameter($pdf, "FontOutline", "ArialItalic=$fontdir/ariali.ttf");

// UTF-8 encoded string (this is bulgarian (cyrillic alphabet))   
$utf_8_string ="Потребление" ;

// Set the font
$font = PDF_findfont($pdf, "ArialUnicode", "unicode",0);
pdf_setfont($pdf, $font, 15);  
// output the encoded string with Arial Unicode font
pdf_show_xy($pdf,  "Arial Unicode : $utf_8_string"   ,40 ,700);  

// output the encoded string with Arial Italic font
$font = PDF_findfont($pdf, "ArialItalic", "unicode",0);
pdf_setfont($pdf, $font, 15);  
pdf_show_xy($pdf,  "Arial Italic  : $utf_8_string"   ,40 ,650);  


PDF_end_page($pdf);
pdf_close($pdf);

$buf = pdf_get_buffer($pdf);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
echo $buf;

pdf_delete($pdf);


?>
up down 0 Mairsil15 years ago An easy way to use .ttf fonts under *nix:

pdf_set_parameter($pdf, "FontOutline", "Arial=/var/path/to/font/arial.ttf");
up down 0 jurgen dot php dot net at nospam dot thewicked dot nl15 years ago try this nice *nix shell code to generate the FontAFM section of your UPR files:

   for i in *.afm
   do
           sep=`echo -e "\r"`
           file=`cat $i | grep FontName | cut -b 10-`
           file=${file//$sep/}
           echo "$file=$i"
   done

it gererates something like this:

   Courier-Oblique=Courier-Oblique.afm
   Courier=Courier.afm
   Helvetica-Bold=Helvetica-Bold.afm
   etc.

probably usefull if you add fonts now and then...
dont be shy to mail me if you find this usefull!
up down 0 chkim at secuve dot com16 years ago you can use korean font.

$font_kr = PDF_findfont($pdf, "HYSMyeongJoStd-Medium-Acro", "KSC-EUC-H", 0);
up down 0 mitch at nospam dot unixprogramming dot net17 years ago A note on fonts...

Everyone should take a look at the PDFlib manual, section 3.3.5 on TrueType fonts and such. In order to not have to embed fonts and have the font metrics file available use one of the 14 internal PDFlib fonts (case sensitive) :

Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique,
Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique,
Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic,
Symbol, ZapfDingbats

Note that "Times New Roman" isn't in there (Times-Roman is, however). All is explained in the PDFlib manual so if you're having trouble with the above example, please check it out.
up down 0 bob at nijman dot de17 years ago Try this:

<?php

//Create & Open PDF-Object
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_set_info($pdf, "Author","Bob Nijman");
pdf_begin_page($pdf, 300, 300);

$font = pdf_findfont($pdf, "Times New Roman", "host", 1);
if ($font) {
    pdf_setfont($pdf, $font, 30);
}

$string = "Hello Berlin-Mitte!";

$width = pdf_stringwidth($pdf, $string);
pdf_set_text_pos($pdf, (300-$width)/2, 200);
pdf_show($pdf, $string);


//close it up
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header('Content-disposition: inline; filename=myTest.pdf');
header('Content-length: ' . strlen($data));
echo $data;

?>
up down 0 martin at better-com dot de17 years ago For using pdf_findfont with pdf_setfont it's a good idea to copy your fonts to a separate directory, i.e. /usr/local/fonts. You should also copy the upr file which comes with PDFlib to this directory. The example code above did not work here until I put a

pdf_set_parameter($pdf, "resourcefile", "/usr/local/fonts/pdflib.upr");

before the line with pdf_findfont().
add a note

官方地址:https://www.php.net/manual/en/function.pdf-findfont.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net