mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
Ignore entities.*.xml git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@310922 c90b9560-bf6c-de11-be94-00142212c4b1
123 lines
3.5 KiB
XML
123 lines
3.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 96c9d88bad9a7d7d44bfb7f26c226df7ee9ddf26 Maintainer: seros Status: ready -->
|
|
|
|
<chapter xml:id="pdf.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<section xml:id="pdf.examples-basic">
|
|
<title>Basic Usage Examples</title>
|
|
<para>
|
|
La mayoría de las funciones son bastante fáciles de usar. La parte más difícil
|
|
es probablemente la de crear su primer documento PDF. El siguiente
|
|
ejemplo debería ayudarle a empezar. Está desarrolado para PHP 4 y
|
|
crea el archivo <filename>hola.pdf</filename> con una página.
|
|
Define algunos contenidos de campos de información del documento, carga la fuente
|
|
Helvetica-Bold e imprime el texto "¡Hola mundo! (dice PHP)".
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de Hola Mundo con la distribucion PDFlib para PHP 4</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$p = PDF_new();
|
|
|
|
/* abrir un nuevo archivo PDF; insertar un nombre de archivo para crear el PDF en disco */
|
|
if (PDF_begin_document($p, "", "") == 0) {
|
|
die("Error: " . PDF_get_errmsg($p));
|
|
}
|
|
|
|
PDF_set_info($p, "Creator", "hola.php");
|
|
PDF_set_info($p, "Author", "Rainer Schaaf");
|
|
PDF_set_info($p, "Title", "¡Hola mundo (PHP)!");
|
|
|
|
PDF_begin_page_ext($p, 595, 842, "");
|
|
|
|
$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
|
|
|
|
PDF_setfont($p, $font, 24.0);
|
|
PDF_set_text_pos($p, 50, 700);
|
|
PDF_show($p, "¡Hola mundo!");
|
|
PDF_continue_text($p, "(dice PHP)");
|
|
PDF_end_page_ext($p, "");
|
|
|
|
PDF_end_document($p, "");
|
|
|
|
$buf = PDF_get_buffer($p);
|
|
$len = strlen($buf);
|
|
|
|
header("Content-type: application/pdf");
|
|
header("Content-Length: $len");
|
|
header("Content-Disposition: inline; filename=hola.pdf");
|
|
print $buf;
|
|
|
|
PDF_delete($p);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
El siguiente ejemplo viene con la distribución de PDFlib para PHP 5.
|
|
Usa las nuevas características de manejo de excepciones y encapsulación de objetos
|
|
disponibles en PHP 5. Crea el archivo <filename>hola.pdf</filename>
|
|
con una página. Define algunos contenidos de campos de información del documento,
|
|
carga la fuente Helvetica-Bold e imprime el texto "¡Hola mundo! (dice PHP)".
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de Hola Mundo con la distribucion PDFlib para PHP 5</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
try {
|
|
$p = new PDFlib();
|
|
|
|
/* abrir un nuevo archivo PDF; insertar un nombre de archivo para crear el PDF en disco */
|
|
if ($p->begin_document("", "") == 0) {
|
|
die("Error: " . $p->get_errmsg());
|
|
}
|
|
|
|
$p->set_info("Creator", "hola.php");
|
|
$p->set_info("Author", "Rainer Schaaf");
|
|
$p->set_info("Title", "¡Hola mundo (PHP)!");
|
|
|
|
$p->begin_page_ext(595, 842, "");
|
|
|
|
$font = $p->load_font("Helvetica-Bold", "winansi", "");
|
|
|
|
$p->setfont($font, 24.0);
|
|
$p->set_text_pos(50, 700);
|
|
$p->show("¡Hola mundo!");
|
|
$p->continue_text("(dice PHP)");
|
|
$p->end_page_ext("");
|
|
|
|
$p->end_document("");
|
|
|
|
$buf = $p->get_buffer();
|
|
$len = strlen($buf);
|
|
|
|
header("Content-type: application/pdf");
|
|
header("Content-Length: $len");
|
|
header("Content-Disposition: inline; filename=hola.pdf");
|
|
print $buf;
|
|
}
|
|
catch (PDFlibException $e) {
|
|
die("Ocurrió un Excepción PDFlib en el ejemplo hola:\n" .
|
|
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
|
|
$e->get_errmsg() . "\n");
|
|
}
|
|
catch (Exception $e) {
|
|
die($e);
|
|
}
|
|
$p = 0;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</section>
|
|
</chapter>
|