A simple example of ASP. NET in itextsharp (converted based on the JSP version of itext)

Source: Internet
Author: User
Using System;
Using System. collections;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. Web;
Using System. Web. sessionstate;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. htmlcontrols;
Using Itextsharp. text;
Using Itextsharp.text.pdf;
Using System. IO;

Namespace Itext
{
/**/ /// <Summary>
///Abstract description of chap0105.
/// </Summary>
Public   Class Chap0105: system. Web. UI. Page
{
Private   Void Page_load ( Object Sender, system. eventargs E)
{
// Step 1
// Need to write to memory first due to IE wanting
// To know the length of the PDF beforehand
Memorystream m =   New Memorystream ();
Document document =   New Document ();
Try  
{
// Step 2: we set the contenttype and create an instance of the writer
Response. contenttype =   " Application/PDF " ;
Using writer. getinstance (document, M );

// Step 3
Document. open ();

// Step 4
Document. Add ( New Paragraph (datetime. Now. tostring ()));
}  
Catch (Effecentexception ex)
{
Console. Error. writeline (ex. stacktrace );
Console. Error. writeline (ex. Message );
}
// Step 5: Close document
Document. Close ();

// Step 6: Write PDF bytes to outputstream
Response. outputstream. Write (M. getbuffer (), 0 , M. getbuffer (). Length );
Response. outputstream. Flush ();
Response. outputstream. Close ();
}

Generated by the web Form DesignerCode # Region Code generated by web Form Designer
Override   Protected   Void Oninit (eventargs E)
{< br> //
// codegen: This call is ASP.. NET web form designer.
//
initializecomponent ();
base . oninit (E);
}

/**/ /// <Summary>
///The designer supports the required methods-do not use the code editor to modify
///The content of this method.
/// </Summary>
Private   Void Initializecomponent ()
{
This. Load+ = NewSystem. eventhandler (This. Page_load );
}
# Endregion
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.