PDF functions

You can use the pdf functions in PHP to create pdf files if you have the PDF library (available at http://www.ifconnection.de/~tm/) by Thomas Merz. Please consult the excelent documentation for pdflib shipped with the source distribution of pdflib or available at http://www.ifconnection.de/~tm/software/pdflib/PDFlib-0.6.pdf. As long as this documentation is not complete the pdflib documentation should be your first choice. The functions in pdflib and the php3 module have the same name. The parameteres are also identical. You should also understand some of the concepts of pdf to efficiently use this module. The pdf module introduces two new types of variables. They are called pdfdoc and pdfinfo.

PDF functions

PDF_get_info

Name

PDF_get_info — Returns a default info structure for a pdf document

Description

info pdf_get_info(string filename);

The PDF_get_info function will return a default info structure for the pdf document. It can be filled with appropriate information like the author, subject etc.

Example 1. PDF_get_info

<?php $info = PDF_get_info(); PDF_set_info_creator($info, "Name of Author") ?>

See also PDF_set_info_creator, PDF_set_info_subject.

PDF_set_info_creator

Name

PDF_set_info_creator — Fills the creator field of the info structure

Description

void pdf_set_info_creator(info info, string creator);

The PDF_set_info_creator function sets the creator of a pdf document. It has to be called after

PDF_get_info and before PDF_open. Calling it after PDF_open will have no effect on the document.

This function is not part of the pdf library.

See also PDF_get_info, PDF_set_info_subject.

PDF_set_info_title

Name

PDF_set_info_title — Fills the title field of the info structure

Description

void pdf_set_info_title(info info, string title);

The PDF_set_info_title function sets the title of a pdf document. It has to be called after

PDF_get_info and before PDF_open. Calling it after PDF_open will have no effect on the document.

This function is not part of the pdf library.

See also PDF_get_info, PDF_set_info_xxxxx.

PDF_set_info_subject

Name

PDF_set_info_subject — Fills the subject field of the info structure

Description

void pdf_set_info_subject(info info, string subject);

The PDF_set_info_subject function sets the subject of a pdf document. It has to be called after

PDF_get_info and before PDF_open. Calling it after PDF_open will have no effect on the document.

This function is not part of the pdf library.

See also PDF_get_info, PDF_set_info_xxxxx.

PDF_set_info_keywords

Name

PDF_set_info_keywords — Fills the keywords field of the info structure

Description

void pdf_set_info_keywords(info info, string keywords);

The PDF_set_info_keywords function sets the keywords of a pdf document. It has to be called after

PDF_get_info and before PDF_open. Calling it after PDF_open will have no effect on the document.

This function is not part of the pdf library.

See also PDF_get_info, PDF_set_info_xxxxx.

PDF_set_info_author

Name

PDF_set_info_author — Fills the author field of the info structure

Description

void pdf_set_info_author(info info, string author);

The PDF_set_info_author function sets the author of a pdf document. It has to be called after

PDF_get_info and before PDF_open. Calling it after PDF_open will have no effect on the document.

This function is not part of the pdf library.

See also PDF_get_info, PDF_set_info_xxxxx.

PDF_open

Name

PDF_open — Opens a new pdf document

Description

int pdf_open(int descripterfile, int info);

The PDF_set_info_author function opens a new pdf document. The corresponding file has to be opened with fopen and the file descriptor passed as argument file. info is the an info structure that has to be created with pdf_get_info.

The return value is needed as the first parameter in all other functions writing to the pdf document.

See also fopen, PDF_get_info.

PDF_close

Name

PDF_close — Closes the pdf document

Description

void pdf_close(int pdf document);

The PDF_close function closes the pdf document int.

It will not close the file. You need to call an extra fclose after pdf_close.

See also PDF_open, fclose.

PDF_begin_page

Name

PDF_begin_page — Starts page

Description

void pdf_begin_page(int pdf document, double height, double width);

The PDF_begin_page function starts a new page with height height and width width. See also PDF_end_page.

PDF_end_page

Name

PDF_end_page — Ends page

Description

void pdf_end_page(int pdf document);

The PDF_end_page function ends a page. See also PDF_end_page.

PDF_show

Name

PDF_show — Output text at current position

Description

void pdf_show(int pdf document, string text);

The PDF_show function outputs the string in text at the current position. See also PDF_show_xy, PDF_set_text_pos.

PDF_show_xy

Name

PDF_show — Output text at position

Description

void pdf_show_xy(int pdf document, string text, double x-koor, double y- koor);

The PDF_show_xy function outputs the string in text at position with koordinates (x-koor, y- koor).

See also PDF_show.

PDF_set_font

Name

PDF_set_font — Select the current font face and size

Description

void pdf_set_font(int pdf document, string font name, double size, string

encoding);

The PDF_set_font function sets the the current font face, font size and encoding. You will need to provide the Adobe Font Metrics (afm-files) for the font in the font path (default is ./fonts).

See also PDF_info.

PDF_set_leading

Name

PDF_set_leading — Sets distance between text lines

Description

void pdf_set leading(int pdf document, double distance);

The PDF_set_leading function sets the distance between text lines. This will be used if text is output by PDF_continue_text.

See also PDF_continue_text.

PDF_set_text_rendering

Name

PDF_set_text_rendering — Determines how text is rendered

Description

void pdf_set_text_rendering(int pdf document, int mode);

The PDF_set_text_rendering function determines how text is rendered. The possible values for mode are 0=fill text, 1=stroke text, 2=fill and stroke text, 3=invisible, 4=fill text and add it to cliping path, 5=stroke text and add it to clipping path, 6=fill and stroke text and add it to cliping path, 7=add it to clipping path.

PDF_set_horiz_scaling

Name

PDF_set_horiz_scaling — Sets horizontal scaling of text

Description

void pdf_set_horiz_scaling(int pdf document, double scale);

The PDF_set_horiz_scaling function sets the horizontal scaling to scale percent.

PDF_set_text_rise

Name

PDF_set_text_rise — Sets the text rise

Description

void pdf_set_text_rise(int pdf document, double value);

The PDF_set_text_rise function sets the text rising to value units.

PDF_set_text_matrix

Name

PDF_set_text_matrix — Sets the text matrix

Description

void pdf_set_text_matrix(int pdf document, array matrix);

The PDF_set_text_matrix function sets a matrix which describes a transformation applied on the current text font.

PDF_set_text_pos

Name

PDF_set_text_pos — Sets text position

Description

void pdf_set_text_pos(int pdf document, double x-koor, double y-koor);

The PDF_set_text_pos function sets the position of text for the next pdf_show function call. See also PDF_show, PDF_show_xy.

PDF_set_char_spacing

Name

PDF_set_char_spacing — Sets character spacing

Description

void pdf_set_char_spacing(int pdf document, double space);

The PDF_set_char_spacing function sets the spacing between characters. See also PDF_set_word_spacing, PDF_set_text_leading.

PDF_set_word_spacing

Name

PDF_set_word_spacing — Sets spacing between words

Description

void pdf_set_word_spacing(int pdf document, double space);

The PDF_set_word_spacing function sets the spacing between words. See also PDF_set_char_spacing, PDF_set_text_leading.

PDF_continue_text

Name

PDF_continue_text — Output text in next line

Description

void pdf_continue_text(int pdf document, string text);

The PDF_continue_text function outputs the string in text in the next line. See also PDF_show_xy, PDF_set_text_leading, PDF_set_text_pos.

PDF_stringwidth

Name

PDF_stringwidth — Returns width of text in current font

Description

double pdf_stringwidth(int pdf document, string text);

The PDF_stringwidth function returns the width of the string in text. It requires a font to be set before.

See also PDF_set_font.

PDF_save

Name

PDF_save — Saves current enviroment

Description

void pdf_save(int pdf document);

The PDF_save function saves the current enviroment. It works like the postscript command gsave. Very useful if you want to translate or rotate an object without effecting other objects.

See also PDF_restore.

PDF_restore

Name

PDF_restore — Restores formerly saved enviroment

Description

void pdf_restore(int pdf document);

The PDF_restore function restores the enviroment saved with PDF_save. It works like the postscript command grestore. Very useful if you want to translate or rotate an object without effecting other objects.

Example 1. PDF_get_info

<?php PDF_save($pdf);

// do all kinds of rotations, transformations, ... PDF_restore($pdf) ?>

See also PDF_save.

PDF_translate

Name

PDF_translate — Sets origin of koordinate system

Description

void pdf_translate(int pdf document, double x-koor, double y-koor);

The PDF_translate function set the origin of koordinate system to the point (x-koor, y-koor).

PDF_scale

Name

PDF_scale — Sets scaling

Description

void pdf_scale(int pdf document, double x-scale, double y-scale);

The PDF_scale function set the scaling factor in both directions.

PDF_rotate

Name

PDF_rotate — Sets rotation

Description

void pdf_rotate(int pdf document, double angle);

The PDF_rotate function set the rotation in degress to angle.

PDF_setflat

Name

PDF_setflat — Sets flatness

Description

void pdf_setflat(int pdf document, double value);

The PDF_setflat function set the flatness to a value between 0 and 100.

PDF_setlinejoin

Name

PDF_setlinejoin — Sets linejoin parameter

Description

void pdf_setlinejoin(int pdf document, long value);

The PDF_setlinejoin function set the linejoin parameter between a value of 0 and 2.

PDF_setlinecap

Name

PDF_setlinecap — Sets linecap aparameter

Description

void pdf_setlinecap(int pdf document, int value);

The PDF_setlinecap function set the linecap parameter between a value of 0 and 2.

PDF_setmiterlimit

Name

PDF_setmiterlimit — Sets miter limit

Description

void pdf_setmiterlimit(int pdf document, double value);

The PDF_setmiterlimit function set the miter limit to a value greater of equal than 1.

PDF_setlinewidth

Name

PDF_setlinewidth — Sets line width

Description

void pdf_setlinewidth(int pdf document, double width);

The PDF_setlinewidth function set the line width to width.

PDF_setdash

Name

PDF_setdash — Sets dash pattern

Description

void pdf_setdash(int pdf document, double white, double black);

The PDF_setdash function set the dash pattern white white units and black black units. If both are 0 a solid line is set.

PDF_moveto

Name

PDF_moveto — Sets current point

Description

void pdf_moveto(int pdf document, double x-koor, double y-koor);

The PDF_moveto function set the current point to the coordinates x-koor and y-koor.

PDF_curveto

Name

PDF_curveto — Draws a curve

Description

void pdf_curveto(int pdf document, double x1, double y1, double x2, double

y2, double x3, double y3);

The PDF_curveto function draws a Bezier curve from the current point to the point (x3, y3) using (x1, y1) and (x2, y2) as control points.

See also PDF_moveto, PDF_lineto.

PDF_lineto

Name

PDF_lineto — Draws a line

Description

void pdf_lineto(int pdf document, double x-koor, double y-koor);

The PDF_lineto function draws a line from the current point to the point with coordinates (x-koor,

y-koor).

See also PDF_moveto, PDF_curveto.

PDF_circle

Name

PDF_circle — Draw a circle

Description

void pdf_circle(int pdf document, double x-koor, double y-koor, double

radius);

The PDF_circle function draws a circle with center at point (x-koor, y-koor) and radius radius. See also PDF_arc.

PDF_arc

Name

PDF_arc — Draws an arc

Description

void pdf_arc(int pdf document, double x-koor, double y-koor, double radius, double start, double end);

The PDF_arc function draws an arc with center at point (x-koor, y-koor) and radius radius, starting at angle start and ending at angle end.

See also PDF_circle.

PDF_rect

Name

PDF_rect — Draw a rectangle

Description

void pdf_rect(int pdf document, double x-koor, double y-koor, double width, double height);

The PDF_rect function draws a rectangle with its lower left corner at point (x-koor, y-koor). This width is set to widgth. This height is set to height.

PDF_closepath

Name

PDF_closepath — Close path

Description

void pdf_closepath(int pdf document);

The PDF_closepath function closes the current path.

PDF_stroke

Name

PDF_stroke — Draw line along path

Description

void pdf_stroke(int pdf document);

The PDF_stroke function draws a line along current path. See also PDF_closepath, PDF_closepath_stroke.

PDF_closepath_stroke

Name

PDF_closepath_stroke — Close path and draw line along path

Description

void pdf_closepath_stroke(int pdf document);

The PDF_closepath_stroke function is a combination of PDF_closepath and PDF_stroke. Than clears the path.

See also PDF_closepath, PDF_stroke.

PDF_fill

Name

PDF_fill — Fill current path

Description

void pdf_fill(int pdf document);

The PDF_fill function fills the interior of the current path with the current fill color.

See also PDF_closepath, PDF_stroke, PDF_setgray_fill, PDF_setgray, PDF_setrgbcolor_fill, PDF_setrgbcolor.

PDF_fill_stroke

Name

PDF_fill_stroke — Fill and stroke current path

Description

void pdf_fill_stroke(int pdf document);

The PDF_fill_stroke function fills the interior of the current path with the current fill color and draws current path.

See also PDF_closepath, PDF_stroke, PDF_fill, PDF_setgray_fill, PDF_setgray, PDF_setrgbcolor_fill, PDF_setrgbcolor.

PDF_closepath_fill_stroke

Name

PDF_closepath_fill_stroke — Close, fill and stroke current path

Description

void pdf_closepath_fill_stroke(int pdf document);

The PDF_closepath_fill_stroke function closes, fills the interior of the current path with the current fill color and draws current path.

See also PDF_closepath, PDF_stroke, PDF_fill, PDF_setgray_fill, PDF_setgray, PDF_setrgbcolor_fill, PDF_setrgbcolor.

PDF_endpath

Name

PDF_endpath — Ends current path

Description

void pdf_endpath(int pdf document);

The PDF_endpath function ends the current path but does not close it. See also PDF_closepath.

PDF_clip

Name

PDF_clip — Clips to current path

Description

void pdf_clip(int pdf document);

The PDF_clip function clips all drawing to the current path.

PDF_setgray_fill

Name

PDF_setgray_fill — Sets filling color to gray value

Description

void pdf_setgray_fill(int pdf document, double value);

The PDF_setgray_fill function sets the current gray value to fill a path. See also PDF_setrgbcolor_fill.

PDF_setgray_stroke

Name

PDF_setgray_stroke — Sets drawing color to gray value

Description

void pdf_setgray_stroke(int pdf document, double gray value);

The PDF_setgray_stroke function sets the current drawing color to the given gray value. See also PDF_setrgbcolor_stroke.

PDF_setgray

Name

PDF_setgray — Sets drawing and filling color to gray value

Description

void pdf_setgray(int pdf document, double gray value);

The PDF_setgray_stroke function sets the current drawing and filling color to the given gray value. See also PDF_setrgbcolor_stroke, PDF_setrgbcolor_fill.

PDF_setrgbcolor_fill

Name

PDF_setrgbcolor_fill — Sets filling color to rgb color value

Description

void pdf_setrgbcolor_fill(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_fill function sets the current rgb color value to fill a path. See also PDF_setrgbcolor_fill.

PDF_setrgbcolor_stroke

Name

PDF_setrgbcolor_stroke — Sets drawing color to rgb color value

Description

void pdf_setrgbcolor_stroke(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_stroke function sets the current drawing color to the given rgb color value. See also PDF_setrgbcolor_stroke.

PDF_setrgbcolor

Name

PDF_setrgbcolor — Sets drawing and filling color to rgb color value

Description

void pdf_setrgbcolor(int pdf document, double red value, double green value, double blue value);

The PDF_setrgbcolor_stroke function sets the current drawing and filling color to the given rgb color value.

See also PDF_setrgbcolor_stroke, PDF_setrgbcolor_fill.

PDF_add_outline

Name

PDF_add_outline — Adds bookmark for current page

Description

void pdf_add_outline(int pdf document, string text);

The PDF_add_outline function adds a bookmark with text text that points to the current page.

PDF_set_transition

Name

PDF_set_transition — Sets transition between pages

Description

void pdf_set_transition(int pdf document, int transition);

The PDF_set_transition function set the transition between following pages. The value of transition can be 0 for none, 1 for two lines sweeping across the screen reveal the page, 2 for multiple lines sweeping across the screen reveal the page, 3 for a box reveals the page, 4 for a single line sweeping across the screen reveals the page, 5 for the old page dissolves to reveal the page, 6 for the dissolve effect moves from one screen edge to another, 7 for the old page is simply replaced by the new page (default)

PDF_set_duration

Name

PDF_set_duration — Sets duration between pages

Description

void pdf_set_duration(int pdf document, double duration);

The PDF_set_duration function set the duration between following pages in seconds.