5/5/11

How to Generate a PDF File Using ASP.Net

ASP.Net is a coding language used specifically to create dynamic web pages. ASP.Net allows coders to manipulate a web page in a variety of ways, including creating PDF (Portable Document Format) files and displaying these files on a user's web browser. ASP.Net itself does not support the generation of PDF files. But it can do so by installing and using a PDF manipulating plug-in freely available on the Internet.
    • 1

      Install a PDF generation plug-in to the current ASP.Net project directory. Extracting the files to the current project directory allows the application to interact with the plug-in correctly.

    • 2

      Type "using iTextSharp.text;" and "using iTextSharp.text.pdf;" into the code page. Ensure the two lines are placed at the top of any current code. These lines of code ready the newly-installed plug-in for use by the rest of the code.

    • 3

      Type "Document document = new Document(PageSize.A4.Rotate());" below the previously entered code. This initiates a PDF file and assigns it to the "document" variable.

    • 4

      Type "PdfWriter.GetInstance(document, new FileStream("myPDF.pdf", FileMode.Create));" after the previously entered text. This line of code causes the application to create the actual PDF file using hard drive space.

    • 5

      Type "document.Close();" after the previously entered code. This line of code ensures the PDF file is ended properly, and prevents many coding errors.

  • No comments: