I am working with iTextSharp. He used a function to generate a PDF file, and save it, with the following piece of code:
//GENERAR ARCHIVO PDF.
private void To_pdf()
{
Document doc = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = @"C:";
saveFileDialog1.Title = "Guardar Reporte";
saveFileDialog1.DefaultExt = "pdf";
saveFileDialog1.Filter = "pdf Files (*.pdf)|*.pdf| All Files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
string filename = "";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = saveFileDialog1.FileName;
}
if (filename.Trim() != "")
{
FileStream file = new FileStream(filename,
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.ReadWrite);
PdfWriter.GetInstance(doc, file);
doc.Open();
string remito = "ARCHIVO PDF DE PRUEBA";
string envio = "Fecha:" + DateTime.Now.ToString();
//AGERGAR UNA IMÁGEN.
iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance("C:/Users/ABG/Desktop/SistemaNóminaABG/Imágenes/grupoabg.png");
Chunk chunk = new Chunk("Reporte de General bitacora", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD));
doc.Add(new Paragraph(chunk));
doc.Add(new Paragraph("------------------------------------------------------------------------------------------"));
doc.Add(imagen);
doc.Add(new Paragraph(remito));
doc.Add(new Paragraph(envio));
//GenerarDocumento(doc);
doc.AddCreationDate();
doc.Add(new Paragraph("______________________________________________", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD)));
doc.Add(new Paragraph("Firma", FontFactory.GetFont("ARIAL", 20, iTextSharp.text.Font.BOLD)));
doc.Close();
Process.Start(filename);//Esta parte se puede omitir, si solo se desea guardar el archivo, y que este no se ejecute al instante
}
}
And then what I do is show it in a FORM of my program, calling the path of the file.
What I want to know is ..., How do I show the PDF file in the form, without having to save it ?, that is, when it is created directly, it opens.
I thank you.