當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfContentByte.SaveState方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.SaveState方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.SaveState方法的具體用法?C# PdfContentByte.SaveState怎麽用?C# PdfContentByte.SaveState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfContentByte的用法示例。


在下文中一共展示了PdfContentByte.SaveState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShowTextAligned

 /** Shows a line of text. Only the first line is written.
  * @param canvas where the text is to be written to
  * @param alignment the alignment. It is not influenced by the run direction
  * @param phrase the <CODE>Phrase</CODE> with the text
  * @param x the x reference position
  * @param y the y reference position
  * @param rotation the rotation to be applied in degrees counterclockwise
  * @param runDirection the run direction
  * @param arabicOptions the options for the arabic shaping
  */    
 public static void ShowTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation, int runDirection, int arabicOptions) {
     if (alignment != Element.ALIGN_LEFT && alignment != Element.ALIGN_CENTER
         && alignment != Element.ALIGN_RIGHT)
         alignment = Element.ALIGN_LEFT;
     canvas.SaveState();
     ColumnText ct = new ColumnText(canvas);
     float lly = -1;
     float ury = 2;
     float llx;
     float urx;
     switch (alignment) {
         case Element.ALIGN_LEFT:
             llx = 0;
             urx = 20000;
             break;
         case Element.ALIGN_RIGHT:
             llx = -20000;
             urx = 0;
             break;
         default:
             llx = -20000;
             urx = 20000;
             break;
     }
     if (rotation == 0) {
         llx += x;
         lly += y;
         urx += x;
         ury += y;
     }
     else {
         double alpha = rotation * Math.PI / 180.0;
         float cos = (float)Math.Cos(alpha);
         float sin = (float)Math.Sin(alpha);
         canvas.ConcatCTM(cos, sin, -sin, cos, x, y);
     }
     ct.SetSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment);
     if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
         if (alignment == Element.ALIGN_LEFT)
             alignment = Element.ALIGN_RIGHT;
         else if (alignment == Element.ALIGN_RIGHT)
             alignment = Element.ALIGN_LEFT;
     }
     ct.Alignment = alignment;
     ct.ArabicOptions = arabicOptions;
     ct.RunDirection = runDirection;
     ct.Go();
     canvas.RestoreState();
 }
開發者ID:medvedttn,項目名稱:itextsharp_mod-src,代碼行數:59,代碼來源:ColumnText.cs

示例2: CreateStarsAndCircles

 // ---------------------------------------------------------------------------
 /**
  * Draws a row of stars and circles.
  * @param canvas the canvas to which the shapes have to be drawn
  * @param x      X coordinate to position the row
  * @param y      Y coordinate to position the row
  * @param radius the radius of the circles
  * @param gutter the space between the shapes
  */
 public static void CreateStarsAndCircles(PdfContentByte canvas,
 float x, float y, float radius, float gutter)
 {
     canvas.SaveState();
       canvas.SetColorStroke(new GrayColor(0.2f));
       canvas.SetColorFill(new GrayColor(0.9f));
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.Fill();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.EoFill();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       canvas.NewPath();
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, false);
       canvas.FillStroke();
       x += 2 * radius + gutter;
       CreateStar(canvas, x, y);
       CreateCircle(canvas, x + radius, y - 70, radius, true);
       CreateCircle(canvas, x + radius, y - 70, radius / 2, true);
       canvas.EoFillStroke();
       canvas.RestoreState();
 }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:41,代碼來源:PathConstructionAndPainting.cs

示例3: Draw

 /**
 * @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
 */
 public override void Draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
     canvas.SaveState();
     canvas.SetLineWidth(lineWidth);
     canvas.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
     canvas.SetLineDash(0, gap, gap / 2);
     DrawLine(canvas, llx, urx, y);
     canvas.RestoreState();
 }
開發者ID:yu0410aries,項目名稱:itextsharp,代碼行數:11,代碼來源:DottedLineSeparator.cs

示例4: DrawRectangles

// ---------------------------------------------------------------------------    
    /**
     * Draws three rectangles
     * @param canvas
     */
    public void DrawRectangles(PdfContentByte canvas) {
      canvas.SaveState();
      canvas.SetGrayFill(0.9f);
      canvas.Rectangle(33, 592, 72, 72);
      canvas.Rectangle(263, 406, 72, 72);
      canvas.Rectangle(491, 168, 72, 72);
      canvas.FillStroke();
      canvas.RestoreState();
    }    
開發者ID:,項目名稱:,代碼行數:14,代碼來源:

示例5: Ellipse

 public void Ellipse(PdfContentByte content, Rectangle rect) {
   content.SaveState();
   content.SetRGBColorFill(0x00, 0x00, 0xFF);
   content.Ellipse(
     rect.Left - 3f, rect.Bottom - 5f,
     rect.Right + 3f, rect.Top + 3f
   );
   content.Fill();
   content.RestoreState();
 }
