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 ));
// Sets the transparency blending colorspace to RGB. the default blending colorspace is CMYK and will result in faded colors in the screen and in printing. calling this method will return the RGB colors to what is expected. the RGB blending will be applied to all subsequent pages until other value is set. note that this is a generic solution that may not work in all cases.
// Parameters:
// RgbTransparencyBlending-true to set the transparency blending colorspace to RGB, false to use the default blending colorspace
// Set the color space. The default value is the CMKY color space. If it is set to true, It is the RGB color space.
Writer. RgbTransparencyBlending = true;
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 ();
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/1272930