Itextsharp processes elements in a group or not.

Source: Internet
Author: User

String filename = DateTime. Now. ToString ("yyyyMMddHHmmss"). ToString () + ". pdf ";
Float w = PageSize. A4.Width;
Float h = PageSize. A4.Height;
Rectangle rect = new Rectangle (0, 0, w, h );
Document document = new Document (rect );
Using writer = Using writer. GetInstance (document, new FileStream (Server. MapPath (filename), FileMode. Create ));

Document. Open ();
Required contentbyte content = writer. DirectContent;
Repeated template = content. CreateTemplate (rect. Width, rect. Height );
PdfGState state = null;
Template. SaveState ();

Template. SetColorFill (Color. RED );
Template. SetColorStroke (Color. GREEN );
Template. SetLineWidth (3 );
State = new PdfGState ();
State. FillOpacity = 0.5f;
State. AlphaIsShape = false;
Template. SetGState (state );
Template. Rectangle (100,100,100,100 );
Template. FillStroke ();
Template. RestoreState ();

Template. SaveState ();
Template. SetColorFill (Color. RED );
Template. SetColorStroke (Color. BLUE );
Template. SetLineWidth (3 );
State = new PdfGState ();
State. FillOpacity = 0.5f;
State. AlphaIsShape = false;
Template. SetGState (state );
Template. Rectangle (150,150,100,100 );
Template. FillStroke ();
Template. RestoreState ();

Template. SaveState ();

// Process the elements in the same group and set the transparency of the Group to 0.5. In this way, when the elements in the group overlap, the image that is drawn later overwrites the image that is first drawn, and no transparency should be set, deepen or affect the colors of overlapping elements
State = new PdfGState ();
State. FillOpacity = 0.5f; // sets the transparency to 0.5.
Template. SetGState (state );
Required template _ template = template. CreateTemplate (rect. Width, rect. Height );

// Set transparent to a group
Transfertransparencygroup group = new transfertransparencygroup ();
Group. Isolated = false; // indicates whether the agent is independent.

_ Template. Group = group;
_ Template. SaveState ();
_ Template. SetColorFill (Color. RED );
_ Template. SetColorStroke (Color. GREEN );
_ Template. SetLineWidth (3 );
_ Template. Rectangle (300,100,100,100 );
_ Template. FillStroke ();
_ Template. RestoreState ();

_ Template. SaveState ();
_ Template. SetColorFill (Color. RED );
_ Template. SetColorStroke (Color. BLUE );
_ Template. SetLineWidth (3 );
_ Template. Rectangle (350,150,100,100 );
_ Template. FillStroke ();
_ Template. RestoreState ();

Template. AddTemplate (_ template, 0, 0 );

Template. RestoreState ();
Content. AddTemplate (template, 1, 0, 0,-1, 0, rect. Height );
Document. Close ();

 

This article is from the explorer blog, please be sure to keep this source http://1906754.blog.51cto.com/1896754/1272926

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.