Example #1
0
 protected static void CreateCalcPartPostScriptCode(PdfColor color0, PdfColor color1, float offset0, float offset1, StringBuilder builder)
 {
     CreateCalcItemPostScriptCode(color0.RedF, color1.RedF, offset0, offset1, builder);
     CreateCalcItemPostScriptCode(color0.GreenF, color1.GreenF, offset0, offset1, builder);
     CreateCalcItemPostScriptCode(color0.BlueF, color1.BlueF, offset0, offset1, builder);
     builder.Append("pop").Append("\r\n");
 }
Example #2
0
 public void DrawLine(float x1, float y1, float x2, float y2, float th, PdfColor stroke)
 {
     InnerWrite("ET\nq\n" + stroke.getColorSpaceOut(false)
                + PdfNumber.doubleOut(x1 / 1000f) + " " + PdfNumber.doubleOut(y1 / 1000f) + " m "
                + PdfNumber.doubleOut(x2 / 1000f) + " " + PdfNumber.doubleOut(y2 / 1000f) + " l "
                + PdfNumber.doubleOut(th / 1000f) + " w S\n" + "Q\nBT\n");
 }
Example #3
0
 /// <summary>
 /// Add rectangle primitive to the page
 /// </summary>
 public RectangleElement AddRectangle(float x1, float y1, float x2, float y2, PdfColor fill, float borderThickness, PdfColor borderColor, PdfLineType borderType)
 {
     return(AddRectangle(x1, y1, x2, y2, new PdfDrawStyle(borderThickness, borderColor, borderType)
     {
         FillColor = fill
     }));
 }
Example #4
0
 public void DrawRect(float x, float y, float w, float h, PdfColor stroke)
 {
     InnerWrite("ET\nq\n" + stroke.getColorSpaceOut(false)
                + PdfNumber.doubleOut(x / 1000f) + " " + PdfNumber.doubleOut(y / 1000f) + " "
                + PdfNumber.doubleOut(w / 1000f) + " " + PdfNumber.doubleOut(h / 1000f) + " re s\n"
                + "Q\nBT\n");
 }
Example #5
0
 public void DrawAndFillRect(float x, float y, float w, float h, PdfColor stroke, PdfColor fill)
 {
     InnerWrite("ET\nq\n" + fill.getColorSpaceOut(true)
                + stroke.getColorSpaceOut(false) + PdfNumber.doubleOut(x / 1000f)
                + " " + PdfNumber.doubleOut(y / 1000f) + " " + PdfNumber.doubleOut(w / 1000f) + " "
                + PdfNumber.doubleOut(h / 1000f) + " re b\n" + "Q\nBT\n");
 }
Example #6
0
        public static void ApplyLightTableStyle(this PdfLightTable pdfLightTable, PdfColor borderColor, PdfColor textColor, PdfColor altBackgroundColor, PdfColor altTextColor)
        {
            //TODO: Extension
            var retStyle = new PdfLightTableStyle
            {
                BorderPen    = new PdfPen(borderColor),
                DefaultStyle = new PdfCellStyle
                {
                    TextBrush = new PdfSolidBrush(textColor),
                    BorderPen = new PdfPen(borderColor)
                },
                AlternateStyle = new PdfCellStyle
                {
                    TextBrush       = new PdfSolidBrush(textColor),
                    BackgroundBrush = new PdfSolidBrush(altBackgroundColor),
                    BorderPen       = new PdfPen(borderColor)
                },
                ShowHeader   = true,
                RepeatHeader = true,
                HeaderSource = PdfHeaderSource.ColumnCaptions,
                HeaderStyle  = new PdfCellStyle
                {
                    BorderPen       = new PdfPen(borderColor),
                    BackgroundBrush = new PdfSolidBrush(borderColor),
                    TextBrush       = new PdfSolidBrush(altTextColor)
                }
            };

            pdfLightTable.Style = retStyle;
        }
        private static void highlightPhrases(PdfDocument pdf, string textToFind, StringComparison comparison,
                                             PdfColor highlightColor)
        {
            if (string.IsNullOrEmpty(textToFind))
            {
                throw new ArgumentNullException(nameof(textToFind));
            }

            string[] wordsToFind = textToFind
                                   .Split(' ')
                                   .Where(w => !string.IsNullOrEmpty(w))
                                   .ToArray();
            foreach (PdfPage page in pdf.Pages)
            {
                foreach (PdfRectangle[] phraseBounds in findPhrases(page, wordsToFind, comparison))
                {
                    PdfHighlightAnnotation annot = page.AddHighlightAnnotation("", phraseBounds[0], highlightColor);
                    if (phraseBounds.Length > 1)
                    {
                        annot.SetTextBounds(phraseBounds.Select(b => (PdfQuadrilateral)b));
                    }

                    // Or you can highlight the text using vector graphics:
                    //page.Canvas.Brush.Color = highlightColor;
                    //page.Canvas.Brush.Opacity = 50;
                    //foreach (var bounds in phraseBounds)
                    //    page.Canvas.DrawRectangle(bounds, PdfDrawMode.Fill);
                }
            }
        }
Example #8
0
 /// <summary>
 /// Add circle primitive to the page
 /// </summary>
 public PathElement AddCircle(float centerX, float centerY, float r, PdfColor fill, float borderThickness, PdfColor borderColor, PdfLineType borderType)
 {
     return(AddCircle(centerX, centerY, r, new PdfDrawStyle(borderThickness, borderColor, borderType)
     {
         FillColor = fill
     }));
 }
Example #9
0
 public TextElement(string content, float fontSize, PdfFont font, PdfColor color)
 {
     Content  = content;
     FontSize = fontSize;
     Font     = font;
     Color    = color;
 }
Example #10
0
        private static void setBrushAndPen(PdfCanvas target, PdfPath path)
        {
            if (path.PaintMode == PdfDrawMode.Fill || path.PaintMode == PdfDrawMode.FillAndStroke)
            {
                target.Brush.Opacity = path.Brush.Opacity;

                PdfColor color = path.Brush.Color;
                if (color != null)
                {
                    target.Brush.Color = path.Brush.Color;
                }
            }

            if (path.PaintMode == PdfDrawMode.Stroke || path.PaintMode == PdfDrawMode.FillAndStroke)
            {
                target.Pen.Opacity     = path.Pen.Opacity;
                target.Pen.Width       = path.Pen.Width;
                target.Pen.DashPattern = path.Pen.DashPattern;
                target.Pen.EndCap      = path.Pen.EndCap;
                target.Pen.LineJoin    = path.Pen.LineJoin;
                target.Pen.MiterLimit  = path.Pen.MiterLimit;

                PdfColor color = path.Pen.Color;
                if (color != null)
                {
                    target.Pen.Color = path.Pen.Color;
                }
            }
        }
Example #11
0
 public PdfTextLine(string text_line, int text_scale, PdfFont font, PdfAlign h_align, PdfColor color = null)
 {
     TextLine  = text_line;
     TextScale = text_scale;
     HAlign    = h_align;
     Color     = color;
     _font     = font;
 }
Example #12
0
        /// <summary>
        /// Add raw text to the page
        /// </summary>
        public TextElement AddText(string text, float fontSize, PdfFont font, PdfColor foreground)
        {
            var element = new TextElement(text, fontSize, font, foreground);

            Add(element);

            return(element);
        }
        private void AddHeader(PdfDocument doc, string title, string description)
        {
            RectangleF rect      = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfColor   blueColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 255));
            PdfColor   GrayColor = new PdfColor(System.Drawing.Color.FromArgb(255, 128, 128, 128));

            //Create page template
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfFont font         = new PdfStandardFont(PdfFontFamily.Helvetica, 24);
            float   doubleHeight = font.Height * 2;

            System.Drawing.Color activeColor = System.Drawing.Color.FromArgb(255, 44, 71, 120);
            SizeF imageSize = new SizeF(110f, 35f);
            //Locating the logo on the right corner of the Drawing Surface
            PointF imageLocation = new PointF(doc.Pages[0].GetClientSize().Width - imageSize.Width - 20, 5);

            Stream   imgStream = typeof(HeadersAndFooters).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.logo.png");
            PdfImage img       = new PdfBitmap(imgStream);

            //Draw the image in the Header.
            header.Graphics.DrawImage(img, imageLocation, imageSize);

            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            PdfPen pen = new PdfPen(blueColor, 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);

            //Set formattings for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            //Draw title
            header.Graphics.DrawString(title, font, brush, new RectangleF(0, 0, header.Width, header.Height), format);
            brush = new PdfSolidBrush(GrayColor);
            font  = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

            format               = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Left;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

            //Draw description
            header.Graphics.DrawString(description, font, brush, new RectangleF(0, 0, header.Width, header.Height - 8), format);

            //Draw some lines in the header
            pen = new PdfPen(blueColor, 0.7f);
            header.Graphics.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(blueColor, 2f);
            header.Graphics.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(blueColor, 2f);
            header.Graphics.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            header.Graphics.DrawLine(pen, 0, header.Height, header.Width, header.Height);

            //Add header template at the top.
            doc.Template.Top = header;
        }
        /// <summary>
        /// Utility method that will create a new pen.
        /// </summary>
        /// <returns>The pen.</returns>
        /// <param name="color">Color.</param>
        private static PdfPen NewPen(PdfColor color, double width = 1)
        {
            var ret = new PdfPen();

            ret.Color = color;
            ret.Width = 1;

            return(ret);
        }
 public PdfGraphicsOptions(double strokeWidth = 0.0, PdfColor strokeColor = null, PdfColor fillColor = null, PdfLineDashPattern lineStyle = null, PdfLineCapStyle?lineCapStyle = null, PdfLineJoinStyle?lineJoinStyle = null)
 {
     this.StrokeColor     = strokeColor ?? PdfColor.Black;
     this.FillColor       = fillColor ?? PdfColor.White;
     this.LineDashPattern = lineStyle ?? PdfLineDashPattern.Solid;
     this.StrokeWidth     = strokeWidth;
     this.LineCapstyle    = lineCapStyle;
     this.LineJoinStyle   = lineJoinStyle;
 }
