I wrote series of articles about create PDF document in ASP.NET with C# using iTextSharp. In this article I’m going to explain how to align images in PDF document.  Other articles related to iTextSharp

How to create PDF document using iTextSharp

How to change PDF document page size using iTextSharp 

    How to use Images in PDF document using iTextSharp

    How to use Tables in PDF document using iTextSharp

  How to export GridView records to PDF document using iTextSharp 

          Here I’m going to explain how to use image in PDF document using iTextSharp. First we have to download iTextSharp.dll class library and include to our project.

          You can download iTextSharp.dll class library here

http://sourceforge.net/projects/itextsharp/

          Then open your project and include that iTextSharp.dll class library.

iTextSharp image align

          Browse the iTextSharp.dll file which is downloaded now and click ok.

iTextSharp image align

          iTextSharp allows you to use images in PDF document and it’ll support many image formats like .jpg, .jpeg, .png, .bmp, .tif and .wmf. 

          Image.GetInstance method is used to create images in PDF document. 

iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(imagepath +

                                                                                      "/image.jpg");

iTextSharp provides way for align images in PDF document. There are some properties used to do that.

Sample code:

gif.ScaleToFit(250f, 250f);

gif.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT;

gif.IndentationLeft = 9f;

gif.SpacingAfter = 9f;

gif.BorderWidthTop = 36f;

 

 You can create your designer page now

Designer source code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Button ID="btnShow" runat="server" Text="Show PDF"

                                    OnClick="btnShow_OnClick"/>

    </div>

    </form>

</body>

</html>

 

Here you should use following namespaces and create one folder for store PDF documents

using iTextSharp.text;

using iTextSharp.text.pdf;

using System.IO;

 

Code Behind:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using iTextSharp.text;

using iTextSharp.text.pdf;

using System.IO; 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {    

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    //server folder path which is stored your PDF documents

    string path = Server.MapPath("PDF-Files");

    string imagepath = Server.MapPath("Images");

    string filename = path + "/Doc1.pdf";

 

    //Create new PDF document

    Document document = new Document(PageSize.A4, 20f, 20f, 20f, 20f);

    try

    {

        PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create)); 

        //Create object for image

        iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(imagepath + "/image.jpg");

 

        Paragraph paragraph = new Paragraph(@"iTextSharp is a C# port of iText,

        and open source Java library for PDF generation and manipulation. It can

        be used to create PDF documents from scratch, to convert XML to PDF (using

        the extra XFA Worker DLL), to fill out interactive PDF forms, to stamp new

        content on existing PDF documents, to split and merge existing PDF documents,

        and much more.");

        paragraph.Alignment = Element.ALIGN_JUSTIFIED;

 

        //Image alignment

        gif.ScaleToFit(250f, 250f);

        gif.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT;

        gif.IndentationLeft = 9f;

        gif.SpacingAfter = 9f;

        gif.BorderWidthTop = 36f;

 

        document.Open();

        document.Add(gif);

        document.Add(new Paragraph(paragraph));            

    }

    catch (Exception ex)

    {        

    }

    finally

    {

        document.Close();

        ShowPdf(filename);

    }       

    }

    public void ShowPdf(string filename)

    {

        //Clears all content output from Buffer Stream

        Response.ClearContent();

        //Clears all headers from Buffer Stream

        Response.ClearHeaders();

        //Adds an HTTP header to the output stream

        Response.AddHeader("Content-Disposition", "inline;filename=" + filename);

        //Gets or Sets the HTTP MIME type of the output stream

        Response.ContentType = "application/pdf";

        //Writes the content of the specified file directory to an HTTP response output stream as a file block

        Response.WriteFile(filename);

        //sends all currently buffered output to the client

        Response.Flush();

        //Clears all content output from Buffer Stream

        Response.Clear(); 

    }  

}

 

cytotec abortion

abortion pill online buy abortion pills online
medical abortion pill online buy cytotec for 24 week abortion abortion pill


View demo Download
http://www.dotnetfox.com/Document/1026/0Demo1.gif

If you enjoyed this article, get email updates (it's free).


Related Articles
  • How to create PDF document in ASP.NET with C# using iTextSharpIts happy weekend and I’ve decided to write series of articles about iTextSharp. This is one of my favourites, of course. Aside from this blog, there are dozens of great blogs on writing about create PDF document using iTextSharp. I like to read about what works for others — it inspires me to write these series of articles about iTextSharp. iTextSharp is a C# port of iText, and open source Java li...
  • How to change PDF Document page size in ASP.NET with C# usng iTextSharpI wrote series of articles about create PDF document using iTextSharp. In this article I’m going to explain how to set PDF document size. Other articles related to iTextSharp, How to create PDF document using iTextSharp , How to use Images in PDF document using iTextSharp, Image alignment in PDF document using iTextSharp, How to use Tables in PDF document using iTextSharp, How to export GridView ...
  • How to use image in PDF document in ASP.NET with C# using iTextSharpIn this article I’m going to explain how to use image in PDF document. Other articles related to iTextSharp. iTextSharp is a C# port of iText, and open source Java library for PDF generation and manipulation. It can be used to create PDF documents from scratch, to convert XML to PDF (using the extra XFA Worker DLL), to fill out interactive PDF forms, to stamp new content on existing PDF documents...
  • How to align images to PDF document in ASP.NET with C# using iTextSharpIn this article I’m going to explain how to align images in PDF document. Other articles related to iTextSharp. iTextSharp is a C# port of iText, and open source Java library for PDF generation and manipulation. It can be used to create PDF documents from scratch, to convert XML to PDF (using the extra XFA Worker DLL), to fill out interactive PDF forms, to stamp new content on existing PDF docume...
  • How to create Table in PDF document using ASP.NET with C# and iTextSharpI wrote series of articles about create PDF document in ASP.NET with C# using iTextSharp. In this article I’m going to explain how to create Tables in PDF document. Other articles related to iTextSharp
  • How to export GridView data to PDF document in ASP.NET with C# using iTextSharpIn this article I’m going to explain how to export GridView to PDF document. Other articles related to iTextSharp. iTextSharp is a C# port of iText, and open source Java library for PDF generation and manipulation. It can be used to create PDF documents from scratch, to convert XML to PDF (using the extra XFA Worker DLL), to fill out interactive PDF forms, to stamp new content on existing PDF doc...
  • Export Chart control to PDF document in ASP.NET using iTextSharp and C#In this article I’m going to explain how to export ASP.NET chart control to PDF using C#. I have already written an article about bind ASP.NET Chart control from database. You could refer this article by following this below link. Bind ASP.NET chart control from database using C#. If you are not aware to include iTextSharp.dll in ASP.NET project you could read this article How to create PDF docume...
  • Export HTML Table to PDF in ASP.NET In this article I’m going to explain how to export HTML table to PDF in ASP.NET. There are many ways we can export HTML Table to PDF document. Here I’ll explain the easiest way to export HTML Table to PDF. WebClient class provide the feature to download the HTML string from current URL. First we need to make sure that how we can extract HTML Table from entire source code and how we can get conten...

Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox