iTextsharp simple Image to PDF c#
Very simple code.
public void ImagetoPDF()
{
string pdfpath = Server.MapPath("PDFs");
string imagepath = Server.MapPath("Images");
Document doc = new Document();
try
{
PdfWriter.GetInstance(doc, new FileStream(pdfpath + "/Images.pdf", FileMode.Create));
doc.Open();
iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(Server.MapPath("") + "/testasp3.gif");
png.ScaleToFit(475f, 1500f);
doc.Add(png);
}
catch (DocumentException dex)
{
Response.Write(dex.Message);
}
catch (IOException ioex)
{
Response.Write(ioex.Message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
doc.Close();
Response.Redirect("PDFs/Images.pdf");
}
}
This entry was posted on Thursday, August 27, 2009 at 3:12 AM. You can follow any responses to this entry through the RSS 2.0. You can