Example #16
0
 public PdfTextLine(string text_line, int text_scale, string typeface, PdfAlign h_align, bool bold = false, bool italic = false, PdfColor color = null)
 {
     TextLine  = text_line;
     TextScale = text_scale;
     HAlign    = h_align;
     Color     = color;
     _typeface = typeface;
     _bold     = bold;
     _italic   = italic;
 }
Example #17
0
 public PdfTextIn(PdfFontMetrics metrics, string font_name, int codepage, int text_scale, string text, PdfAlign h_align, PdfColor color, bool kerning = false)
 {
     Metrics   = metrics;
     FontName  = font_name;
     CodePage  = codepage;
     TextScale = text_scale;
     Text      = text;
     HAlign    = h_align;
     Color     = color;
     Kerning   = kerning;
 }
Example #18
0
 public PdfTextOut(PdfAlign h_align, string font_name, int text_scale, double width, double y, double word_spacing, int codepage, PdfColor color, string text)
 {
     HAlign      = h_align;
     FontName    = font_name;
     TextScale   = text_scale;
     Width       = width;
     Y           = y;
     WordSpacing = word_spacing;
     CodePage    = codepage;
     Color       = color;
     Text        = text;
 }
Example #19
0
 public PdfTextOptions(PdfFont font, double fontSize, PdfColor inkColor, int leftRotationDegrees, PdfTextRenderingMode renderingMode = PdfTextRenderingMode.Fill, PdfColor outlineColor = null, double?outlineWidth = null, PdfLineDashPattern lineDashPattern = null, PdfLineCapStyle?lineCapStyle = null)
 {
     this.InkColor            = inkColor ?? PdfColor.Black;
     this.Font                = font;
     this.FontSize            = fontSize;
     this.LeftRotationDegrees = leftRotationDegrees;
     this.RenderingMode       = renderingMode;
     this.OutlineColor        = outlineColor;
     this.LineDashPattern     = lineDashPattern;
     this.LineCapStyle        = LineCapStyle;
     this.OutlineWidth        = outlineWidth;
 }
        private void Draw(PdfGraphics g, Box box)
        {
            var boxX = (float)box.Layout.X;
            var boxY = (float)box.Layout.Y;
            var boxH = (float)box.Layout.Height;
            var boxW = (float)box.Layout.Width;

            var color      = new PdfColor(GetColor(box.Appearance.Background));
            var background = new PdfSolidBrush(color);

            g.DrawRectangle(background, boxX, boxY, boxW, boxH);
        }
Example #21
0
        private void AddHeader(PdfDocument doc, string title)
        {
            RectangleF rect = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);

            //Create page template
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);

            //Create a new PDF standard font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 24);

            float doubleHeight = font.Height * 2;

            PdfColor activeColor = new PdfColor(24, 21, 104);

            SizeF imageSize = new SizeF(110f, 30f);

            //Locating the logo on the right corner of the Drawing Surface
            PointF imageLocation = new PointF(doc.Pages[0].GetClientSize().Width - imageSize.Width - 10, 5);

            Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.logo.jpg");

            PdfImage img = new PdfBitmap(imgStream);

            //Draw the image in the Header.
            header.Graphics.DrawImage(img, imageLocation, imageSize);

            //Create new PDF solid brush
            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            //Create a new PDF pen
            PdfPen pen = new PdfPen(new PdfColor(72, 61, 139), 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);

            //Set formattings for the text
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment = PdfTextAlignment.Center;

            format.LineAlignment = PdfVerticalAlignment.Middle;

            //Draw title
            header.Graphics.DrawString(title, font, brush, new RectangleF(0, 0, header.Width, header.Height), format);

            pen = new PdfPen(new PdfColor(24, 21, 104), 2f);

            header.Graphics.DrawLine(pen, 10, header.Height, header.Width - 10, header.Height);

            //Add header template at the top.
            doc.Template.Top = header;
        }
Example #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            var document = new PdfDocument();

            document.Fonts.Add(PdfFont.Times);


            var page = document.AddPage();

            // simple text: english français español übersetzen 日本人 Ελλάδα русский 中国
            var text = page.AddText(@"Hello world", 20, PdfFont.Times, PdfColor.Blue);

            text.X = 10;
            text.Y = 730;

            // path
            var path = page.AddPath(200, 200);

            path.AddLine(250, 250);
            path.AddLine(300, 200);
            path.AddBezier(300, 250, 350, 300, 400, 300);
            path.AddBezier(500, 350, 450, 400, 400, 300);

            // lines
            page.AddLine(20, 620, 50, 620);
            page.AddLine(50, 620, 70, 600, 2.5F);
            page.AddLine(70, 600, 80, 550, 0.5F, PdfColor.Red);
            page.AddLine(80, 550, 80, 530, 1.0F, PdfColor.Green, PdfLineType.Outlined);
            page.AddLine(80, 530, 80, 500, 3.2F, PdfColor.DarkBlue, PdfLineType.OutlinedBold);
            page.AddLine(80, 500, 120, 500, 1.0F, PdfColor.Black, PdfLineType.Normal);
            page.AddLine(130, 500, 170, 500, 1.0F, PdfColor.Black, PdfLineType.Outlined);
            page.AddLine(180, 500, 240, 500, 1.0F, PdfColor.Black, PdfLineType.OutlinedThin);
            page.AddLine(250, 500, 290, 500, 1.0F, PdfColor.Black, PdfLineType.OutlinedBold);

            // rectangles
            page.AddRectangle(100, 600, 200, 700, PdfColor.Blue);
            page.AddRectangle(210, 600, 250, 680, PdfColor.Red, 0.1F);
            page.AddRectangle(260, 600, 300, 700, PdfColor.ByName("custom1", 10, 200, 100), 2.3F, PdfColor.DarkRed);

            // circles
            page.AddCircle(0, 0, 100, PdfColor.Blue);
            page.AddCircle(0, 50, 50, PdfColor.Red, 0.0F);
            page.AddCircle(350, 650, 50, PdfColor.ByName("custom2", 150, 150, 50), 2.0F, PdfColor.LightBlue);

            document.Save(@"test.pdf");

            Process.Start(@"test.pdf");
        }
Example #23
0
 /// <summary>
 /// Creates the specified x0.
 /// </summary>
 /// <param name="x0">The x0.</param>
 /// <param name="y0">The y0.</param>
 /// <param name="x1">The x1.</param>
 /// <param name="y1">The y1.</param>
 /// <param name="startColor">The start color.</param>
 /// <param name="endColor">The end color.</param>
 /// <param name="extendStart">if set to <c>true</c> [extend start].</param>
 /// <param name="extendEnd">if set to <c>true</c> [extend end].</param>
 /// <returns></returns>
 public static PdfAxialShading Create(float x0, float y0, float x1, float y1, PdfColor startColor, PdfColor endColor, bool extendStart, bool extendEnd)
 {
     if (startColor == null)
     {
         throw new PdfArgumentNullException("startColor");
     }
     if (endColor == null)
     {
         throw new PdfArgumentNullException("endColor");
     }
     float[] domain = new float[2];
     domain[1] = 1f;
     return(new PdfAxialShading(new float[] { x0, y0, x1, y1 }, PdfFunction.Type2(domain, null, 1f, startColor.ToArray(), endColor.ToArray()))
     {
         ExtendStart = extendStart, ExtendEnd = extendEnd
     });
 }
        private static Color toGdiColor(PdfColor pdfColor, int opacityPercent)
        {
            if (pdfColor == null)
            {
                return(Color.Empty);
            }

            PdfRgbColor rgbColor = pdfColor.ToRgb();

            int alpha = 255;

            if (opacityPercent < 100 && opacityPercent >= 0)
            {
                alpha = (int)(255.0 * opacityPercent / 100.0);
            }

            return(Color.FromArgb(alpha, rgbColor.R, rgbColor.G, rgbColor.B));
        }
Example #25
0
        private static void HighlightSearchResults(PdfPage page, PdfTextSearchResultCollection searchResults, PdfColor color)
        {
            PdfPen pen = new PdfPen(color, 0.5);

            for (int i = 0; i < searchResults.Count; i++)
            {
                PdfTextFragmentCollection tfc = searchResults[i].TextFragments;
                for (int j = 0; j < tfc.Count; j++)
                {
                    PdfPath path = new PdfPath();

                    path.StartSubpath(tfc[j].FragmentCorners[0].X, tfc[j].FragmentCorners[0].Y);
                    path.AddPolygon(tfc[j].FragmentCorners);

                    page.Graphics.DrawPath(pen, path);
                }
            }
        }
Example #26
0
        private static void setBrush(PdfBrush dst, PdfBrushInfo src)
        {
            PdfColor color = src.Color;

            if (color != null)
            {
                dst.Color = color;
            }

            dst.Opacity = src.Opacity;

            var pattern = src.Pattern;

            if (pattern != null)
            {
                dst.Pattern = pattern;
            }
        }
Example #27
0
        private static Color toGdiColor(PdfColor pdfColor, int opacityPercent)
        {
            if (pdfColor == null)
            {
                return(Color.Empty);
            }

            // NOTE: PdfColor.ToColor() method is not supported in version for .NET Standard
            Color color = pdfColor.ToColor();

            int alpha = 255;

            if (opacityPercent < 100 && opacityPercent >= 0)
            {
                alpha = (int)(255.0 * opacityPercent / 100.0);
            }

            return(Color.FromArgb(alpha, color.R, color.G, color.B));
        }
        public void Setup(string firstPageName)
        {
            //Create a new PDF document.
            Document = new PdfDocument();
            Document.Pages.PageAdded += Pages_PageAdded;
            //Add a page to the document.
            AddPage(firstPageName);

            AccentColor           = new PdfColor(89, 106, 122);
            AccentBrush           = new PdfSolidBrush(AccentColor);
            PdfGridStyle2Color    = new PdfColor(237, 125, 49);
            PdfGridStyle2AltColor = new PdfColor(251, 228, 213);
            PdfGridStyle2Brush    = new PdfSolidBrush(PdfGridStyle2Color);

            NormalFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 10);
            PdfFontStyle style = PdfFontStyle.Bold;

            NormalFontBold = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, style);
            SubHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 18);
        }
        private void AddFooter(PdfDocument doc, string footerText)
        {
            RectangleF rect      = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfColor   blueColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 255));
            PdfColor   GrayColor = new PdfColor(System.Drawing.Color.FromArgb(255, 128, 128, 128));
            //Create a page template
            PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8);

            PdfSolidBrush brush = new PdfSolidBrush(GrayColor);

            PdfPen pen = new PdfPen(blueColor, 3f);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);
            PdfStringFormat format = new PdfStringFormat();

            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;
            footer.Graphics.DrawString(footerText, font, brush, new RectangleF(0, 18, footer.Width, footer.Height), format);

            format               = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Right;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

            //Create page number field
            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field
            PdfPageCountField count = new PdfPageCountField(font, brush);

            PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);

            compositeField.Bounds = footer.Bounds;
            compositeField.Draw(footer.Graphics, new PointF(470, 40));

            //Add the footer template at the bottom
            doc.Template.Bottom = footer;
        }
Example #30
0
        private static void setPen(PdfPen dst, PdfPenInfo src)
        {
            PdfColor color = src.Color;

            if (color != null)
            {
                dst.Color = color;
            }

            var pattern = src.Pattern;

            if (pattern != null)
            {
                dst.Pattern = pattern;
            }

            dst.DashPattern = src.DashPattern;
            dst.EndCap      = src.EndCap;
            dst.LineJoin    = src.LineJoin;
            dst.MiterLimit  = src.MiterLimit;
            dst.Opacity     = src.Opacity;
            dst.Width       = src.Width;
        }
Example #31
0
        /**
        * add a line to the current stream
        *
        * @param x1 the start x location in millipoints
        * @param y1 the start y location in millipoints
        * @param x2 the end x location in millipoints
        * @param y2 the end y location in millipoints
        * @param th the thickness in millipoints
        * @param rs the rule style
        * @param r the red component
        * @param g the green component
        * @param b the blue component
        */

        private void AddLine(int x1, int y1, int x2, int y2, int th, int rs,
                             PdfColor stroke) {
            CloseText();
            currentStream.Write("ET\nq\n" + stroke.getColorSpaceOut(false)
                + SetRuleStylePattern(rs) + PdfNumber.doubleOut(x1/1000f) + " "
                + PdfNumber.doubleOut(y1/1000f) + " m " + PdfNumber.doubleOut(x2/1000f) + " "
                + PdfNumber.doubleOut(y2/1000f) + " l " + PdfNumber.doubleOut(th/1000f) + " w S\n"
                + "Q\nBT\n");
        }
Example #32
0
        private void AddWordLines(WordArea area, int rx, int bl, int size,
                                  PdfColor theAreaColor) {
            if (area.getUnderlined()) {
                int yPos = bl - size/10;
                AddLine(rx, yPos, rx + area.getContentWidth(), yPos, size/14,
                        theAreaColor);
                // save position for underlining a following InlineSpace
                prevUnderlineXEndPos = rx + area.getContentWidth();
                prevUnderlineYEndPos = yPos;
                prevUnderlineSize = size/14;
                prevUnderlineColor = theAreaColor;
            }

            if (area.getOverlined()) {
                int yPos = bl + area.GetFontState().Ascender + size/10;
                AddLine(rx, yPos, rx + area.getContentWidth(), yPos, size/14,
                        theAreaColor);
                prevOverlineXEndPos = rx + area.getContentWidth();
                prevOverlineYEndPos = yPos;
                prevOverlineSize = size/14;
                prevOverlineColor = theAreaColor;
            }

            if (area.getLineThrough()) {
                int yPos = bl + area.GetFontState().Ascender*3/8;
                AddLine(rx, yPos, rx + area.getContentWidth(), yPos, size/14,
                        theAreaColor);
                prevLineThroughXEndPos = rx + area.getContentWidth();
                prevLineThroughYEndPos = yPos;
                prevLineThroughSize = size/14;
                prevLineThroughColor = theAreaColor;
            }
        }
Example #33
0
        public void StopRenderer() {
            fontSetup.AddToResources(new PdfFontCreator(pdfDoc), pdfDoc.getResources());
            pdfDoc.outputTrailer();

            pdfDoc = null;
            pdfResources = null;
            currentStream = null;
            currentAnnotList = null;
            currentPage = null;

            idReferences = null;
            currentFontName = String.Empty;
            currentFill = null;
            prevUnderlineColor = null;
            prevOverlineColor = null;
            prevLineThroughColor = null;
            fontSetup = null;
            fontInfo = null;
        }
Example #34
0
        /**
        * add a filled rectangle to the current stream
        *
        * @param x the x position of left edge in millipoints
        * @param y the y position of top edge in millipoints
        * @param w the width in millipoints
        * @param h the height in millipoints
        * @param fill the fill color/gradient
        */

        private void AddFilledRect(int x, int y, int w, int h,
                                   PdfColor fill) {
            CloseText();
            currentStream.Write("ET\nq\n" + fill.getColorSpaceOut(true)
                + PdfNumber.doubleOut(x/1000f) + " " + PdfNumber.doubleOut(y/1000f) + " "
                + PdfNumber.doubleOut(w/1000f) + " " + PdfNumber.doubleOut(h/1000f) + " re f\n"
                + "Q\nBT\n");
        }
