cvs: phpdoc-es /reference/pdf reference.xml
| From: | Javier Tac�n Iglesias | Date: | Sat, 17 Jan 2004 17:06:16 +0000 |
| Subject: | cvs: phpdoc-es /reference/pdf reference.xml | ||
| Groups: | php.doc.es | ||
| Request: | Send a blank email to doc-es+get-476@lists.php.net to get a copy of this message | ||
jtacon Sat Jan 17 12:06:16 2004 EDT
Modified files:
/phpdoc-es/reference/pdf reference.xml
Log:
Traducción
Index: phpdoc-es/reference/pdf/reference.xml diff -u phpdoc-es/reference/pdf/reference.xml:1.2 phpdoc-es/reference/pdf/reference.xml:1.3 --- phpdoc-es/reference/pdf/reference.xml:1.2 Mon Apr 15 20:33:22 2002 +++ phpdoc-es/reference/pdf/reference.xml Sat Jan 17 12:06:16 2004 @@ -1,235 +1,354 @@ <?xml version="1.0" encoding="iso-8859-1"?> +<!-- $Revision: 1.3 $ --> <reference id="ref.pdf"> - <title>PDF functions</title> + <title>Funciones PDF</title> <titleabbrev>PDF</titleabbrev> <partintro> - - <simpara> - You can use the PDF functions in PHP to create PDF files if you - have the PDF library by Thomas Merz (available at - <ulink url="&url.pdf;">&url.pdf;</ulink>; - you will also need <ulink url="&url.jpeg;">the JPEG library</ulink> - and <ulink url="&url.tiff;">the TIFF library</ulink> to - compile this. These two libs also quite often make problems when - configuring php. Follow the messages of configure to fix possible - problems. If you use pdflib 2.01 check how the lib was installed. - There should be file or link libpdf.so. Version 2.01 just creates - a lib with the name libpdf2.01.so which cannot be found when linking - the test programm in configure. You will have to create a symbolic - link from libpdf.so to libpdf2.01.so.). - </simpara> - <simpara> - Version 2.20 of pdflib has introduced more changes to its API and - support for chinese and japanese fonts. This unfortunately causes - some changes of the pdf module of php4 (not php3). If you use pdflib 2.20 - handle the in memory generation of PDF documents with care. Until - pdflib 3.0 is released it might be unstable. The encoding parameter - of <function>pdf_set_font</function> has changed to a string. This - means that instead of e.g. 4 you have to use 'winansi'. - </simpara> - <simpara> - If you use pdflib 2.30 the <function>pdf_set_text_matrix</function> - will have gone. It is not supported any more. In general it is a good - advise to consult the release notes of the used version of pdflib - for possible changes. - </simpara> - <simpara> - Since version 3.0 of pdflib you should configure pdflib with the option - <literal>--enable-shared-pdflib</literal>. - </simpara> - <simpara> - Any version of PHP4 after March, 9th 2000 do not support versions - of pdflib older than 3.0. PHP3 on the other hand should not be used - with version newer than 2.01. - </simpara> - <simpara> - Please consult the excellent documentation for - pdflib shipped with the source distribution of pdflib. - It provides a very good overview of what pdflib capable of doing. - Most of the functions in pdflib - and the PHP module have the same name. The parameters are also - identical. You should also understand some of the concepts of PDF - or Postscript to efficiently use this module. - All lengths and coordinates are measured in Postscript points. - There are generally 72 PostScript points to an inch, but this - depends on the output resolution. - </simpara> - <simpara> - There is another PHP module for pdf document creation based on - <ulink url="&url.cpdf;">FastIO's</ulink>. - ClibPDF. It has a slightly different API. Check the - <link linkend="ref.cpdf">ClibPDF functions</link> section for - details. - </simpara> - <simpara> - Currently all versions of pdflib are supported. It - is recommended that you use the newest version since it has more - features and fixes some problems which required a patch for the old - version. Unfortunately, the changes of the pdflib API in 2.x - compared to 0.6 have - been so severe that even some PHP functions had to be altered. Here - is a list of changes: - </simpara> - <itemizedlist> - <listitem> + <section id="pdf.intro"> + &reftitle.intro; + <simpara> + Las funciones PDF en PHP pueden crear ficheros PDF utilizando + la librería PDFlib creada por + <ulink url="&url.pdflib.merz;">Thomas Merz</ulink>. + </simpara> + <simpara> + La documentación en esta sección solamente es una + descripción de las funciones de la librería PDFlib + y no debería considerarse una referencia exhaustiva. + Se ha de consultar la documentación incluida en el + código fuente de la distribución de PDFlib para + una completa y detallada explicación de cada + función. Proporciona muy buena descripción + de las capacidades de PDFlib y contiene actualizada la + documentación de todas las funciones. + </simpara> + <simpara> + Todas las funciones de PDFlib y del módulo PHP tienen + nombres iguales para las funciones y parámetros. Se + necesitará entender algunos de los conceptos + básicos de PDF y PostScript para un eficiente uso + de esta extensión. Todas las longitudes y coordenadas + se mesuran en puntos PostScript. Generalmente hay 72 puntos + PostScript por pulgada, pero esto depende de la + resolución de salida. Se puede consultar la + documentación incluida en la distribución de + PDFlib para una detallada explicación del sistema + de coordenadas utilizado. + </simpara> + <simpara> + Hay que tener en cuenta que la mayoría de las + funciones PDF requieren un primer parámetro + <parameter>pdfdoc</parameter>. En los siguientes + <link linkend="pdf.examples">ejemplos</link> hay más + información. + </simpara> + <note> <simpara> - The Info structure does not exist anymore. Therefore the function - <function>pdf_get_info</function> is obsolete and the functions - <function>pdf_set_info_creator</function>, - <function>pdf_set_info_title</function>, - <function>pdf_set_info_author</function>, - <function>pdf_set_info_subject</function> and - <function>pdf_set_info_keywords</function> do not take the - info structure as the first parameter but the pdf document. This - also means that the pdf document must be opened before these functions - can be called. The above functions can and should also be replaced by - <function>pdf_set_info</function> + Si se está interesado en alternativas de generadores gratis de PDF que + no utilizen liberías externas PDF, mirar + <link linkend="faq.using.freepdf"> este FAQ relacionado</link>. </simpara> - </listitem> - <listitem> - <simpara> - The way a new document is opened has changed. The function - <function>pdf_open</function> takes only one parameter which is - the file handle of a file opened with <function>fopen</function>. - </simpara> - </listitem> - </itemizedlist> - - <simpara> - There were some more changes with the release 2.01 of pdflib which - should be covered by PHP. Some functions are not required anymore - (e.g. <function>pdf_put_image</function>). You will get a warning so - don't be shocked.</simpara> - - <simpara> - The pdf module introduces two new types of variables (if pdflib 2.x - is used it is only one new type). They are called - <parameter>pdfdoc</parameter> and <parameter>pdfinfo</parameter> - (<parameter>pdfinfo</parameter> is not existent if pdflib 2.x is used. - <parameter>pdfdoc</parameter> is a pointer to a pdf document and - almost all functions need it as its first parameter. - <parameter>pdfinfo</parameter> contains meta data about the PDF - document. It has to be set before <function>pdf_open</function> is - called.</simpara> - - <note><simpara>The following is only &true; for pdflib 0.6. Read the pdflib - manual for newer version</simpara></note> - <simpara> - In order to output text into a PDF document you will need to provide - the afm file for each font. Afm files contain font metrics for a - Postscript font. By default these afm files are searched - for in a directory named 'fonts' relative to the directory where the - PHP script is located. (Again, this was &true; for pdflib 0.6, newer - versions do not not neccessarily need the afm files.)</simpara> + </note> + </section> - <simpara> - Most of the functions are fairly easy to use. The most difficult part - is probably to create a very simple pdf document at all. The following - example should help to get started. It uses the PHP functions for - pdflib 0.6. It creates the file test.pdf - with one page. The page contains the text "Times-Roman" in an - outlined 30pt font. The text is also underlined.</simpara> + <section id="pdf.requirements"> + &reftitle.required; + <para> + PDFlib está disponible para descargar en + <ulink url="&url.pdf;">&url.pdf;</ulink>, pero requiere la + compra de una licencia para uso comercial. Se requieren + las librerías <ulink url="&url.jpeg;">JPEG</ulink> y <ulink + url="&url.tiff;">TIFF</ulink> para compilar esta extensión. + </para> + + <section id="pdf.oldlibs.hints"> + <title>Compatibilidad con versiones antiguas de PDFlib</title> + <simpara> + Cualquier versión de PHP después del 9 de Marzo del 2000 no + soporta versiones de PDFlib anteriores a la 3.0. + </simpara> + <simpara> + PDFlib 3.0 o superior es compatible desde PHP 3.0.19 en adelante. + </simpara> + </section> + </section> + + &reference.pdf.configure; + + <section id="pdf.configuration"> + &reftitle.runtime; + &no.config; + </section> + + + <section id="pdf.oldlibs.confusion"> + <title>Confusiones con antiguas versiones de PDFlib</title> + <simpara> + Desde PHP 4.0.5, la extensión PHP para PDFlib es oficialmente + soportada por PDFlib GmbH. Esto significa que todas las funciones + descritas en el manual de PDFlib (V3.00 o superior) son + soportadas por PHP 4 con el mismo funcionamiento y parámetros. + Sólo los valores devueltos pueden variar en el manual + PDFlib, ya que PHP adoptó la convención de devolver &false;. + Por razones de compatibilidad, PDFlib aún soporta las antiguas + funciones, pero deberían reemplazarlas en sus nuevas versiones. + PDFlib GmbH no dará soporte a cualquier problema causado + por el uso de estas funciones obsoletas. + </simpara> + <para> + <table> + <title>Funciones obsoletas y sus reemplazos.</title> + <tgroup cols="2"> + <thead> + <row> + <entry>Antigua función</entry> + <entry>Reemplazo</entry> + </row> + </thead> + <tbody> + <row> + <entry><function>pdf_put_image</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_execute_image</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_get_annotation</function></entry> + <entry><function>pdf_get_bookmark</function> + utilizando los mismos parámetros.</entry> + </row> + <row> + <entry><function>pdf_get_font</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"font"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_fontsize</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"fontsize"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_fontname</function></entry> + <entry><function>pdf_get_parameter</function> pasando + <literal>"fontname"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_creator</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Creator"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_title</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Title"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_subject</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Subject"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_author</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Author"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_keywords</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Keywords"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_leading</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"leading"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_rendering</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"textrendering"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_rise</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"textrise"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_horiz_scaling</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"horizscaling"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_matrix</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_set_char_spacing</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"charspacing"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_word_spacing</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"wordspacing"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_transition</function></entry> + <entry><function>pdf_set_parameter</function> pasando + <literal>"transition"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open</function></entry> + <entry><function>pdf_new</function> más la subsecuente llamada de + <function>pdf_open_file</function></entry> + </row> + <row> + <entry><function>pdf_set_font</function></entry> + <entry><function>pdf_findfont</function> más la subsecuente llamada de + <function>pdf_setfont</function></entry> + </row> + <row> + <entry><function>pdf_set_duration</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"duration"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_gif</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"gif"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_jpeg</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"jpeg"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_tiff</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"tiff"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_png</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"png"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_image_width</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"imagewidth"</literal> como segundo parámetro y la + imágen como tercer parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_image_height</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"imageheight"</literal> como segundo parámetro y la + imágen como tercer parámetro.</entry> + </row> + </tbody> + </tgroup> + </table> + </para> + </section> + + <section id="pdf.examples"> + &reftitle.examples; + <simpara> + La mayoría de las funciones son bastante fáciles de utilizar. + La parte más difícil probablemente es la creación de un primer + documento PDF. El siguiente ejemplo debería ayudar para + comenzar. El ejemplo crea el fichero <filename>test.pdf</filename> + en una página. La página contiene el texto "Times Roman outlined" + en un contorno, con fuente de 30pt. + El texto también está subrayado. + </simpara> + <para> <example> - <title>Creating a PDF document with pdflib 0.6</title> - <programlisting> -<?php -$fp = fopen("test.pdf", "w"); -$info = PDF_get_info(); -pdf_set_info_author($info, "Uwe Steinmann"); -PDF_set_info_title($info, "Test for PHP wrapper of PDFlib 0.6"); -PDF_set_info_author($info, "Name of Author"); -pdf_set_info_creator($info, "See Author"); -pdf_set_info_subject($info, "Testing"); -$pdf = PDF_open($fp, $info); -PDF_begin_page($pdf, 595, 842); -PDF_add_outline($pdf, "Page 1"); -pdf_set_font($pdf, "Times-Roman", 30, 4); -pdf_set_text_rendering($pdf, 1); -PDF_show_xy($pdf, "Times Roman outlined", 50, 750); + <title>Creando un documento PDF con PDFlib</title> + <programlisting role="php"> +<![CDATA[ +<?php +$pdf = pdf_new(); +pdf_open_file($pdf, "test.pdf"); +pdf_set_info($pdf, "Author", "Javier Tacon"); +pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0"); +pdf_set_info($pdf, "Creator", "See Author"); +pdf_set_info($pdf, "Subject", "Testing"); +pdf_begin_page($pdf, 595, 842); +pdf_add_outline($pdf, "Page 1"); +$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1); +pdf_setfont($pdf, $font, 10); +pdf_set_value($pdf, "textrendering", 1); +pdf_show_xy($pdf, "Times Roman outlined", 50, 750); pdf_moveto($pdf, 50, 740); pdf_lineto($pdf, 330, 740); pdf_stroke($pdf); -PDF_end_page($pdf); -PDF_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3>finished</A>"; +pdf_end_page($pdf); +pdf_close($pdf); +pdf_delete($pdf); +echo "<A HREF=getpdf.php>finished</A>"; ?> - </programlisting> - </example> - - <para> +]]> + </programlisting> + </example> - The PHP script getpdf.php3 just outputs the pdf document. + El script <filename>getpdf.php</filename> simplemente devuelve el + documento pdf. - <informalexample> - <programlisting> -<?php -$fp = fopen("test.pdf", "r"); + <example> + <title>Mostrando un documento PDF precalculado</title> + <programlisting role="php"> +<![CDATA[ +<?php +$len = filesize($filename); header("Content-type: application/pdf"); -fpassthru($fp); -fclose($fp); +header("Content-Length: $len"); +header("Content-Disposition: inline; filename=foo.pdf"); +readfile($filename); ?> - </programlisting> - </informalexample> +]]> + </programlisting> + </example> + </para> + <para> + La distrubución PDFlib contiene un ejemplo + más complejo para crear un reloj analógico en + una página. Aquí se utiliza el método de + creación en memoria de PDFlib para no tener que crear + un fichero temporal. El ejemplo se ha convertido a PHP + desde uno de PDFlib (El mismo ejemplo está + disponible en la documentación <link + linkend="ref.cpdf">ClibPDF</link>.) + </para> + <para> + <example> + <title>Ejemplo pdfclock de la distribución PDFlib</title> + <programlisting role="php"> +<![CDATA[ +<?php +$radius = 200; +$margin = 20; +$pagecount = 10; - Doing the same with pdflib 2.x looks like the following: +$pdf = pdf_new(); - <example> - <title>Creating a PDF document with pdflib 2.x</title> - <programlisting> -<?php -$fp = fopen("test.pdf", "w"); -$pdf = PDF_open($fp); -pdf_set_info_author($pdf, "Uwe Steinmann"); -PDF_set_info_title($pdf, "Test for PHP wrapper of PDFlib 2.0"); -PDF_set_info_author($pdf, "Name of Author"); -pdf_set_info_creator($pdf, "See Author"); -pdf_set_info_subject($pdf, "Testing"); -PDF_begin_page($pdf, 595, 842); -PDF_add_outline($pdf, "Page 1"); -pdf_set_font($pdf, "Times-Roman", 30, 4); -pdf_set_text_rendering($pdf, 1); -PDF_show_xy($pdf, "Times Roman outlined", 50, 750); -pdf_moveto($pdf, 50, 740); -pdf_lineto($pdf, 330, 740); -pdf_stroke($pdf); -PDF_end_page($pdf); -PDF_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3>finished</A>"; -?> - </programlisting> - <para> - The PHP script getpdf.php3 is the same as above.</para> - </example> +if (!pdf_open_file($pdf, "")) { + echo error; + exit; +}; - The pdflib distribution contains a more complex example which - creates a serious of pages with an analog clock. This example - converted into PHP using pdflib 2.x looks as the following (you - can see the same example in the documentation for the - <link linkend="ref.cpdf">clibpdf module)</link>: - - <example> - <title>pdfclock example from pdflib 2.x distribution</title> - <programlisting> -<?php -$pdffilename = "clock.pdf"; -$radius = 200; -$margin = 20; -$pagecount = 40; +pdf_set_parameter($pdf, "warning", "true"); -$fp = fopen($pdffilename, "w"); -$pdf = pdf_open($fp); -pdf_set_info_creator($pdf, "pdf_clock.php3"); -pdf_set_info_author($pdf, "Uwe Steinmann"); -pdf_set_info_title($pdf, "Analog Clock"); +pdf_set_info($pdf, "Creator", "pdf_clock.php"); +pdf_set_info($pdf, "Author", "Uwe Steinmann"); +pdf_set_info($pdf, "Title", "Analog Clock"); -while($pagecount-- > 0) { +while ($pagecount-- > 0) { pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin)); - pdf_set_transition($pdf, 4); /* wipe */ - pdf_set_duration($pdf, 0.5); + pdf_set_parameter($pdf, "transition", "wipe"); + pdf_set_value($pdf, "duration", 0.5); pdf_translate($pdf, $radius + $margin, $radius + $margin); pdf_save($pdf); @@ -237,7 +356,7 @@ /* minute strokes */ pdf_setlinewidth($pdf, 2.0); - for ($alpha = 0; $alpha < 360; $alpha += 6) { + for ($alpha = 0; $alpha < 360; $alpha += 6) { pdf_rotate($pdf, 6.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin/3, 0.0); @@ -249,7 +368,7 @@ /* 5 minute strokes */ pdf_setlinewidth($pdf, 3.0); - for ($alpha = 0; $alpha < 360; $alpha += 30) { + for ($alpha = 0; $alpha < 360; $alpha += 30) { pdf_rotate($pdf, 30.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin, 0.0); @@ -295,25 +414,44 @@ pdf_restore($pdf); pdf_end_page($pdf); + + # to see some difference + sleep(1); } -$pdf = pdf_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3?filename=".$pdffilename.">finished</A>"; -?> - </programlisting> - <para> - The PHP script getpdf.php3 just outputs the pdf document. - <programlisting> -<?php -$fp = fopen($filename, "r"); +pdf_close($pdf); + +$buf = pdf_get_buffer($pdf); +$len = strlen($buf); + header("Content-type: application/pdf"); -fpassthru($fp); -fclose($fp); +header("Content-Length: $len"); +header("Content-Disposition: inline; filename=foo.pdf"); +echo $buf; + +pdf_delete($pdf); ?> - </programlisting></para> - </example></para> - </partintro> +]]> + </programlisting> + </example> + </para> + </section> + + <section id="pdf.seealso"> + &reftitle.seealso; + <note> + <para> + Una alternativa de módulo PHP para la creación + de documentos PDF basados en + <ulink url="&url.cpdf;">FastIO's</ulink> ClibPDF está + disponible. Mirar la sección <link linkend="ref.cpdf">ClibPDF</link> + para más detalles. Tener en cuenta que <link + linkend="ref.cpdf">ClibPDF</link> tiene alguna diferencia con PDFlib. + </para> + </note> + </section> + + </partintro> &reference.pdf.functions; @@ -334,5 +472,8 @@ sgml-local-catalogs:nil sgml-local-ecat-files:nil End: +vim600: syn=xml fen fdm=syntax fdl=2 si +vim: et tw=78 syn=sgml +vi: ts=1 sw=1 -->
Index: phpdoc-es/reference/pdf/reference.xml diff -u phpdoc-es/reference/pdf/reference.xml:1.2 phpdoc-es/reference/pdf/reference.xml:1.3 --- phpdoc-es/reference/pdf/reference.xml:1.2 Mon Apr 15 20:33:22 2002 +++ phpdoc-es/reference/pdf/reference.xml Sat Jan 17 12:06:16 2004 @@ -1,235 +1,354 @@ <?xml version="1.0" encoding="iso-8859-1"?> +<!-- $Revision: 1.3 $ --> <reference id="ref.pdf"> - <title>PDF functions</title> + <title>Funciones PDF</title> <titleabbrev>PDF</titleabbrev> <partintro> - - <simpara> - You can use the PDF functions in PHP to create PDF files if you - have the PDF library by Thomas Merz (available at - <ulink url="&url.pdf;">&url.pdf;</ulink>; - you will also need <ulink url="&url.jpeg;">the JPEG library</ulink> - and <ulink url="&url.tiff;">the TIFF library</ulink> to - compile this. These two libs also quite often make problems when - configuring php. Follow the messages of configure to fix possible - problems. If you use pdflib 2.01 check how the lib was installed. - There should be file or link libpdf.so. Version 2.01 just creates - a lib with the name libpdf2.01.so which cannot be found when linking - the test programm in configure. You will have to create a symbolic - link from libpdf.so to libpdf2.01.so.). - </simpara> - <simpara> - Version 2.20 of pdflib has introduced more changes to its API and - support for chinese and japanese fonts. This unfortunately causes - some changes of the pdf module of php4 (not php3). If you use pdflib 2.20 - handle the in memory generation of PDF documents with care. Until - pdflib 3.0 is released it might be unstable. The encoding parameter - of <function>pdf_set_font</function> has changed to a string. This - means that instead of e.g. 4 you have to use 'winansi'. - </simpara> - <simpara> - If you use pdflib 2.30 the <function>pdf_set_text_matrix</function> - will have gone. It is not supported any more. In general it is a good - advise to consult the release notes of the used version of pdflib - for possible changes. - </simpara> - <simpara> - Since version 3.0 of pdflib you should configure pdflib with the option - <literal>--enable-shared-pdflib</literal>. - </simpara> - <simpara> - Any version of PHP4 after March, 9th 2000 do not support versions - of pdflib older than 3.0. PHP3 on the other hand should not be used - with version newer than 2.01. - </simpara> - <simpara> - Please consult the excellent documentation for - pdflib shipped with the source distribution of pdflib. - It provides a very good overview of what pdflib capable of doing. - Most of the functions in pdflib - and the PHP module have the same name. The parameters are also - identical. You should also understand some of the concepts of PDF - or Postscript to efficiently use this module. - All lengths and coordinates are measured in Postscript points. - There are generally 72 PostScript points to an inch, but this - depends on the output resolution. - </simpara> - <simpara> - There is another PHP module for pdf document creation based on - <ulink url="&url.cpdf;">FastIO's</ulink>. - ClibPDF. It has a slightly different API. Check the - <link linkend="ref.cpdf">ClibPDF functions</link> section for - details. - </simpara> - <simpara> - Currently all versions of pdflib are supported. It - is recommended that you use the newest version since it has more - features and fixes some problems which required a patch for the old - version. Unfortunately, the changes of the pdflib API in 2.x - compared to 0.6 have - been so severe that even some PHP functions had to be altered. Here - is a list of changes: - </simpara> - <itemizedlist> - <listitem> + <section id="pdf.intro"> + &reftitle.intro; + <simpara> + Las funciones PDF en PHP pueden crear ficheros PDF utilizando + la librería PDFlib creada por + <ulink url="&url.pdflib.merz;">Thomas Merz</ulink>. + </simpara> + <simpara> + La documentación en esta sección solamente es una + descripción de las funciones de la librería PDFlib + y no debería considerarse una referencia exhaustiva. + Se ha de consultar la documentación incluida en el + código fuente de la distribución de PDFlib para + una completa y detallada explicación de cada + función. Proporciona muy buena descripción + de las capacidades de PDFlib y contiene actualizada la + documentación de todas las funciones. + </simpara> + <simpara> + Todas las funciones de PDFlib y del módulo PHP tienen + nombres iguales para las funciones y parámetros. Se + necesitará entender algunos de los conceptos + básicos de PDF y PostScript para un eficiente uso + de esta extensión. Todas las longitudes y coordenadas + se mesuran en puntos PostScript. Generalmente hay 72 puntos + PostScript por pulgada, pero esto depende de la + resolución de salida. Se puede consultar la + documentación incluida en la distribución de + PDFlib para una detallada explicación del sistema + de coordenadas utilizado. + </simpara> + <simpara> + Hay que tener en cuenta que la mayoría de las + funciones PDF requieren un primer parámetro + <parameter>pdfdoc</parameter>. En los siguientes + <link linkend="pdf.examples">ejemplos</link> hay más + información. + </simpara> + <note> <simpara> - The Info structure does not exist anymore. Therefore the function - <function>pdf_get_info</function> is obsolete and the functions - <function>pdf_set_info_creator</function>, - <function>pdf_set_info_title</function>, - <function>pdf_set_info_author</function>, - <function>pdf_set_info_subject</function> and - <function>pdf_set_info_keywords</function> do not take the - info structure as the first parameter but the pdf document. This - also means that the pdf document must be opened before these functions - can be called. The above functions can and should also be replaced by - <function>pdf_set_info</function> + Si se está interesado en alternativas de generadores gratis de PDF que + no utilizen liberías externas PDF, mirar + <link linkend="faq.using.freepdf"> este FAQ relacionado</link>. </simpara> - </listitem> - <listitem> - <simpara> - The way a new document is opened has changed. The function - <function>pdf_open</function> takes only one parameter which is - the file handle of a file opened with <function>fopen</function>. - </simpara> - </listitem> - </itemizedlist> - - <simpara> - There were some more changes with the release 2.01 of pdflib which - should be covered by PHP. Some functions are not required anymore - (e.g. <function>pdf_put_image</function>). You will get a warning so - don't be shocked.</simpara> - - <simpara> - The pdf module introduces two new types of variables (if pdflib 2.x - is used it is only one new type). They are called - <parameter>pdfdoc</parameter> and <parameter>pdfinfo</parameter> - (<parameter>pdfinfo</parameter> is not existent if pdflib 2.x is used. - <parameter>pdfdoc</parameter> is a pointer to a pdf document and - almost all functions need it as its first parameter. - <parameter>pdfinfo</parameter> contains meta data about the PDF - document. It has to be set before <function>pdf_open</function> is - called.</simpara> - - <note><simpara>The following is only &true; for pdflib 0.6. Read the pdflib - manual for newer version</simpara></note> - <simpara> - In order to output text into a PDF document you will need to provide - the afm file for each font. Afm files contain font metrics for a - Postscript font. By default these afm files are searched - for in a directory named 'fonts' relative to the directory where the - PHP script is located. (Again, this was &true; for pdflib 0.6, newer - versions do not not neccessarily need the afm files.)</simpara> + </note> + </section> - <simpara> - Most of the functions are fairly easy to use. The most difficult part - is probably to create a very simple pdf document at all. The following - example should help to get started. It uses the PHP functions for - pdflib 0.6. It creates the file test.pdf - with one page. The page contains the text "Times-Roman" in an - outlined 30pt font. The text is also underlined.</simpara> + <section id="pdf.requirements"> + &reftitle.required; + <para> + PDFlib está disponible para descargar en + <ulink url="&url.pdf;">&url.pdf;</ulink>, pero requiere la + compra de una licencia para uso comercial. Se requieren + las librerías <ulink url="&url.jpeg;">JPEG</ulink> y <ulink + url="&url.tiff;">TIFF</ulink> para compilar esta extensión. + </para> + + <section id="pdf.oldlibs.hints"> + <title>Compatibilidad con versiones antiguas de PDFlib</title> + <simpara> + Cualquier versión de PHP después del 9 de Marzo del 2000 no + soporta versiones de PDFlib anteriores a la 3.0. + </simpara> + <simpara> + PDFlib 3.0 o superior es compatible desde PHP 3.0.19 en adelante. + </simpara> + </section> + </section> + + &reference.pdf.configure; + + <section id="pdf.configuration"> + &reftitle.runtime; + &no.config; + </section> + + + <section id="pdf.oldlibs.confusion"> + <title>Confusiones con antiguas versiones de PDFlib</title> + <simpara> + Desde PHP 4.0.5, la extensión PHP para PDFlib es oficialmente + soportada por PDFlib GmbH. Esto significa que todas las funciones + descritas en el manual de PDFlib (V3.00 o superior) son + soportadas por PHP 4 con el mismo funcionamiento y parámetros. + Sólo los valores devueltos pueden variar en el manual + PDFlib, ya que PHP adoptó la convención de devolver &false;. + Por razones de compatibilidad, PDFlib aún soporta las antiguas + funciones, pero deberían reemplazarlas en sus nuevas versiones. + PDFlib GmbH no dará soporte a cualquier problema causado + por el uso de estas funciones obsoletas. + </simpara> + <para> + <table> + <title>Funciones obsoletas y sus reemplazos.</title> + <tgroup cols="2"> + <thead> + <row> + <entry>Antigua función</entry> + <entry>Reemplazo</entry> + </row> + </thead> + <tbody> + <row> + <entry><function>pdf_put_image</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_execute_image</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_get_annotation</function></entry> + <entry><function>pdf_get_bookmark</function> + utilizando los mismos parámetros.</entry> + </row> + <row> + <entry><function>pdf_get_font</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"font"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_fontsize</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"fontsize"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_fontname</function></entry> + <entry><function>pdf_get_parameter</function> pasando + <literal>"fontname"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_creator</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Creator"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_title</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Title"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_subject</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Subject"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_author</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Author"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_info_keywords</function></entry> + <entry><function>pdf_set_info</function> pasando + <literal>"Keywords"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_leading</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"leading"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_rendering</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"textrendering"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_rise</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"textrise"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_horiz_scaling</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"horizscaling"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_text_matrix</function></entry> + <entry>Ya no se necesita.</entry> + </row> + <row> + <entry><function>pdf_set_char_spacing</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"charspacing"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_word_spacing</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"wordspacing"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_set_transition</function></entry> + <entry><function>pdf_set_parameter</function> pasando + <literal>"transition"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open</function></entry> + <entry><function>pdf_new</function> más la subsecuente llamada de + <function>pdf_open_file</function></entry> + </row> + <row> + <entry><function>pdf_set_font</function></entry> + <entry><function>pdf_findfont</function> más la subsecuente llamada de + <function>pdf_setfont</function></entry> + </row> + <row> + <entry><function>pdf_set_duration</function></entry> + <entry><function>pdf_set_value</function> pasando + <literal>"duration"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_gif</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"gif"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_jpeg</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"jpeg"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_tiff</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"tiff"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_open_png</function></entry> + <entry><function>pdf_open_image_file</function> pasando + <literal>"png"</literal> como segundo parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_image_width</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"imagewidth"</literal> como segundo parámetro y la + imágen como tercer parámetro.</entry> + </row> + <row> + <entry><function>pdf_get_image_height</function></entry> + <entry><function>pdf_get_value</function> pasando + <literal>"imageheight"</literal> como segundo parámetro y la + imágen como tercer parámetro.</entry> + </row> + </tbody> + </tgroup> + </table> + </para> + </section> + + <section id="pdf.examples"> + &reftitle.examples; + <simpara> + La mayoría de las funciones son bastante fáciles de utilizar. + La parte más difícil probablemente es la creación de un primer + documento PDF. El siguiente ejemplo debería ayudar para + comenzar. El ejemplo crea el fichero <filename>test.pdf</filename> + en una página. La página contiene el texto "Times Roman outlined" + en un contorno, con fuente de 30pt. + El texto también está subrayado. + </simpara> + <para> <example> - <title>Creating a PDF document with pdflib 0.6</title> - <programlisting> -<?php -$fp = fopen("test.pdf", "w"); -$info = PDF_get_info(); -pdf_set_info_author($info, "Uwe Steinmann"); -PDF_set_info_title($info, "Test for PHP wrapper of PDFlib 0.6"); -PDF_set_info_author($info, "Name of Author"); -pdf_set_info_creator($info, "See Author"); -pdf_set_info_subject($info, "Testing"); -$pdf = PDF_open($fp, $info); -PDF_begin_page($pdf, 595, 842); -PDF_add_outline($pdf, "Page 1"); -pdf_set_font($pdf, "Times-Roman", 30, 4); -pdf_set_text_rendering($pdf, 1); -PDF_show_xy($pdf, "Times Roman outlined", 50, 750); + <title>Creando un documento PDF con PDFlib</title> + <programlisting role="php"> +<![CDATA[ +<?php +$pdf = pdf_new(); +pdf_open_file($pdf, "test.pdf"); +pdf_set_info($pdf, "Author", "Javier Tacon"); +pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0"); +pdf_set_info($pdf, "Creator", "See Author"); +pdf_set_info($pdf, "Subject", "Testing"); +pdf_begin_page($pdf, 595, 842); +pdf_add_outline($pdf, "Page 1"); +$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1); +pdf_setfont($pdf, $font, 10); +pdf_set_value($pdf, "textrendering", 1); +pdf_show_xy($pdf, "Times Roman outlined", 50, 750); pdf_moveto($pdf, 50, 740); pdf_lineto($pdf, 330, 740); pdf_stroke($pdf); -PDF_end_page($pdf); -PDF_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3>finished</A>"; +pdf_end_page($pdf); +pdf_close($pdf); +pdf_delete($pdf); +echo "<A HREF=getpdf.php>finished</A>"; ?> - </programlisting> - </example> - - <para> +]]> + </programlisting> + </example> - The PHP script getpdf.php3 just outputs the pdf document. + El script <filename>getpdf.php</filename> simplemente devuelve el + documento pdf. - <informalexample> - <programlisting> -<?php -$fp = fopen("test.pdf", "r"); + <example> + <title>Mostrando un documento PDF precalculado</title> + <programlisting role="php"> +<![CDATA[ +<?php +$len = filesize($filename); header("Content-type: application/pdf"); -fpassthru($fp); -fclose($fp); +header("Content-Length: $len"); +header("Content-Disposition: inline; filename=foo.pdf"); +readfile($filename); ?> - </programlisting> - </informalexample> +]]> + </programlisting> + </example> + </para> + <para> + La distrubución PDFlib contiene un ejemplo + más complejo para crear un reloj analógico en + una página. Aquí se utiliza el método de + creación en memoria de PDFlib para no tener que crear + un fichero temporal. El ejemplo se ha convertido a PHP + desde uno de PDFlib (El mismo ejemplo está + disponible en la documentación <link + linkend="ref.cpdf">ClibPDF</link>.) + </para> + <para> + <example> + <title>Ejemplo pdfclock de la distribución PDFlib</title> + <programlisting role="php"> +<![CDATA[ +<?php +$radius = 200; +$margin = 20; +$pagecount = 10; - Doing the same with pdflib 2.x looks like the following: +$pdf = pdf_new(); - <example> - <title>Creating a PDF document with pdflib 2.x</title> - <programlisting> -<?php -$fp = fopen("test.pdf", "w"); -$pdf = PDF_open($fp); -pdf_set_info_author($pdf, "Uwe Steinmann"); -PDF_set_info_title($pdf, "Test for PHP wrapper of PDFlib 2.0"); -PDF_set_info_author($pdf, "Name of Author"); -pdf_set_info_creator($pdf, "See Author"); -pdf_set_info_subject($pdf, "Testing"); -PDF_begin_page($pdf, 595, 842); -PDF_add_outline($pdf, "Page 1"); -pdf_set_font($pdf, "Times-Roman", 30, 4); -pdf_set_text_rendering($pdf, 1); -PDF_show_xy($pdf, "Times Roman outlined", 50, 750); -pdf_moveto($pdf, 50, 740); -pdf_lineto($pdf, 330, 740); -pdf_stroke($pdf); -PDF_end_page($pdf); -PDF_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3>finished</A>"; -?> - </programlisting> - <para> - The PHP script getpdf.php3 is the same as above.</para> - </example> +if (!pdf_open_file($pdf, "")) { + echo error; + exit; +}; - The pdflib distribution contains a more complex example which - creates a serious of pages with an analog clock. This example - converted into PHP using pdflib 2.x looks as the following (you - can see the same example in the documentation for the - <link linkend="ref.cpdf">clibpdf module)</link>: - - <example> - <title>pdfclock example from pdflib 2.x distribution</title> - <programlisting> -<?php -$pdffilename = "clock.pdf"; -$radius = 200; -$margin = 20; -$pagecount = 40; +pdf_set_parameter($pdf, "warning", "true"); -$fp = fopen($pdffilename, "w"); -$pdf = pdf_open($fp); -pdf_set_info_creator($pdf, "pdf_clock.php3"); -pdf_set_info_author($pdf, "Uwe Steinmann"); -pdf_set_info_title($pdf, "Analog Clock"); +pdf_set_info($pdf, "Creator", "pdf_clock.php"); +pdf_set_info($pdf, "Author", "Uwe Steinmann"); +pdf_set_info($pdf, "Title", "Analog Clock"); -while($pagecount-- > 0) { +while ($pagecount-- > 0) { pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin)); - pdf_set_transition($pdf, 4); /* wipe */ - pdf_set_duration($pdf, 0.5); + pdf_set_parameter($pdf, "transition", "wipe"); + pdf_set_value($pdf, "duration", 0.5); pdf_translate($pdf, $radius + $margin, $radius + $margin); pdf_save($pdf); @@ -237,7 +356,7 @@ /* minute strokes */ pdf_setlinewidth($pdf, 2.0); - for ($alpha = 0; $alpha < 360; $alpha += 6) { + for ($alpha = 0; $alpha < 360; $alpha += 6) { pdf_rotate($pdf, 6.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin/3, 0.0); @@ -249,7 +368,7 @@ /* 5 minute strokes */ pdf_setlinewidth($pdf, 3.0); - for ($alpha = 0; $alpha < 360; $alpha += 30) { + for ($alpha = 0; $alpha < 360; $alpha += 30) { pdf_rotate($pdf, 30.0); pdf_moveto($pdf, $radius, 0.0); pdf_lineto($pdf, $radius-$margin, 0.0); @@ -295,25 +414,44 @@ pdf_restore($pdf); pdf_end_page($pdf); + + # to see some difference + sleep(1); } -$pdf = pdf_close($pdf); -fclose($fp); -echo "<A HREF=getpdf.php3?filename=".$pdffilename.">finished</A>"; -?> - </programlisting> - <para> - The PHP script getpdf.php3 just outputs the pdf document. - <programlisting> -<?php -$fp = fopen($filename, "r"); +pdf_close($pdf); + +$buf = pdf_get_buffer($pdf); +$len = strlen($buf); + header("Content-type: application/pdf"); -fpassthru($fp); -fclose($fp); +header("Content-Length: $len"); +header("Content-Disposition: inline; filename=foo.pdf"); +echo $buf; + +pdf_delete($pdf); ?> - </programlisting></para> - </example></para> - </partintro> +]]> + </programlisting> + </example> + </para> + </section> + + <section id="pdf.seealso"> + &reftitle.seealso; + <note> + <para> + Una alternativa de módulo PHP para la creación + de documentos PDF basados en + <ulink url="&url.cpdf;">FastIO's</ulink> ClibPDF está + disponible. Mirar la sección <link linkend="ref.cpdf">ClibPDF</link> + para más detalles. Tener en cuenta que <link + linkend="ref.cpdf">ClibPDF</link> tiene alguna diferencia con PDFlib. + </para> + </note> + </section> + + </partintro> &reference.pdf.functions; @@ -334,5 +472,8 @@ sgml-local-catalogs:nil sgml-local-ecat-files:nil End: +vim600: syn=xml fen fdm=syntax fdl=2 si +vim: et tw=78 syn=sgml +vi: ts=1 sw=1 -->