開發者ID:,項目名稱:,代碼行數:10,代碼來源:

示例6: DrawTimeTable

        // ---------------------------------------------------------------------------    
        /**
         * Draws the time table for a day at the film festival.
         * @param directcontent a canvas to which the time table has to be drawn.
         */
        protected void DrawTimeTable(PdfContentByte directcontent)
        {
            directcontent.SaveState();
            directcontent.SetLineWidth(1.2f);
            float llx, lly, urx, ury;

            llx = OFFSET_LEFT;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LEFT + WIDTH;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePath();
            directcontent.Stroke();

            llx = OFFSET_LOCATION;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LOCATION + WIDTH_LOCATION;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePathStroke();

            directcontent.SetLineWidth(1);
            directcontent.MoveTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM
            );
            directcontent.LineTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM + HEIGHT
            );
            float y;
            for (int i = 1; i < LOCATIONS; i++)
            {
                y = OFFSET_BOTTOM + (i * HEIGHT_LOCATION);
                if (i == 2 || i == 6)
                {
                    directcontent.MoveTo(OFFSET_LOCATION, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                else
                {
                    directcontent.MoveTo(OFFSET_LOCATION + WIDTH_LOCATION / 2, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                directcontent.MoveTo(OFFSET_LEFT, y);
                directcontent.LineTo(OFFSET_LEFT + WIDTH, y);
            }
            directcontent.Stroke();
            directcontent.RestoreState();
        }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:59,代碼來源:MovieTimeTable.cs

示例7: Render_FrontBase

        private static void Render_FrontBase(PdfContentByte under, DateTime expiration)
        {
            float BORDER_WIDTH = 1.5f;

            // Draw background stripes and bars
            under.SaveState();
            under.SetRGBColorFill(0xff, 0x45, 0x00);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT), CARD_WIDTH, (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT + LOWER_BAR_HEIGHT));
            under.Fill();
            under.SetRGBColorFill(0x0, 0x0, 0x0);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT) - BORDER_WIDTH, CARD_WIDTH, PHOTO_BAR_HEIGHT + 2 * BORDER_WIDTH);
            under.Fill();
            under.SetRGBColorFill(0xff, 0xff, 0xff);
            under.Rectangle(0, CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT), CARD_WIDTH, PHOTO_BAR_HEIGHT);
            under.Fill();
            under.RestoreState();

            var img = Image.GetInstance(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "images", "sheriff.png"));
            img.ScaleToFit(CARD_WIDTH - PHOTO_WIDTH - 8, PHOTO_BAR_HEIGHT);
            img.SetAbsolutePosition(
                ((CARD_WIDTH - PHOTO_WIDTH) - img.ScaledWidth) / 2,
                CARD_HEIGHT - (UPPER_BAR_HEIGHT + img.ScaledHeight) - 4);

            under.AddImage(img);

            Font f = new Font(baseFont, 8) { Color = BaseColor.WHITE };

            Phrase p = new Phrase("Expiration:", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_LEFT, p, 4, CARD_HEIGHT - 10, 0);
            p = new Phrase(expiration.ToString("MM/dd/yyyy"), f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_RIGHT, p, CARD_WIDTH - 4, CARD_HEIGHT - 10, 0);

            f = new Font(baseFont, 11) { Color = BaseColor.WHITE };
            p = new Phrase("King County", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 34, 0);

            f = new Font(baseFont, 14, Font.BOLD) { Color = BaseColor.WHITE };

            p = new Phrase("Search & Rescue", f);
            ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, CARD_HEIGHT - 49, 0);
        }
開發者ID:mattkur,項目名稱:KCSARA-Database,代碼行數:41,代碼來源:BadgeService.cs

示例8: AddWaterMarkText

        private static void AddWaterMarkText(PdfContentByte directContent, string textWatermark, BaseFont font, float fontSize, float angle, BaseColor color, Rectangle realPageSize)
        {
            var gstate = new PdfGState { FillOpacity = 0.2f, StrokeOpacity = 0.2f };

            directContent.SaveState();
            directContent.SetGState(gstate);
            directContent.SetColorFill(color);
            directContent.BeginText();
            directContent.SetFontAndSize(font, fontSize);

            var x = (realPageSize.Right + realPageSize.Left) / 2;
            var y = (realPageSize.Bottom + realPageSize.Top) / 2;

            directContent.ShowTextAligned(Element.ALIGN_CENTER, textWatermark, x, y, angle);
            directContent.EndText();
            directContent.RestoreState();
        }
開發者ID:fabiohvp,項目名稱:DocumentSigner,代碼行數:17,代碼來源:PdfHelper.cs

示例9: DirectDrawReport

        private void DirectDrawReport(PdfContentByte canvas)
        {
            //畫線
            canvas.SaveState();
            canvas.SetLineWidth(2f);
            canvas.MoveTo(100, 100);
            canvas.LineTo(200, 200);
            canvas.Stroke();
            canvas.RestoreState();

            //文本
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("JulyLuo測試", new Font(BF_Light, 10)), 100, 20, 0);
        }
開發者ID:GitForShadow,項目名稱:PersonalProfile,代碼行數:13,代碼來源:ReportDemo.cs

示例10: Render_BackBase

        private static void Render_BackBase(PdfContentByte under)
        {
            // Y relative to card top, line width, <repeat>
            float[] measures = new[] { 37, 3f, 144, 1.5f };

            under.SaveState();
            for (int i = 0; i < measures.Length / 2; i++)
            {
                under.SetLineWidth(measures[i * 2 + 1]);
                under.MoveTo(0, CARD_HEIGHT - measures[i * 2]);
                under.LineTo(CARD_WIDTH, CARD_HEIGHT - measures[i * 2]);
                under.Stroke();
            }

            under.SetFontAndSize(baseFont, 7);
            under.ShowTextAlignedKerned(Element.ALIGN_CENTER, "If found, please call KCSAR at (206) 205-8226", CARD_WIDTH / 2, 7, 0);

            under.RestoreState();
        }
開發者ID:mattkur,項目名稱:KCSARA-Database,代碼行數:19,代碼來源:BadgeService.cs

示例11: DrawBlock

// ---------------------------------------------------------------------------        
    /**
     * Draws a colored block on the time table, corresponding with
     * the screening of a specific movie.
     * @param    screening    a screening POJO, contains a movie and a category
     * @param    under    the canvas to which the block is drawn
     */
    protected void DrawBlock(
      Screening screening, PdfContentByte under, PdfContentByte over
    ) {
      under.SaveState();
      BaseColor color = WebColors.GetRGBColor(
        "#" + screening.movie.entry.category.color
      );
      under.SetColorFill(color);
      Rectangle rect = GetPosition(screening);
      under.Rectangle(
        rect.Left, rect.Bottom, rect.Width, rect.Height
      );
      under.Fill();
      over.Rectangle(
        rect.Left, rect.Bottom, rect.Width, rect.Height
      );
      over.Stroke();
      under.RestoreState();
    }
開發者ID:,項目名稱:,代碼行數:26,代碼來源:

示例12: CreateSquares

// ---------------------------------------------------------------------------    
    /**
     * Draws a row of squares.
     * @param canvas the canvas to which the squares have to be drawn
     * @param x      X coordinate to position the row
     * @param y      Y coordinate to position the row
     * @param side   the side of the square
     * @param gutter the space between the squares
     */
    public void CreateSquares(PdfContentByte canvas,
      float x, float y, float side, float gutter) {
      canvas.SaveState();
      canvas.SetColorStroke(new GrayColor(0.2f));
      canvas.SetColorFill(new GrayColor(0.9f));
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Stroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Fill();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.FillStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathFillStroke();
      canvas.RestoreState();
    }
開發者ID:,項目名稱:,代碼行數:45,代碼來源:

示例13: WriteSelectedRows

 /**
 * Writes the selected rows to the document.
 * This method clips the columns; this is only important
 * if there are columns with colspan at boundaries.
 * <P>
 * The table event is only fired for complete rows.
 *
 * @param colStart the first column to be written, zero index
 * @param colEnd the last column to be written + 1. If it is -1 all the
 * @param rowStart the first row to be written, zero index
 * @param rowEnd the last row to be written + 1. If it is -1 all the
 * rows to the end are written
 * @param xPos the x write coodinate
 * @param yPos the y write coodinate
 * @param canvas the <CODE>PdfContentByte</CODE> where the rows will
 * be written to
 * @return the y coordinate position of the bottom of the last row
 */
 public float WriteSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
 {
     if (colEnd < 0)
         colEnd = absoluteWidths.Length;
     colEnd = Math.Min(colEnd, absoluteWidths.Length);
     if (colStart < 0)
         colStart = 0;
     colStart = Math.Min(colStart, absoluteWidths.Length);
     if (colStart != 0 || colEnd != absoluteWidths.Length) {
         float w = 0;
         for (int k = colStart; k < colEnd; ++k)
             w += absoluteWidths[k];
         canvas.SaveState();
         float lx = 0;
         float rx = 0;
         if (colStart == 0)
             lx = 10000;
         if (colEnd == absoluteWidths.Length)
             rx = 10000;
         canvas.Rectangle(xPos - lx, -10000, w + lx + rx, 20000);
         canvas.Clip();
         canvas.NewPath();
     }
     PdfContentByte[] canvases = BeginWritingRows(canvas);
     float y = WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos, canvases);
     EndWritingRows(canvases);
     if (colStart != 0 || colEnd != absoluteWidths.Length)
         canvas.RestoreState();
     return y;
 }
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:48,代碼來源:PdfPTable.cs