Example #35
0
        /**
        * render inline area to PDF
        *
        * @param area inline area to render
        */

        public void RenderWordArea(WordArea area) {
            // TODO: I don't understand why we are locking the private member
            // _wordAreaPDF.  Maybe this string buffer was originally static? (MG)
            lock (_wordAreaPDF) {
                StringBuilder pdf = _wordAreaPDF;
                pdf.Length = 0;

                GdiKerningPairs kerning = null;
                bool kerningAvailable = false;

                // If no options are supplied, by default we do not enable kerning
                if (options != null && options.Kerning) {
                    kerning = area.GetFontState().Kerning;
                    if (kerning != null && (kerning.Count > 0)) {
                        kerningAvailable = true;
                    }
                }

                String name = area.GetFontState().FontName;
                int size = area.GetFontState().FontSize;

                // This assumes that *all* CIDFonts use a /ToUnicode mapping
                Font font = (Font) area.GetFontState().FontInfo.GetFontByName(name);
                bool useMultiByte = font.MultiByteFont;

                string startText = useMultiByte ? "<" : "(";
                string endText = useMultiByte ? "> " : ") ";

                if ((!name.Equals(this.currentFontName)) || (size != this.currentFontSize)) {
                    CloseText();

                    this.currentFontName = name;
                    this.currentFontSize = size;
                    pdf = pdf.Append("/" + name + " " +
                        PdfNumber.doubleOut(size/1000f) + " Tf\n");
                }

                // Do letter spacing (must be outside of [...] TJ]
                float letterspacing = ((float) area.GetFontState().LetterSpacing)/1000f;
                if (letterspacing != this.currentLetterSpacing) {
                    this.currentLetterSpacing = letterspacing;
                    CloseText();
                    pdf.Append(PdfNumber.doubleOut(letterspacing));
                    pdf.Append(" Tc\n");
                }

                PdfColor areaColor = this.currentFill;

                if (areaColor == null || areaColor.getRed() != (double) area.getRed()
                    || areaColor.getGreen() != (double) area.getGreen()
                    || areaColor.getBlue() != (double) area.getBlue()) {
                    areaColor = new PdfColor((double) area.getRed(),
                                             (double) area.getGreen(),
                                             (double) area.getBlue());


                    CloseText();
                    this.currentFill = areaColor;
                    pdf.Append(this.currentFill.getColorSpaceOut(true));
                }


                int rx = this.currentXPosition;
                int bl = this.currentYPosition;

                AddWordLines(area, rx, bl, size, areaColor);

                if (!textOpen || bl != prevWordY) {
                    CloseText();

                    pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx/1000f) +
                        " " + PdfNumber.doubleOut(bl/1000f) + " Tm [" + startText);
                    prevWordY = bl;
                    textOpen = true;
                }
                else {
                    // express the space between words in thousandths of an em
                    int space = prevWordX - rx + prevWordWidth;
                    float emDiff = (float) space/(float) currentFontSize*1000f;
                    // this prevents a problem in Acrobat Reader where large
                    // numbers cause text to disappear or default to a limit
                    if (emDiff < -33000) {
                        CloseText();

                        pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx/1000f) +
                            " " + PdfNumber.doubleOut(bl/1000f) + " Tm [" + startText);
                        textOpen = true;
                    }
                    else {
                        pdf.Append(PdfNumber.doubleOut(emDiff));
                        pdf.Append(" ");
                        pdf.Append(startText);
                    }
                }
                prevWordWidth = area.getContentWidth();
                prevWordX = rx;

                string s;
                if (area.getPageNumberID() != null) {
                    // This text is a page number, so resolve it
                    s = idReferences.getPageNumber(area.getPageNumberID());
                    if (s == null) {
                        s = String.Empty;
                    }
                }
                else {
                    s = area.getText();
                }

                int wordLength = s.Length;
                for (int index = 0; index < wordLength; index++) {
                    ushort ch = area.GetFontState().MapCharacter(s[index]);

                    if (!useMultiByte) {
                        if (ch > 127) {
                            pdf.Append("\\");
                            pdf.Append(Convert.ToString((int) ch, 8));

                        }
                        else {
                            switch (ch) {
                                case '(':
                                case ')':
                                case '\\':
                                    pdf.Append("\\");
                                    break;
                            }
                            pdf.Append((char) ch);
                        }
                    }
                    else {
                        pdf.Append(GetUnicodeString(ch));
                    }

                    if (kerningAvailable && (index + 1) < wordLength) {
                        ushort ch2 = area.GetFontState().MapCharacter(s[index + 1]);
                        AddKerning(pdf, ch, ch2, kerning, startText, endText);
                    }

                }
                pdf.Append(endText);

                currentStream.Write(pdf.ToString());

                this.currentXPosition += area.getContentWidth();

            }
        }
Example #36
0
        /**
        * render page into PDF
        *
        * @param page page to render
        */

        public void RenderPage(Page page) {
            BodyAreaContainer body;
            AreaContainer before, after, start, end;

            currentStream = this.pdfDoc.makeContentStream();
            body = page.getBody();
            before = page.getBefore();
            after = page.getAfter();
            start = page.getStart();
            end = page.getEnd();

            this.currentFontName = "";
            this.currentFontSize = 0;
            this.currentLetterSpacing = Single.NaN;

            currentStream.Write("BT\n");

            RenderBodyAreaContainer(body);

            if (before != null) {
                RenderAreaContainer(before);
            }

            if (after != null) {
                RenderAreaContainer(after);
            }

            if (start != null) {
                RenderAreaContainer(start);
            }

            if (end != null) {
                RenderAreaContainer(end);
            }
            CloseText();

            // Bug fix for issue 1823
            this.currentLetterSpacing = Single.NaN;

            float w = page.getWidth();
            float h = page.GetHeight();
            currentStream.Write("ET\n");

            currentPage = this.pdfDoc.makePage(
                this.pdfResources, currentStream,
                Convert.ToInt32(Math.Round(w/1000)),
                Convert.ToInt32(Math.Round(h/1000)), page);

            if (page.hasLinks() || currentAnnotList != null) {
                if (currentAnnotList == null) {
                    currentAnnotList = this.pdfDoc.makeAnnotList();
                }
                currentPage.SetAnnotList(currentAnnotList);

                ArrayList lsets = page.getLinkSets();
                foreach (LinkSet linkSet in lsets) {
                    linkSet.align();
                    String dest = linkSet.getDest();
                    int linkType = linkSet.getLinkType();
                    ArrayList rsets = linkSet.getRects();
                    foreach (LinkedRectangle lrect in rsets) {
                        currentAnnotList.Add(this.pdfDoc.makeLink(lrect.getRectangle(),
                                                                  dest, linkType).GetReference());
                    }
                }
                currentAnnotList = null;
            }
            else {
                // just to be on the safe side
                currentAnnotList = null;
            }

            // ensures that color is properly reset for blocks that carry over pages
            this.currentFill = null;
        }
