Last active
August 11, 2020 18:11
-
-
Save gutoccs/b72a24380db5eb6c24dbc2dc0ddb8ab7 to your computer and use it in GitHub Desktop.
Crear un archivo PDF en C# con iTextSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
//Clase necesaria para poder utilizar iTextSharp | |
using System.IO; | |
//Clases necesarias de iTextSharp | |
using iTextSharp; | |
using iTextSharp.text.pdf; | |
using iTextSharp.text; | |
namespace Crear_Un_Archivo_PDF | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Creamos un tipo de archivo que solo se cargará en la memoria principal | |
Document documento = new Document(); | |
//Creamos la instancia para generar el archivo PDF | |
//Le pasamos el documento creado arriba y con capacidad para abrir o Crear y de nombre Mi_Primer_PDF | |
PdfWriter.GetInstance(documento, new FileStream("Mi_Primer_PDF.pdf", FileMode.OpenOrCreate)); | |
//Abrimos el documento | |
documento.Open(); | |
//Le agregamos un párrafo | |
documento.Add(new Paragraph("Este es mi primer PDF")); | |
//Le agregamos un segundo párrafo | |
documento.Add(new Paragraph("Segundo párrafo")); | |
//Cerramos el documento | |
documento.Close(); | |
Console.WriteLine("El archivo ha sido creado"); | |
//Para que no se cierre la cónsola, hasta que presionemos alguna tecla | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
puedo generar el pdf en una ruta especifica.?