示例14: DrawImageAndText

 // ---------------------------------------------------------------------------
 /**
  * Draws the image of the month to the calendar.
  * @param canvas the direct content layer
  * @param dt the DateTime (to know which picture to use)
  */
 public void DrawImageAndText(PdfContentByte canvas, DateTime dt)
 {
     string MM = dt.ToString("MM");
     // get the image
     Image img = Image.GetInstance(Path.Combine(
       RESOURCE, MM + ".jpg"
     ));
     img.ScaleToFit(PageSize.A4.Height, PageSize.A4.Width);
     img.SetAbsolutePosition(
       (PageSize.A4.Height - img.ScaledWidth) / 2,
       (PageSize.A4.Width - img.ScaledHeight) / 2
     );
     canvas.AddImage(img);
     // add metadata
     canvas.SaveState();
     canvas.SetCMYKColorFill(0x00, 0x00, 0x00, 0x80);
     Phrase p = new Phrase(string.Format(
         "{0} - \u00a9 Katharine Osborne",
         content[string.Format("{0}.jpg", dt.ToString("MM"))]
       ),
       small
     );
     ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, p, 5, 5, 0);
     p = new Phrase(
       "Calendar generated using iText - example for the book iText in Action 2nd Edition",
       small
     );
     ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, p, 839, 5, 0);
     canvas.RestoreState();
 }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:36,代碼來源:PdfCalendar.cs

示例15: Layout

        virtual public int Layout(PdfContentByte canvas, bool useAscender, bool simulate, float llx, float lly, float urx, float ury)
        {
            float leftX = Math.Min(llx, urx);
            float maxY = Math.Max(lly, ury);
            float minY = Math.Min(lly, ury);
            float rightX = Math.Max(llx, urx);
            yLine = maxY;
            bool contentCutByFixedHeight = false;

            if (width != null && width > 0)
            {
                if (width < rightX - leftX)
                    rightX = leftX + (float) width;
                else if (width > rightX - leftX)
                    return ColumnText.NO_MORE_COLUMN;
            }
            else if (percentageWidth != null)
            {
                contentWidth = (rightX - leftX)*(float) percentageWidth;
                rightX = leftX + contentWidth;
            }

            if (height != null && height > 0)
            {
                if (height < maxY - minY)
                {
                    contentCutByFixedHeight = true;
                    minY = maxY - (float) height;
                }
                else if (height > maxY - minY)
                {
                    return ColumnText.NO_MORE_COLUMN;
                }
            }
            else if (percentageHeight != null)
            {
                if (percentageHeight < 1.0)
                    contentCutByFixedHeight = true;
                contentHeight = (maxY - minY)*(float) percentageHeight;
                minY = maxY - contentHeight;
            }

            if (!simulate && position == PdfDiv.PositionType.RELATIVE)
            {
                float? translationX = null;
                if (left != null)
                    translationX = left;
                else if (right != null)
                    translationX = -right;
                else
                    translationX = 0f;

                float? translationY = null;
                if (top != null)
                    translationY = -top;
                else if (bottom != null)
                    translationY = bottom;
                else
                    translationY = 0f;
                canvas.SaveState();
                canvas.Transform(new AffineTransform(1f, 0, 0, 1f, translationX.Value, translationY.Value));
            }

            if (!simulate)
            {
                if (backgroundColor != null && getActualWidth() > 0 && getActualHeight() > 0)
                {
                    float backgroundWidth = getActualWidth();
                    float backgroundHeight = getActualHeight();
                    if (width != null)
                        backgroundWidth = width > 0 ? (float) width : 0;
                    if (height != null)
                        backgroundHeight = height > 0 ? (float) height : 0;
                    if (backgroundWidth > 0 && backgroundHeight > 0)
                    {
                        Rectangle background = new Rectangle(leftX, maxY - backgroundHeight, leftX + backgroundWidth, maxY);
                        background.BackgroundColor = backgroundColor;
                        PdfArtifact artifact = new PdfArtifact();
                        canvas.OpenMCBlock(artifact);
                        canvas.Rectangle(background);
                        canvas.CloseMCBlock(artifact);
                    }
                }
            }

            if (percentageWidth == null)
                contentWidth = 0;
            if (percentageHeight == null)
                contentHeight = 0;

            minY += paddingBottom;
            leftX += paddingLeft;
            rightX -= paddingRight;

            yLine -= paddingTop;

            int status = ColumnText.NO_MORE_TEXT;

            if (content.Count > 0) {
                if (floatLayout == null) {
//.........這裏部分代碼省略.........
開發者ID:,項目名稱:,代碼行數:101,代碼來源:


注:本文中的iTextSharp.text.pdf.PdfContentByte.SaveState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。