Example #37
0
        public ActionResult Attachments(string Browser)
        {
            //Creates a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Add a page
            PdfPage page = doc.Pages.Add();

            //Set the font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Bold);

            //Create new PDF color
            PdfColor orangeColor = new PdfColor(255, 255, 167, 73);

            //Draw the text
            page.Graphics.DrawString("Attachments", font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), new PdfStringFormat(PdfTextAlignment.Center));

            //Create font
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);

            page.Graphics.DrawString("This PDF document contains image and text file as attachment.", font, PdfBrushes.Black, new PointF(0, 30));

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 8f, PdfFontStyle.Regular);

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 50));

            page.Graphics.DrawString("Click to open the attachment:", font, PdfBrushes.Black, new PointF(0, 70));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Read the file
            FileStream file = new FileStream(dataPath + "Text1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            PdfAttachment attachment = new PdfAttachment("Text1.txt", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "About Syncfusion";

            attachment.MimeType = "application/txt";

            //Adds the attachment to the document
            doc.Attachments.Add(attachment);

            file = new FileStream(dataPath + "Autumn Leaves.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            attachment = new PdfAttachment("Autumn Leaves.jpg", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "Autumn Leaves Image";

            attachment.MimeType = "application/jpg";

            doc.Attachments.Add(attachment);

            file = new FileStream(dataPath + "Text2.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Creates an attachment
            attachment = new PdfAttachment("Text2.txt", file);

            attachment.ModificationDate = DateTime.Now;

            attachment.Description = "List of Syncfusion Control";

            attachment.MimeType = "application/txt";

            doc.Attachments.Add(attachment);

            //Set document viewerpreference.
            doc.ViewerPreferences.HideWindowUI = false;
            doc.ViewerPreferences.HideMenubar  = false;
            doc.ViewerPreferences.HideToolbar  = false;
            doc.ViewerPreferences.FitWindow    = false;
            doc.ViewerPreferences.DisplayTitle = false;
            doc.ViewerPreferences.PageMode     = PdfPageMode.UseAttachments;

            //Disable the default appearance.
            doc.Form.SetDefaultAppearance(false);

            //Create pdfbuttonfield.
            PdfButtonField openSpecificationButton = new PdfButtonField(page, "openSpecification");

            openSpecificationButton.Bounds          = new RectangleF(105, 50, 62, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Autumn Leaves.jpg";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Autumn Leaves.jpg', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            openSpecificationButton                 = new PdfButtonField(page, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(105, 70, 30, 10);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Text1.txt";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Text1.txt', nLaunch: 2 });");
            doc.Form.Fields.Add(openSpecificationButton);

            //Save the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            doc.Save(ms);

            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Close the PDF document.
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Attachments.pdf";
            return(fileStreamResult);
        }
Example #38
0
        /**
        * add a rectangle to the current stream
        *
        * @param x the x position of left edge in millipoints
        * @param y the y position of top edge in millipoints
        * @param w the width in millipoints
        * @param h the height in millipoints
        * @param stroke the stroke color/gradient
        */

        private void AddRect(int x, int y, int w, int h, PdfColor stroke) {
            CloseText();
            currentStream.Write("ET\nq\n" + stroke.getColorSpaceOut(false)
                + PdfNumber.doubleOut(x/1000f) + " " + PdfNumber.doubleOut(y/1000f) + " "
                + PdfNumber.doubleOut(w/1000f) + " " + PdfNumber.doubleOut(h/1000f) + " re s\n"
                + "Q\nBT\n");
        }