Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : PDF Functions : PDF_findfont

PDF_findfont

Prepare font for later use [deprecated] ()
int PDF_findfont ( resource p, string fontname, string encoding, int embed )


Related Examples ( Source code ) » pdf_findfont



Code Examples / Notes » pdf_findfont

chkim

you can use korean font.
$font_kr = PDF_findfont($pdf, "HYSMyeongJoStd-Medium-Acro", "KSC-EUC-H", 0);


bob

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;
?>


jurgen dot php dot net

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!


r. christiaanse

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...


leander hanwald

Hi
--- English ----
Be carefull if you want to use german umlauts.
I tried it with libpdf 5.x and used the builtin paramater.
After i created a pdf I saw that all umlauts are a space ('ä' -> ' ')
I tried it with winansi and it works.
---- German ---
Vorsicht bei der Benutzung von Deutschen Umlauten.
Ich habe hier libpdf 5.x im Einsatz und habe es mit dem Parameter "buildin" versucht. Leider waren danach alle Umlaute nur Leerstellen ('Ä' -> ' ').
Als ich es mit "winansi" versucht habe hat es funktioniert.


martin

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().


sebastien

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

?>


mairsil

An easy way to use .ttf fonts under *nix:
pdf_set_parameter($pdf, "FontOutline", "Arial=/var/path/to/font/arial.ttf");


mitch

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.


Change Language


Follow Navioo On Twitter
PDF_activate_item
PDF_add_annotation
PDF_add_bookmark
PDF_add_launchlink
PDF_add_locallink
PDF_add_nameddest
PDF_add_note
PDF_add_outline
PDF_add_pdflink
PDF_add_table_cell
PDF_add_textflow
PDF_add_thumbnail
PDF_add_weblink
PDF_arc
PDF_arcn
PDF_attach_file
PDF_begin_document
PDF_begin_font
PDF_begin_glyph
PDF_begin_item
PDF_begin_layer
PDF_begin_page_ext
PDF_begin_page
PDF_begin_pattern
PDF_begin_template_ext
PDF_begin_template
PDF_circle
PDF_clip
PDF_close_image
PDF_close_pdi_page
PDF_close_pdi
PDF_close
PDF_closepath_fill_stroke
PDF_closepath_stroke
PDF_closepath
PDF_concat
PDF_continue_text
PDF_create_3dview
PDF_create_action
PDF_create_annotation
PDF_create_bookmark
PDF_create_field
PDF_create_fieldgroup
PDF_create_gstate
PDF_create_pvf
PDF_create_textflow
PDF_curveto
PDF_define_layer
PDF_delete_pvf
PDF_delete_table
PDF_delete_textflow
PDF_delete
PDF_encoding_set_char
PDF_end_document
PDF_end_font
PDF_end_glyph
PDF_end_item
PDF_end_layer
PDF_end_page_ext
PDF_end_page
PDF_end_pattern
PDF_end_template
PDF_endpath
PDF_fill_imageblock
PDF_fill_pdfblock
PDF_fill_stroke
PDF_fill_textblock
PDF_fill
PDF_findfont
PDF_fit_image
PDF_fit_pdi_page
PDF_fit_table
PDF_fit_textflow
PDF_fit_textline
PDF_get_apiname
PDF_get_buffer
PDF_get_errmsg
PDF_get_errnum
PDF_get_font
PDF_get_fontname
PDF_get_fontsize
PDF_get_image_height
PDF_get_image_width
PDF_get_majorversion
PDF_get_minorversion
PDF_get_parameter
PDF_get_pdi_parameter
PDF_get_pdi_value
PDF_get_value
PDF_info_font
PDF_info_matchbox
PDF_info_table
PDF_info_textflow
PDF_info_textline
PDF_initgraphics
PDF_lineto
PDF_load_3ddata
PDF_load_font
PDF_load_iccprofile
PDF_load_image
PDF_makespotcolor
PDF_moveto
PDF_new
PDF_open_ccitt
PDF_open_file
PDF_open_gif
PDF_open_image_file
PDF_open_image
PDF_open_jpeg
PDF_open_memory_image
PDF_open_pdi_page
PDF_open_pdi
PDF_open_tiff
PDF_pcos_get_number
PDF_pcos_get_stream
PDF_pcos_get_string
PDF_place_image
PDF_place_pdi_page
PDF_process_pdi
PDF_rect
PDF_restore
PDF_resume_page
PDF_rotate
PDF_save
PDF_scale
PDF_set_border_color
PDF_set_border_dash
PDF_set_border_style
PDF_set_char_spacing
PDF_set_duration
PDF_set_gstate
PDF_set_horiz_scaling
PDF_set_info_author
PDF_set_info_creator
PDF_set_info_keywords
PDF_set_info_subject
PDF_set_info_title
PDF_set_info
PDF_set_layer_dependency
PDF_set_leading
PDF_set_parameter
PDF_set_text_matrix
PDF_set_text_pos
PDF_set_text_rendering
PDF_set_text_rise
PDF_set_value
PDF_set_word_spacing
PDF_setcolor
PDF_setdash
PDF_setdashpattern
PDF_setflat
PDF_setfont
PDF_setgray_fill
PDF_setgray_stroke
PDF_setgray
PDF_setlinecap
PDF_setlinejoin
PDF_setlinewidth
PDF_setmatrix
PDF_setmiterlimit
PDF_setpolydash
PDF_setrgbcolor_fill
PDF_setrgbcolor_stroke
PDF_setrgbcolor
PDF_shading_pattern
PDF_shading
PDF_shfill
PDF_show_boxed
PDF_show_xy
PDF_show
PDF_skew
PDF_stringwidth
PDF_stroke
PDF_suspend_page
PDF_translate
PDF_utf16_to_utf8
PDF_utf32_to_utf16
PDF_utf8_to_utf16
eXTReMe Tracker