コード例 #1
0
ファイル: Text.cs プロジェクト: baitun/BGUEP-Journal
 private static void DrawHorizontalLines(PdfGraphics g, PdfPen pen, double x, double y, double width, double height)
 {
     for (double i = 0; i < height; i = i + 5)
     {
         g.DrawLine(pen, x, y + i, x + width, y + i);
     }
 }
コード例 #2
0
        private void DrawPath(PdfPageBase page)
        {
            PointF[] points = new PointF[5];
            for (int i = 0; i < points.Length; i++)
            {
                float x = (float)Math.Cos(i * 2 * Math.PI / 5);
                float y = (float)Math.Sin(i * 2 * Math.PI / 5);
                points[i] = new PointF(x, y);
            }
            PdfPath path = new PdfPath();
            path.AddLine(points[2], points[0]);
            path.AddLine(points[0], points[3]);
            path.AddLine(points[3], points[1]);
            path.AddLine(points[1], points[4]);
            path.AddLine(points[4], points[2]);

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();
            PdfPen pen = new PdfPen(Color.DeepSkyBlue, 0.02f);
            PdfBrush brush1 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.ScaleTransform(50f, 50f);
            page.Canvas.TranslateTransform(5f, 1.2f);
            page.Canvas.DrawPath(pen, path);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Alternate;
            page.Canvas.DrawPath(pen, brush1, path);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush1, path);

            PdfLinearGradientBrush brush2 = new PdfLinearGradientBrush(new PointF(-2, 0), new PointF(2, 0), Color.Red, Color.Blue);
            page.Canvas.TranslateTransform(-4f, 2f);
            path.FillMode = PdfFillMode.Alternate;
            page.Canvas.DrawPath(pen, brush2, path);

            PdfRadialGradientBrush brush3 = new PdfRadialGradientBrush(new PointF(0f, 0f), 0f, new PointF(0f, 0f), 1f, Color.Red, Color.Blue);
            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush3, path);

            PdfTilingBrush brush4 = new PdfTilingBrush(new RectangleF(0, 0, 4f, 4f));
            brush4.Graphics.DrawRectangle(brush2, 0, 0, 4f, 4f);

            page.Canvas.TranslateTransform(2f, 0f);
            path.FillMode = PdfFillMode.Winding;
            page.Canvas.DrawPath(pen, brush4, path);

            //restor graphics
            page.Canvas.Restore(state);
        }
コード例 #3
0
ファイル: SearchText.cs プロジェクト: baitun/BGUEP-Journal
        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);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream CreatePdfDocument()
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

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

            //Create font
            FileStream fontFileStream = new FileStream(ResolveApplicationPath("arial.ttf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfFont    font           = new PdfTrueTypeFont(fontFileStream, 14);

            //Read the text from text file
            FileStream   rtlText = new FileStream(ResolveApplicationPath("arabic.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader  = new StreamReader(rtlText, System.Text.Encoding.Unicode);
            string       text    = reader.ReadToEnd();

            reader.Dispose();

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfPen     pen        = new PdfPen(new PdfColor(0, 0, 0));
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

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

            format.TextDirection   = PdfTextDirection.RightToLeft;
            format.Alignment       = PdfTextAlignment.Right;
            format.ParagraphIndent = 35f;

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect, format);
            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            document.Close();
            stream.Position = 0;

            return(stream);
        }
コード例 #5
0
        /// <summary>
        /// Draws header to the document.
        /// </summary>
        private PdfPageTemplateElement AddHeader(float width, string title, string description)
        {
            RectangleF rect = new RectangleF(0, 0, width, 50);
            //Create a new instance of PdfPageTemplateElement class.
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfGraphics            g      = header.Graphics;

            //Draw the image in the Header.
            SizeF imageSize = new SizeF(110f, 27f);
            //Locating the logo on the right corner.
            PointF   imageLocation = new PointF(width - imageSize.Width - 20, (int)(rect.Height / 4));
            PdfImage img           = new PdfBitmap(@"../../Resources/syncfusion_logo.gif");

            g.DrawImage(img, imageLocation, imageSize);

            //Draw title.
            PdfFont       font  = new PdfTrueTypeFont(new Font("Helvetica", 16, FontStyle.Bold), true);
            PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(44, 71, 120));
            float         x     = (width / 2) - (font.MeasureString(title).Width) / 2;

            g.DrawString(title, font, brush, new RectangleF(x, (rect.Height / 4) + 3, font.MeasureString(title).Width, font.Height));

            //Draw description
            brush = new PdfSolidBrush(Color.Gray);
            font  = new PdfTrueTypeFont(new Font("Helvetica", 6, FontStyle.Bold), true);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom);

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

            //Draw some lines in the header
            PdfPen pen = new PdfPen(Color.DarkBlue, 0.7f);

            g.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            g.DrawLine(pen, 0, header.Height, header.Width, header.Height);

            return(header);
        }
コード例 #6
0
        private void AddHeader(PdfPage page, PdfDocument doc, string title)
        {
            RectangleF             rect   = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfFont font         = new PdfStandardFont(PdfFontFamily.Helvetica, 24);
            float   doubleHeight = font.Height * 2;

            Syncfusion.Drawing.Color activeColor = Syncfusion.Drawing.Color.FromArgb(44, 71, 120);


            //Draw the image in the Header.

            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.DarkBlue, 3f);

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

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

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

            //Draw title
            //Draw description
            header.Graphics.DrawString("                  mail: [email protected]", font, brush, new RectangleF(0, 0, header.Width, header.Height), format);
            header.Graphics.DrawString(" tel: 781 507 097", font, brush, new RectangleF(0, 0, header.Width, header.Height + 11), format);
            header.Graphics.DrawString("       785 886 491", font, brush, new RectangleF(0, 0, header.Width, header.Height + 21), format);
            brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Gray);
            font  = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

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



            //Add header template at the top.
            doc.Template.Top = header;
        }
コード例 #7
0
        public ActionResult TableFeatures(string InsideBrowser)
        {
            #region Field Definitions
            //Load product data.
            IEnumerable <Products> products = DataProvider.GetProducts(_hostingEnvironment.WebRootPath);

            //Create a new PDF standard font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
            smallFont = new PdfStandardFont(font, 5f);
            PdfFont bigFont = new PdfStandardFont(font, 16f);

            //Create a new PDF solid brush
            PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29));
            PdfBrush grayBrush   = new PdfSolidBrush(new PdfColor(170, 171, 171));

            //Create a new PDF pen
            borderPen              = new PdfPen(PdfBrushes.DarkGray, .3f);
            borderPen.LineCap      = PdfLineCap.Square;
            transparentPen         = new PdfPen(PdfBrushes.Transparent, .3f);
            transparentPen.LineCap = PdfLineCap.Square;
            # endregion
コード例 #8
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            #region Field Definitions
            //Load product data.
            IEnumerable <Products> products = DataProvider.GetProducts();

            //Create a new PDF standard font
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f);
            smallFont = new PdfStandardFont(font, 5f);
            PdfFont bigFont = new PdfStandardFont(font, 16f);

            //Create a new PDF solid brush
            PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29));
            PdfBrush grayBrush   = new PdfSolidBrush(new PdfColor(170, 171, 171));

            //Create a new PDF pen
            borderPen              = new PdfPen(PdfBrushes.DarkGray, .3f);
            borderPen.LineCap      = PdfLineCap.Square;
            transparentPen         = new PdfPen(PdfBrushes.Transparent, .3f);
            transparentPen.LineCap = PdfLineCap.Square;
            # endregion
コード例 #9
0
        private void DrawText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw text - brush
            String          text   = "Go! Turn Around! Go! Go! Go!";
            PdfPen          pen    = PdfPens.DeepSkyBlue;
            PdfSolidBrush   brush  = new PdfSolidBrush(Color.White);
            PdfStringFormat format = new PdfStringFormat();
            PdfFont         font   = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic);
            SizeF           size   = font.MeasureString(text, format);
            RectangleF      rctg
                = new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180,
                                 size.Width / 3 * 2, size.Height * 2);

            page.Canvas.DrawString(text, font, pen, brush, rctg, format);

            //restor graphics
            page.Canvas.Restore(state);
        }
コード例 #10
0
        private void Init()
        {
            string fontPath          = Path.Combine(_hostingEnvironment.WebRootPath, "fonts");
            var    fontRegularStream = File.OpenRead(Path.Combine(fontPath, "SourceSansPro-Regular.ttf"));
            var    fontItalicStream  = File.OpenRead(Path.Combine(fontPath, "SourceSansPro-Italic.ttf"));

            fontBig = new PdfTrueTypeFont(fontRegularStream, 14);

            fontNormal                = new PdfTrueTypeFont(fontRegularStream, 12);
            fontNormalBold            = new PdfTrueTypeFont(fontRegularStream, 12, PdfFontStyle.Bold);
            fontNormalItalic          = new PdfTrueTypeFont(fontItalicStream, 12);
            fontNormalItalicUnderline = new PdfTrueTypeFont(fontItalicStream, 12, PdfFontStyle.Underline);

            fontSmall                = new PdfTrueTypeFont(fontRegularStream, 10);
            fontSmallBold            = new PdfTrueTypeFont(fontRegularStream, 10, PdfFontStyle.Bold);
            fontSmallItalic          = new PdfTrueTypeFont(fontItalicStream, 10);
            fontSmallItalicUnderline = new PdfTrueTypeFont(fontItalicStream, 10, PdfFontStyle.Underline);

            brushBlack = new PdfSolidBrush(Color.FromArgb(255, 0, 0, 0));
            penGray    = new PdfPen(Color.FromArgb(128, 128, 128), 1);
        }
コード例 #11
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

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

            //Create font
            Stream  fontStream = typeof(OpenTypeFont).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.NotoSerif-Black.otf");
            PdfFont font       = new PdfTrueTypeFont(fontStream, 14);

            //Text to draw
            string text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfPen     pen        = new PdfPen(new PdfColor(0, 0, 0));
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect);

            MemoryStream stream = new MemoryStream();

            //Save the PDF dcoument.
            document.Save(stream);

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

            stream.Position = 0;

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("OpenTypeFont.pdf", "application/pdf", stream, m_context);
            }
        }
コード例 #12
0
        private void Draw(PdfGraphics g, CheckBox box)
        {
            var lineWidth = Math.Min(box.Layout.Width, box.Layout.Height) / 10.0;

            var x      = box.Layout.X;
            var y      = box.Layout.Y;
            var width  = box.Layout.Width - lineWidth;
            var height = box.Layout.Height - lineWidth;

            var shiftX = 0.0;
            var shiftY = 0.0;

            if (width > height)
            {
                shiftX = (width - height) / 2;
                width  = height;
            }

            if (width < height)
            {
                shiftY = (height - width) / 2.0;
                height = width;
            }

            shiftX += x + (lineWidth / 2);
            shiftY += y + (lineWidth / 2);

            var pen = new PdfPen(PdfBrushes.Black, (float)lineWidth);

            g.DrawRectangle(pen, (float)x, (float)y, (float)width, (float)height);

            if (box.IsChecked)
            {
                pen = new PdfPen(PdfBrushes.Black, (float)lineWidth * 1.5f);
                g.DrawLine(pen, (float)(x + width * 0.2), (float)(y + height * 0.57),
                           (float)(x + width * 0.4), (float)(y + height * 0.77));
                g.DrawLine(pen, (float)(x + width * 0.4), (float)(y + height * 0.77),
                           (float)(x + width * 0.8), (float)(y + height * 0.27));
            }
        }
コード例 #13
0
        private PdfPageTemplateElement CreateHeaderTemplate(PdfDocument doc, PdfMargins margins)
        {
            //get page size
            SizeF pageSize = doc.PageSettings.Size;

            //create a PdfPageTemplateElement object as header space
            PdfPageTemplateElement headerSpace = new PdfPageTemplateElement(pageSize.Width, margins.Top);

            headerSpace.Foreground = false;

            //declare two float variables
            float x = margins.Left;
            float y = 0;

            //draw image in header space
            //var path = Path.Combine(
            // Directory.GetCurrentDirectory(),
            // "wwwroot/images", "logo.jpg");
            //PdfImage headerImage = PdfImage.FromFile(path);
            //float width = headerImage.Width / 3;
            //float height = headerImage.Height / 3;
            //headerSpace.Graphics.DrawImage(headerImage, x, margins.Top - height - 2, width, height);

            //draw line in header space
            PdfPen pen = new PdfPen(PdfBrushes.Gray, 2);

            headerSpace.Graphics.DrawLine(pen, x, y + margins.Top - 2, pageSize.Width - x, y + margins.Top - 2);

            //draw text in header space
            PdfTrueTypeFont font       = new PdfTrueTypeFont(new Font("Impact", 25f, FontStyle.Bold));
            PdfStringFormat format     = new PdfStringFormat(PdfTextAlignment.Left);
            String          headerText = "SACRAMENT MEETING AGENDA";
            SizeF           size       = font.MeasureString(headerText, format);

            headerSpace.Graphics.DrawString(headerText, font, PdfBrushes.Gray, pageSize.Width - x - size.Width - 2, margins.Top - (size.Height + 5), format);

            //return headerSpace
            return(headerSpace);
        }
コード例 #14
0
 private void DrawPageNumber(PdfSection section, PdfMargins margin, int startNumber, int pageCount)
 {
     foreach (PdfPageBase page in section.Pages)
     {
         page.Canvas.SetTransparency(0.5f);
         PdfBrush        brush  = PdfBrushes.Black;
         PdfPen          pen    = new PdfPen(brush, 0.75f);
         PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic), true);
         PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
         format.MeasureTrailingSpaces = true;
         float space = font.Height * 0.75f;
         float x     = margin.Left;
         float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
         float y     = page.Canvas.ClientSize.Height - margin.Bottom + space;
         page.Canvas.DrawLine(pen, x, y, x + width, y);
         y = y + 1;
         String numberLabel
             = String.Format("{0} of {1}", startNumber++, pageCount);
         page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
         page.Canvas.SetTransparency(1);
     }
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: YankeeKogut/PDF
        private static void DrawPageNumber(PdfPageCollection pages, PdfMargins margin, int startNumber, int pageCount)
        {
            var brush  = PdfBrushes.Black;
            var pen    = new PdfPen(brush, 2f);
            var font   = new PdfTrueTypeFont(new Font("Arial", 9f, System.Drawing.FontStyle.Italic), true);
            var format = new PdfStringFormat(PdfTextAlignment.Right)
            {
                MeasureTrailingSpaces = true
            };
            var space = font.Height * 0.75f;
            var x     = margin.Left;

            foreach (PdfPageBase page in pages)
            {
                page.Canvas.SetTransparency(1f);
                var width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
                var y     = page.Canvas.ClientSize.Height - margin.Bottom + space;
                page.Canvas.DrawLine(pen, x, y, x + width, y);
                var numberLabel = $"{startNumber++} of {pageCount}";
                page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
            }
        }
コード例 #16
0
        public ActionResult OpenTypeFont(string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Create a new PDF document
            PdfDocument document = new PdfDocument();

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

            //Create font
            FileStream fontFileStream = new FileStream(dataPath + "NotoSerif-Black.otf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfFont    font           = new PdfTrueTypeFont(fontFileStream, 14);

            //Text to draw
            string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(new PdfColor(0, 0, 0));
            PdfPen     pen        = new PdfPen(new PdfColor(0, 0, 0));
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect);
            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            document.Close();
            stream.Position = 0;
            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "OpenTypeFont.pdf";
            return(fileStreamResult);
        }
コード例 #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document and load file from disk
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile(@"../../../../../../Data/PDFTemplate_N.pdf");

            //Get the first page
            PdfPageBase page = doc.Pages[0];

            //Define Pdf pen
            PdfPen pen = new PdfPen(Color.Gray);

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Rotate page canvas
            page.Canvas.RotateTransform(-20);

            PdfStringFormat format = new PdfStringFormat();

            format.CharacterSpacing = 5f;

            //Draw the string on page
            page.Canvas.DrawString("E-ICEBLUE", new PdfFont(PdfFontFamily.Helvetica, 45f), pen, 0, 500f, format);

            //Restore graphics
            page.Canvas.Restore(state);

            //Save the Pdf file
            string output = "FillStrokeText_out.pdf";

            doc.SaveToFile(output);
            doc.Close();

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
コード例 #18
0
        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;
        }
コード例 #19
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf");
            //Create one page
            PdfPageBase page = pdf.Pages[0];

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw line
            //Set location and size
            float x      = 95;
            float y      = 95;
            float width  = 400;
            float height = 500;

            //Create pens
            PdfPen pen  = new PdfPen(Color.Black, 0.1f);
            PdfPen pen1 = new PdfPen(Color.Red, 0.1f);

            //Draw a rectangle
            page.Canvas.DrawRectangle(pen, x, y, width, height);
            //Draw two crossed lines
            page.Canvas.DrawLine(pen1, x, y, x + width, y + height);
            page.Canvas.DrawLine(pen1, x + width, y, x, y + height);

            //Restore graphics
            page.Canvas.Restore(state);

            String result = "DrawLine_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
コード例 #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf");
            //Create one page
            PdfPageBase page = pdf.Pages[0];

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw rectangles
            int          x      = 200;
            int          y      = 300;
            int          width  = 200;
            int          height = 100;
            PdfPen       pen    = new PdfPen(Color.Black, 1f);
            PdfBrush     brush  = new PdfSolidBrush(Color.Red);
            PdfBlendMode mode   = new PdfBlendMode();

            page.Canvas.SetTransparency(0.5f, 0.5f, mode);
            page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height)));

            x = x + width / 2;
            y = y - height / 2;
            page.Canvas.SetTransparency(0.2f, 0.2f, mode);
            page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height)));

            //Restor graphics
            page.Canvas.Restore(state);

            String result = "SetRectangleTransparency_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
コード例 #21
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;
        }
コード例 #22
0
        private static void DrawAffineTransformations(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);
            PdfPen bluePen = new PdfPen(PdfRgbColor.Blue, 1);
            PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 1);

            page.Graphics.DrawString("Affine transformations", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 0, page.Height / 2, page.Width, page.Height / 2);
            page.Graphics.DrawLine(blackPen, page.Width / 2, 0, page.Width / 2, page.Height);

            page.Graphics.SaveGraphicsState();

            // Move the coordinate system in the center of the page.
            page.Graphics.TranslateTransform(page.Width / 2, page.Height / 2);

            // Draw a rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(redPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Rotate the coordinate system with 30 degrees.
            page.Graphics.RotateTransform(30);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(greenPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Scale the coordinate system with 1.5
            page.Graphics.ScaleTransform(1.5, 1.5);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(bluePen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            page.Graphics.RestoreGraphicsState();

            page.Graphics.CompressAndClose();
        }
コード例 #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf");
            //Create one page
            PdfPageBase page = pdf.Pages[0];

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw line
            //Set location and size
            float x     = 150;
            float y     = 200;
            float width = 300;

            //Create pens
            PdfPen pen = new PdfPen(Color.Red, 3f);

            //Set dash style and pattern
            pen.DashStyle   = PdfDashStyle.Dash;
            pen.DashPattern = new float[] { 1, 4, 1 };
            //Draw a rectangle
            //Draw two crossed lines
            page.Canvas.DrawLine(pen, x, y, x + width, y);

            //Restor graphics
            page.Canvas.Restore(state);

            String result = "DrawDashedLine_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
コード例 #24
0
        private static void DrawAffineTransformations(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush    = new PdfBrush();
            PdfPen   blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen   redPen   = new PdfPen(PdfRgbColor.Red, 1);
            PdfPen   bluePen  = new PdfPen(PdfRgbColor.Blue, 1);
            PdfPen   greenPen = new PdfPen(PdfRgbColor.Green, 1);

            page.Graphics.DrawString("Affine transformations", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 0, page.Height / 2, page.Width, page.Height / 2);
            page.Graphics.DrawLine(blackPen, page.Width / 2, 0, page.Width / 2, page.Height);

            page.Graphics.SaveGraphicsState();

            // Move the coordinate system in the center of the page.
            page.Graphics.TranslateTransform(page.Width / 2, page.Height / 2);

            // Draw a rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(redPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Rotate the coordinate system with 30 degrees.
            page.Graphics.RotateTransform(30);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(greenPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            // Scale the coordinate system with 1.5
            page.Graphics.ScaleTransform(1.5, 1.5);

            // Draw the same rectangle with the center at (0, 0)
            page.Graphics.DrawRectangle(bluePen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4);

            page.Graphics.RestoreGraphicsState();

            page.Graphics.CompressAndClose();
        }
コード例 #25
0
        public ActionResult OpenTypeFont(string InsideBrowser)
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();

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

            //Create font
            string  path       = ResolveApplicationDataPath("NotoSerif-Black.otf");
            Stream  fontStream = System.IO.File.OpenRead(path);
            PdfFont font       = new PdfTrueTypeFont(fontStream, 14);


            //Text to draw
            string text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            //Create a brush
            PdfBrush   brush      = new PdfSolidBrush(Color.Black);
            PdfPen     pen        = new PdfPen(Color.Black);
            SizeF      clipBounds = page.Graphics.ClientSize;
            RectangleF rect       = new RectangleF(0, 0, clipBounds.Width, clipBounds.Height);

            //Draw text.
            page.Graphics.DrawString(text, font, brush, rect);

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
コード例 #26
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();

            document.PageSettings.SetMargins(0);

            PdfFont  font  = new PdfStandardFont(PdfFontFamily.Helvetica, 10f);
            PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
            string   text  = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

            page.Graphics.DrawString("Annotation with Comments and Reviews", font, brush, new PointF(30, 10));
            page.Graphics.DrawString(text, font, brush, new RectangleF(30, 40, page.GetClientSize().Width - 60, 60));

            string markupText = "North American, European and Asian commercial markets";
            PdfTextMarkupAnnotation textMarkupAnnot = new PdfTextMarkupAnnotation("sample", "Highlight", markupText, new PointF(147, 63.5f), font);

            textMarkupAnnot.Author                   = "Annotation";
            textMarkupAnnot.Opacity                  = 1.0f;
            textMarkupAnnot.Subject                  = "Comments and Reviews";
            textMarkupAnnot.ModifiedDate             = new DateTime(2015, 1, 18);
            textMarkupAnnot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
            textMarkupAnnot.TextMarkupColor          = new PdfColor(System.Drawing.Color.Yellow);
            textMarkupAnnot.InnerColor               = new PdfColor(System.Drawing.Color.Red);
            textMarkupAnnot.Color = new PdfColor(System.Drawing.Color.Yellow);
            if (flatten.IsChecked == true)
            {
                textMarkupAnnot.Flatten = true;
            }
            //Create a new comment.
            PdfPopupAnnotation userQuery = new PdfPopupAnnotation();

            userQuery.Author       = "John";
            userQuery.Text         = "Can you please change South Asian to Asian?";
            userQuery.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userQuery);

            //Creates a new comment
            PdfPopupAnnotation userAnswer = new PdfPopupAnnotation();

            userAnswer.Author       = "Smith";
            userAnswer.Text         = "South Asian has changed as Asian";
            userAnswer.ModifiedDate = new DateTime(2015, 1, 18);
            //Add comment to the annotation
            textMarkupAnnot.Comments.Add(userAnswer);

            //Creates a new review
            PdfPopupAnnotation userAnswerReview = new PdfPopupAnnotation();

            userAnswerReview.Author       = "Smith";
            userAnswerReview.State        = PdfAnnotationState.Completed;
            userAnswerReview.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReview.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReview);

            //Creates a new review
            PdfPopupAnnotation userAnswerReviewJohn = new PdfPopupAnnotation();

            userAnswerReviewJohn.Author       = "John";
            userAnswerReviewJohn.State        = PdfAnnotationState.Accepted;
            userAnswerReviewJohn.StateModel   = PdfAnnotationStateModel.Review;
            userAnswerReviewJohn.ModifiedDate = new DateTime(2015, 1, 18);
            //Add review to the comment
            userAnswer.ReviewHistory.Add(userAnswerReviewJohn);

            //Add annotation to the page
            page.Annotations.Add(textMarkupAnnot);

            RectangleF bounds = new RectangleF(350, 170, 80, 80);

            //Creates a new Circle annotation.
            PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds);

            circleannotation.InnerColor      = new PdfColor(System.Drawing.Color.Yellow);
            circleannotation.Color           = new PdfColor(System.Drawing.Color.Red);
            circleannotation.AnnotationFlags = PdfAnnotationFlags.Default;
            circleannotation.Author          = "Syncfusion";
            circleannotation.Subject         = "CircleAnnotation";
            circleannotation.ModifiedDate    = new DateTime(2015, 1, 18);
            page.Annotations.Add(circleannotation);
            page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 130));


            //Creates a new Ellipse annotation.
            PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 150, 50, 100), "Ellipse Annotation");

            ellipseannotation.Color      = new PdfColor(System.Drawing.Color.Red);
            ellipseannotation.InnerColor = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 130));
            page.Annotations.Add(ellipseannotation);

            //Creates a new Square annotation.
            PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 300, 80, 80));

            squareannotation.Text       = "SquareAnnotation";
            squareannotation.InnerColor = new PdfColor(System.Drawing.Color.Red);
            squareannotation.Color      = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 280));
            page.Annotations.Add(squareannotation);

            //Creates a new Rectangle annotation.
            RectangleF             rectannot           = new RectangleF(350, 320, 100, 50);
            PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation");

            rectangleannotation.InnerColor = new PdfColor(System.Drawing.Color.Red);
            rectangleannotation.Color      = new PdfColor(System.Drawing.Color.Yellow);
            page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 280));
            page.Annotations.Add(rectangleannotation);

            //Creates a new Line annotation.
            int[]             points         = new int[] { 400, 350, 550, 350 };
            PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type...");

            lineAnnotation.Author       = "Syncfusion";
            lineAnnotation.Subject      = "LineAnnotation";
            lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18);
            lineAnnotation.Text         = "PdfLineAnnotation";
            lineAnnotation.BackColor    = new PdfColor(System.Drawing.Color.Red);
            page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 420));
            page.Annotations.Add(lineAnnotation);

            //Creates a new Polygon annotation.
            int[] polypoints = new int[] { 50, 298, 100, 325, 200, 355, 300, 230, 180, 230 };
            PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation");

            polygonannotation.Bounds = new RectangleF(30, 210, 300, 200);
            PdfPen pen = new PdfPen(System.Drawing.Color.Red);

            polygonannotation.Text       = "polygon";
            polygonannotation.Color      = new PdfColor(System.Drawing.Color.Red);
            polygonannotation.InnerColor = new PdfColor(System.Drawing.Color.LightPink);
            page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 420));
            page.Annotations.Add(polygonannotation);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect = new RectangleF(405, 645, 80, 30);
            PdfFreeTextAnnotation freeText     = new PdfFreeTextAnnotation(freetextrect);

            freeText.MarkupText      = "Free Text with Callouts";
            freeText.TextMarkupColor = new PdfColor(System.Drawing.Color.Green);
            freeText.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText.BorderColor     = new PdfColor(System.Drawing.Color.Blue);
            freeText.Border          = new PdfAnnotationBorder(.5f);
            freeText.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText.Text            = "Free Text";
            freeText.Color           = new PdfColor(System.Drawing.Color.Yellow);
            PointF[] Freetextpoints = { new PointF(365, 700), new PointF(379, 654), new PointF(405, 654) };
            freeText.CalloutLines = Freetextpoints;
            page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 610));
            page.Annotations.Add(freeText);

            //Creates a new Ink annotation.
            List <float> linePoints = new List <float> {
                72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f
            };
            RectangleF       rectangle     = new RectangleF(30, 580, 300, 400);
            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints);

            inkAnnotation.Bounds = rectangle;
            inkAnnotation.Color  = new PdfColor(System.Drawing.Color.Red);
            page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610));
            page.Annotations.Add(inkAnnotation);

            PdfPage secondPage = document.Pages.Add();


            //Creates a new TextMarkup annotation.
            string s = "This is TextMarkup annotation!!!";

            secondPage.Graphics.DrawString(s, font, brush, new PointF(30, 70));
            PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Strikeout", s, new PointF(30, 70), font);

            textannot.Author                   = "Annotation";
            textannot.Opacity                  = 1.0f;
            textannot.Subject                  = "pdftextmarkupannotation";
            textannot.ModifiedDate             = new DateTime(2015, 1, 18);
            textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut;
            textannot.TextMarkupColor          = new PdfColor(System.Drawing.Color.Yellow);
            textannot.InnerColor               = new PdfColor(System.Drawing.Color.Red);
            textannot.Color = new PdfColor(System.Drawing.Color.Yellow);
            if (flatten.IsChecked == true)
            {
                textannot.Flatten = true;
            }
            secondPage.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 40));
            secondPage.Annotations.Add(textannot);

            //Creates a new popup annotation.
            RectangleF         popupRect       = new RectangleF(430, 70, 30, 30);
            PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation();

            popupAnnotation.Border.Width            = 4;
            popupAnnotation.Border.HorizontalRadius = 20;
            popupAnnotation.Border.VerticalRadius   = 30;
            popupAnnotation.Opacity    = 1;
            popupAnnotation.Open       = true;
            popupAnnotation.Text       = "Popup Annotation";
            popupAnnotation.Color      = System.Drawing.Color.Green;
            popupAnnotation.InnerColor = System.Drawing.Color.Blue;
            popupAnnotation.Bounds     = popupRect;
            if (flatten.IsChecked == true)
            {
                popupAnnotation.FlattenPopUps = true;
                popupAnnotation.Flatten       = true;
            }
            secondPage.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 40));
            secondPage.Annotations.Add(popupAnnotation);

            //Creates a new Line measurement annotation.
            points = new int[] { 400, 630, 550, 630 };
            PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points);

            lineMeasureAnnot.Author                 = "Syncfusion";
            lineMeasureAnnot.Subject                = "LineAnnotation";
            lineMeasureAnnot.ModifiedDate           = new DateTime(2015, 1, 18);
            lineMeasureAnnot.Unit                   = PdfMeasurementUnit.Inch;
            lineMeasureAnnot.lineBorder.BorderWidth = 2;
            lineMeasureAnnot.Font                   = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular);
            lineMeasureAnnot.Color                  = new PdfColor(System.Drawing.Color.Red);
            if (flatten.IsChecked == true)
            {
                lineMeasureAnnot.Flatten = true;
            }
            secondPage.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 130));
            secondPage.Annotations.Add(lineMeasureAnnot);

            //Creates a new Freetext annotation.
            RectangleF            freetextrect0 = new RectangleF(80, 160, 100, 50);
            PdfFreeTextAnnotation freeText0     = new PdfFreeTextAnnotation(freetextrect0);

            freeText0.MarkupText      = "Free Text with Callouts";
            freeText0.TextMarkupColor = new PdfColor(System.Drawing.Color.Green);
            freeText0.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
            freeText0.BorderColor     = new PdfColor(System.Drawing.Color.Blue);
            freeText0.Border          = new PdfAnnotationBorder(.5f);
            freeText0.AnnotationFlags = PdfAnnotationFlags.Default;
            freeText0.Text            = "Free Text";
            freeText0.Rotate          = PdfAnnotationRotateAngle.RotateAngle90;
            freeText0.Color           = new PdfColor(System.Drawing.Color.Yellow);
            PointF[] Freetextpoints0 = { new PointF(45, 220), new PointF(60, 175), new PointF(80, 175) };
            freeText0.CalloutLines = Freetextpoints0;
            secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 130));
            if (flatten.IsChecked == true)
            {
                freeText0.Flatten = true;
            }
            secondPage.Annotations.Add(freeText0);

            PdfRectangleAnnotation cloudannotation = new PdfRectangleAnnotation(new RectangleF(30, 300, 100, 50), "Rectangle Cloud Annoatation");

            cloudannotation.Border.BorderWidth = 1;
            cloudannotation.Color      = System.Drawing.Color.Red;
            cloudannotation.InnerColor = System.Drawing.Color.Blue;
            PdfBorderEffect bordereffect = new PdfBorderEffect();

            bordereffect.Intensity       = 2;
            bordereffect.Style           = PdfBorderEffectStyle.Cloudy;
            cloudannotation.BorderEffect = bordereffect;
            secondPage.Graphics.DrawString("Cloud Annotation", font, brush, new PointF(40, 260));
            secondPage.Annotations.Add(cloudannotation);
            if (flatten.IsChecked == false)
            {
                PdfRedactionAnnotation redactionannot = new PdfRedactionAnnotation();
                redactionannot.Bounds        = new RectangleF(350, 300, 100, 50);
                redactionannot.Text          = "Redaction Annotation";
                redactionannot.InnerColor    = System.Drawing.Color.Orange;
                redactionannot.BorderColor   = System.Drawing.Color.Red;
                redactionannot.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 13);
                redactionannot.TextColor     = System.Drawing.Color.Green;
                redactionannot.OverlayText   = "REDACTED";
                redactionannot.RepeatText    = true;
                redactionannot.TextAlignment = PdfTextAlignment.Left;
                redactionannot.SetAppearance(true);
                secondPage.Graphics.DrawString("Redaction Annotation", font, brush, new PointF(350, 260));
                secondPage.Annotations.Add(redactionannot);
            }
            //Saving the document
            MemoryStream SourceStream = new MemoryStream();

            document.Save(SourceStream);
            document.Close(true);

            //Loading and flatten the  annotation
            PdfLoadedDocument lDoc   = new PdfLoadedDocument(SourceStream);
            PdfLoadedPage     lpage1 = lDoc.Pages[0] as PdfLoadedPage;
            PdfLoadedPage     lpage2 = lDoc.Pages[1] as PdfLoadedPage;

            if (flatten.IsChecked == true)
            {
                lpage1.Annotations.Flatten = true;
                lpage2.Annotations.Flatten = true;
            }
            MemoryStream stream = new MemoryStream();
            await lDoc.SaveAsync(stream);

            lDoc.Close(true);

            Save(stream, "Sample.pdf");
        }
コード例 #27
0
ファイル: Creator.cs プロジェクト: banzaiiiiii/PdfCreator
 public void setPen(float penWidth)
 {
     pen = new PdfPen(Color.Black, penWidth);
 }
コード例 #28
0
        private static void DrawPatterns(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfPen darkRedPen = new PdfPen(new PdfRgbColor(0xFF, 0x40, 0x40), 0.8);
            PdfPen darkOrangePen = new PdfPen(new PdfRgbColor(0xA6, 0x4B, 0x00), 0.8);
            PdfPen darkCyanPen = new PdfPen(new PdfRgbColor(0x00, 0x63, 0x63), 0.8);
            PdfPen darkGreenPen = new PdfPen(new PdfRgbColor(0x00, 0x85, 0x00), 0.8);
            PdfBrush lightRedBrush = new PdfBrush(new PdfRgbColor(0xFF, 0x73, 0x73));
            PdfBrush lightOrangeBrush = new PdfBrush(new PdfRgbColor(0xFF, 0x96, 0x40));
            PdfBrush lightCyanBrush = new PdfBrush(new PdfRgbColor(0x33, 0xCC, 0xCC));
            PdfBrush lightGreenBrush = new PdfBrush(new PdfRgbColor(0x67, 0xE6, 0x67));

            page.Graphics.DrawString("Patterns", titleFont, brush, 20, 50);

            page.Graphics.DrawString("Colored patterns", sectionFont, brush, 25, 70);

            // Create the pattern visual appearance.
            PdfColoredTilingPattern ctp = new PdfColoredTilingPattern(20, 20);
            // Red circle
            ctp.Graphics.DrawEllipse(darkRedPen, lightRedBrush, 1, 1, 8, 8);
            // Cyan square
            ctp.Graphics.DrawRectangle(darkCyanPen, lightCyanBrush, 11, 1, 8, 8);
            // Green diamond
            PdfPath diamondPath = new PdfPath();
            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            ctp.Graphics.DrawPath(darkGreenPen, lightGreenBrush, diamondPath);
            // Orange triangle
            PdfPath trianglePath = new PdfPath();
            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            ctp.Graphics.DrawPath(darkOrangePen, lightOrangeBrush, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace coloredPatternColorSpace = new PdfPatternColorSpace(ctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor coloredPatternColor = new PdfPatternColor(coloredPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            PdfPatternBrush patternBrush = new PdfPatternBrush(coloredPatternColor);
            PdfPatternPen patternPen = new PdfPatternPen(coloredPatternColor, 40);

            page.Graphics.DrawEllipse(patternBrush, 25, 90, 250, 200);
            page.Graphics.DrawRoundRectangle(patternPen, 310, 110, 250, 160, 100, 100);

            page.Graphics.DrawString("Uncolored patterns", sectionFont, brush, 25, 300);

            // Create the pattern visual appearance.
            PdfUncoloredTilingPattern uctp = new PdfUncoloredTilingPattern(20, 20);
            // A pen without color is used to create the pattern content.
            PdfPen noColorPen = new PdfPen(null, 0.8);
            // Circle
            uctp.Graphics.DrawEllipse(noColorPen, 1, 1, 8, 8);
            // Square
            uctp.Graphics.DrawRectangle(noColorPen, 11, 1, 8, 8);
            // Diamond
            diamondPath = new PdfPath();
            diamondPath.StartSubpath(1, 15);
            diamondPath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(5, 11), new PdfPoint(9, 15), new PdfPoint(5, 19) });
            diamondPath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, diamondPath);
            // Triangle
            trianglePath = new PdfPath();
            trianglePath.StartSubpath(11, 19);
            trianglePath.AddPolyLineTo(new PdfPoint[] { new PdfPoint(15, 11), new PdfPoint(19, 19) });
            trianglePath.CloseSubpath();
            uctp.Graphics.DrawPath(noColorPen, trianglePath);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace uncoloredPatternColorSpace = new PdfPatternColorSpace(uctp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor uncoloredPatternColor = new PdfPatternColor(uncoloredPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            patternBrush = new PdfPatternBrush(uncoloredPatternColor);

            // Before using the uncolored pattern set the color that will be used to paint the pattern.
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xFF, 0x40, 0x40);
            page.Graphics.DrawEllipse(patternBrush, 25, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0xA6, 0x4B, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 175, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x63, 0x63);
            page.Graphics.DrawEllipse(patternBrush, 325, 320, 125, 200);
            patternBrush.UncoloredPatternPaintColor = new PdfRgbColor(0x00, 0x85, 0x00);
            page.Graphics.DrawEllipse(patternBrush, 475, 320, 125, 200);

            page.Graphics.DrawString("Shading patterns", sectionFont, brush, 25, 550);

            // Create the pattern visual appearance.
            PdfAxialShading horizontalShading = new PdfAxialShading();
            horizontalShading.StartColor = new PdfRgbColor(255, 0, 0);
            horizontalShading.EndColor = new PdfRgbColor(0, 0, 255);
            horizontalShading.StartPoint = new PdfPoint(25, 600);
            horizontalShading.EndPoint = new PdfPoint(575, 600);
            PdfShadingPattern sp = new PdfShadingPattern(horizontalShading);

            // Create a pattern colorspace from the pattern object.
            PdfPatternColorSpace shadingPatternColorSpace = new PdfPatternColorSpace(sp);
            // Create a color based on the pattern colorspace.
            PdfPatternColor shadingPatternColor = new PdfPatternColor(shadingPatternColorSpace);
            // The pen and brush use the pattern color like any other color.
            patternPen = new PdfPatternPen(shadingPatternColor, 40);

            page.Graphics.DrawEllipse(patternPen, 50, 600, 500, 150);

            page.Graphics.CompressAndClose();
        }
コード例 #29
0
ファイル: Annotations.cs プロジェクト: littlefeihu/checktask
        private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            page.Rotation = 90;

            page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            Pdf3DView view0 = new Pdf3DView();

            view0.CameraToWorldMatrix    = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit          = 0.123106;
            view0.ExternalName           = "Default";
            view0.InternalName           = "Default";
            view0.Projection             = new Pdf3DProjection();
            view0.Projection.FieldOfView = 30;

            Pdf3DView view1 = new Pdf3DView();

            view1.CameraToWorldMatrix    = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit          = 0.123106;
            view1.ExternalName           = "Top";
            view1.InternalName           = "Top";
            view1.Projection             = new Pdf3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            Pdf3DView view2 = new Pdf3DView();

            view2.CameraToWorldMatrix    = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit          = 0.123106;
            view2.ExternalName           = "Side";
            view2.InternalName           = "Side";
            view2.Projection             = new Pdf3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            Pdf3DView view3 = new Pdf3DView();

            view3.CameraToWorldMatrix    = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit          = 0.123106;
            view3.ExternalName           = "Isometric";
            view3.InternalName           = "Isometric";
            view3.Projection             = new Pdf3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            Pdf3DView view4 = new Pdf3DView();

            view4.CameraToWorldMatrix    = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit          = 0.123106;
            view4.ExternalName           = "Front";
            view4.InternalName           = "Front";
            view4.Projection             = new Pdf3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            Pdf3DView view5 = new Pdf3DView();

            view5.CameraToWorldMatrix    = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit          = 0.123106;
            view5.ExternalName           = "Back";
            view5.InternalName           = "Back";
            view5.Projection             = new Pdf3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            Pdf3DStream _3dStream = new Pdf3DStream();

            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content          = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            Pdf3DAnnotation _3da = new Pdf3DAnnotation();

            _3da.Stream = _3dStream;

            PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200);

            appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Font  = font;
            sao.Brush = blackBrush;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);

            page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Graphics.DrawString("Top", sao, slo);

            PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction();

            gotoTopView.ViewIndex        = 1;
            gotoTopView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18);
            linkGotoTopView.Action          = gotoTopView;

            page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Graphics.DrawString("Side", sao, slo);

            PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction();

            gotoSideView.ViewIndex        = 2;
            gotoSideView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18);
            linkGotoSideView.Action          = gotoSideView;

            page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Graphics.DrawString("Isometric", sao, slo);

            PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction();

            gotoIsometricView.ViewIndex        = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action          = gotoIsometricView;

            page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Graphics.DrawString("Front", sao, slo);

            PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction();

            gotoFrontView.ViewIndex        = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action          = gotoFrontView;

            page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Graphics.DrawString("Back", sao, slo);

            PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction();

            gotoBackView.ViewIndex        = 5;
            gotoBackView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation();

            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18);
            linkGotoBackView.Action          = gotoBackView;
        }
コード例 #30
0
ファイル: Annotations.cs プロジェクト: baitun/BGUEP-Journal
        private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();
            page.Rotation = 90;

            page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            Pdf3DView view0 = new Pdf3DView();
            view0.CameraToWorldMatrix = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit = 0.123106;
            view0.ExternalName = "Default";
            view0.InternalName = "Default";
            view0.Projection = new Pdf3DProjection();
            view0.Projection.FieldOfView = 30;

            Pdf3DView view1 = new Pdf3DView();
            view1.CameraToWorldMatrix = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit = 0.123106;
            view1.ExternalName = "Top";
            view1.InternalName = "Top";
            view1.Projection = new Pdf3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            Pdf3DView view2 = new Pdf3DView();
            view2.CameraToWorldMatrix = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit = 0.123106;
            view2.ExternalName = "Side";
            view2.InternalName = "Side";
            view2.Projection = new Pdf3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            Pdf3DView view3 = new Pdf3DView();
            view3.CameraToWorldMatrix = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit = 0.123106;
            view3.ExternalName = "Isometric";
            view3.InternalName = "Isometric";
            view3.Projection = new Pdf3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            Pdf3DView view4 = new Pdf3DView();
            view4.CameraToWorldMatrix = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit = 0.123106;
            view4.ExternalName = "Front";
            view4.InternalName = "Front";
            view4.Projection = new Pdf3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            Pdf3DView view5 = new Pdf3DView();
            view5.CameraToWorldMatrix = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit = 0.123106;
            view5.ExternalName = "Back";
            view5.InternalName = "Back";
            view5.Projection = new Pdf3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            Pdf3DStream _3dStream = new Pdf3DStream();
            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            Pdf3DAnnotation _3da = new Pdf3DAnnotation();
            _3da.Stream = _3dStream;

            PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200);
            appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Font = font;
            sao.Brush = blackBrush;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);

            page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Graphics.DrawString("Top", sao, slo);

            PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction();
            gotoTopView.ViewIndex = 1;
            gotoTopView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18);
            linkGotoTopView.Action = gotoTopView;

            page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Graphics.DrawString("Side", sao, slo);

            PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction();
            gotoSideView.ViewIndex = 2;
            gotoSideView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18);
            linkGotoSideView.Action = gotoSideView;

            page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Graphics.DrawString("Isometric", sao, slo);

            PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction();
            gotoIsometricView.ViewIndex = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action = gotoIsometricView;

            page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Graphics.DrawString("Front", sao, slo);

            PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction();
            gotoFrontView.ViewIndex = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action = gotoFrontView;

            page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Graphics.DrawString("Back", sao, slo);

            PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction();
            gotoBackView.ViewIndex = 5;
            gotoBackView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18);
            linkGotoBackView.Action = gotoBackView;
        }
コード例 #31
0
ファイル: Form1.cs プロジェクト: e-iceblue/Spire.PDF-for-.NET
 private float DrawFormSection(String label, PdfPageBase page, float y)
 {
     PdfBrush brush1 = PdfBrushes.LightYellow;
     PdfBrush brush2 = PdfBrushes.DarkSlateGray;
     PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
     PdfStringFormat format = new PdfStringFormat();
     float height = font.MeasureString(label).Height;
     page.Canvas.DrawRectangle(brush2, 0, y, page.Canvas.ClientSize.Width, height + 2);
     page.Canvas.DrawString(label, font, brush1, 2, y + 1);
     y = y + height + 2;
     PdfPen pen = new PdfPen(PdfBrushes.LightSkyBlue, 0.75f);
     page.Canvas.DrawLine(pen, 0, y, page.Canvas.ClientSize.Width, y);
     return y + 0.75f;
 }
コード例 #32
0
        private static void DrawArcsAndPies(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Arcs", titleFont, brush, 20, 50);
            page.Graphics.DrawString("Pies", titleFont, brush, 310, 50);

            page.Graphics.DrawLine(blackPen, 20, 210, 300, 210);
            page.Graphics.DrawLine(blackPen, 160, 70, 160, 350);
            page.Graphics.DrawLine(blackPen, 310, 210, 590, 210);
            page.Graphics.DrawLine(blackPen, 450, 70, 450, 350);

            blackPen.DashPattern = new double[] { 2, 2 };
            page.Graphics.DrawLine(blackPen, 20, 70, 300, 350);
            page.Graphics.DrawLine(blackPen, 20, 350, 300, 70);
            page.Graphics.DrawLine(blackPen, 310, 70, 590, 350);
            page.Graphics.DrawLine(blackPen, 310, 350, 590, 70);

            page.Graphics.DrawArc(redPen, 30, 80, 260, 260, 0, 135);
            page.Graphics.DrawPie(redPen, 320, 80, 260, 260, 45, 270);

            page.Graphics.DrawString("Random arcs and pies clipped to view", sectionFont, brush, 20, 385);
            PdfPath rectPath = new PdfPath();
            rectPath.AddRectangle(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(rectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int mode = rnd.Next(4);
                double left = rnd.NextDouble() * page.Width;
                double top = 380 + rnd.NextDouble() * 350;
                double width = rnd.NextDouble() * page.Width;
                double height = rnd.NextDouble() * 250;
                double startAngle = rnd.Next(360);
                double sweepAngle = rnd.Next(360);
                switch (mode)
                {
                    case 0:
                        // Stroke arc outline
                        page.Graphics.DrawArc(randomPen, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 1:
                        // Stroke pie outline
                        page.Graphics.DrawPie(randomPen, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 2:
                        // Fill pie interior
                        page.Graphics.DrawPie(randomBrush, left, top, width, height, startAngle, sweepAngle);
                        break;
                    case 3:
                        // Stroke and fill pie
                        page.Graphics.DrawPie(randomPen, randomBrush, left, top, width, height, startAngle, sweepAngle);
                        break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            blackPen.DashPattern = null;
            page.Graphics.DrawPath(blackPen, rectPath);

            page.Graphics.CompressAndClose();
        }
コード例 #33
0
ファイル: Annotations.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateRubberStampAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] rubberStampAnnotationNames = new string[]
                {
                    "Approved", "AsIs", "Confidential", "Departmental", "Draft", "Experimental", "Expired", "Final",
                    "ForComment", "ForPublicRelease", "NotApproved", "NotForPublicRelease", "Sold", "TopSecret"
                };

            page.Graphics.DrawString("Rubber stamp annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < rubberStampAnnotationNames.Length; i++)
            {
                PdfRubberStampAnnotation rsa = new PdfRubberStampAnnotation();
                rsa.Author = "Xfinium.Pdf";
                rsa.Contents = "I am a " + rubberStampAnnotationNames[i] + " rubber stamp annotation.";
                rsa.StampName = rubberStampAnnotationNames[i];
                page.Annotations.Add(rsa);
                rsa.VisualRectangle = new PdfVisualRectangle(50, 70 + 50 * i, 200, 40);
                page.Graphics.DrawString(rubberStampAnnotationNames[i], font, blackBrush, 270, 85 + 50 * i);
            }

            page.Graphics.DrawString("Stamp annotations with custom appearance", font, blackBrush, 350, 50);
            PdfRubberStampAnnotation customRubberStampAnnotation = new PdfRubberStampAnnotation();
            customRubberStampAnnotation.Contents = "Rubber stamp annotation with custom appearance.";
            customRubberStampAnnotation.StampName = "Custom";
            page.Annotations.Add(customRubberStampAnnotation);
            customRubberStampAnnotation.VisualRectangle = new PdfVisualRectangle(350, 70, 200, 40);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customRubberStampAnnotation.NormalAppearance = customAppearance;
        }
コード例 #34
0
        private static void DrawColorsAndColorSpaces(PdfPage page, PdfFont titleFont, PdfFont sectionFont, Stream iccStream)
        {
            PdfBrush brush = new PdfBrush();

            page.Graphics.DrawString("Colors and colorspaces", titleFont, brush, 20, 50);

            page.Graphics.DrawString("DeviceRGB", sectionFont, brush, 20, 70);
            PdfPen rgbPen = new PdfPen(PdfRgbColor.DarkRed, 4);
            PdfBrush rgbBrush = new PdfBrush(PdfRgbColor.LightGoldenrodYellow);
            page.Graphics.DrawRectangle(rgbPen, rgbBrush, 20, 85, 250, 100);

            page.Graphics.DrawString("DeviceCMYK", sectionFont, brush, 340, 70);
            PdfPen cmykPen = new PdfPen(new PdfCmykColor(1, 0.5, 0, 0.1), 4);
            PdfBrush cmykBrush = new PdfBrush(new PdfCmykColor(0, 0.5, 0.43, 0));
            page.Graphics.DrawRectangle(cmykPen, cmykBrush, 340, 85, 250, 100);

            page.Graphics.DrawString("DeviceGray", sectionFont, brush, 20, 200);
            PdfPen grayPen = new PdfPen(new PdfGrayColor(0.1), 4);
            PdfBrush grayBrush = new PdfBrush(new PdfGrayColor(0.75));
            page.Graphics.DrawRectangle(grayPen, grayBrush, 20, 215, 250, 100);

            page.Graphics.DrawString("Indexed", sectionFont, brush, 340, 200);
            PdfIndexedColorSpace indexedColorSpace = new PdfIndexedColorSpace();
            indexedColorSpace.ColorCount = 2;
            indexedColorSpace.BaseColorSpace = new PdfRgbColorSpace();
            indexedColorSpace.ColorTable = new byte[] { 192, 0, 0, 0, 0, 128 };
            PdfIndexedColor indexedColor0 = new PdfIndexedColor(indexedColorSpace);
            indexedColor0.ColorIndex = 0;
            PdfIndexedColor indexedColor1 = new PdfIndexedColor(indexedColorSpace);
            indexedColor1.ColorIndex = 1;
            PdfPen indexedPen = new PdfPen(indexedColor0, 4);
            PdfBrush indexedBrush = new PdfBrush(indexedColor1);
            page.Graphics.DrawRectangle(indexedPen, indexedBrush, 340, 215, 250, 100);

            page.Graphics.DrawString("CalGray", sectionFont, brush, 20, 330);
            PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace();
            PdfCalGrayColor calGrayColor1 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor1.Gray = 0.6;
            PdfCalGrayColor calGrayColor2 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor2.Gray = 0.2;
            PdfPen calGrayPen = new PdfPen(calGrayColor1, 4);
            PdfBrush calGrayBrush = new PdfBrush(calGrayColor2);
            page.Graphics.DrawRectangle(calGrayPen, calGrayBrush, 20, 345, 250, 100);

            page.Graphics.DrawString("CalRGB", sectionFont, brush, 340, 330);
            PdfCalRgbColorSpace calRgbColorSpace = new PdfCalRgbColorSpace();
            PdfCalRgbColor calRgbColor1 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor1.Red = 0.1;
            calRgbColor1.Green = 0.5;
            calRgbColor1.Blue = 0.25;
            PdfCalRgbColor calRgbColor2 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor2.Red = 0.6;
            calRgbColor2.Green = 0.1;
            calRgbColor2.Blue = 0.9;
            PdfPen calRgbPen = new PdfPen(calRgbColor1, 4);
            PdfBrush calRgbBrush = new PdfBrush(calRgbColor2);
            page.Graphics.DrawRectangle(calRgbPen, calRgbBrush, 340, 345, 250, 100);

            page.Graphics.DrawString("L*a*b", sectionFont, brush, 20, 460);
            PdfLabColorSpace labColorSpace = new PdfLabColorSpace();
            PdfLabColor labColor1 = new PdfLabColor(labColorSpace);
            labColor1.L = 90;
            labColor1.A = -40;
            labColor1.B = 120;
            PdfLabColor labColor2 = new PdfLabColor(labColorSpace);
            labColor2.L = 45;
            labColor2.A = 90;
            labColor2.B = -34;
            PdfPen labPen = new PdfPen(labColor1, 4);
            PdfBrush labBrush = new PdfBrush(labColor2);
            page.Graphics.DrawRectangle(labPen, labBrush, 20, 475, 250, 100);

            page.Graphics.DrawString("Icc", sectionFont, brush, 340, 460);
            PdfIccColorSpace iccColorSpace = new PdfIccColorSpace();
            byte[] iccData = new byte[iccStream.Length];
            iccStream.Read(iccData, 0, iccData.Length);
            iccColorSpace.IccProfile = iccData;
            iccColorSpace.AlternateColorSpace = new PdfRgbColorSpace();
            iccColorSpace.ColorComponents = 3;
            PdfIccColor iccColor1 = new PdfIccColor(iccColorSpace);
            iccColor1.ColorComponents = new double[] { 0.45, 0.1, 0.22 };
            PdfIccColor iccColor2 = new PdfIccColor(iccColorSpace);
            iccColor2.ColorComponents = new double[] { 0.21, 0.76, 0.31 };
            PdfPen iccPen = new PdfPen(iccColor1, 4);
            PdfBrush iccBrush = new PdfBrush(iccColor2);
            page.Graphics.DrawRectangle(iccPen, iccBrush, 340, 475, 250, 100);

            page.Graphics.DrawString("Separation", sectionFont, brush, 20, 590);
            PdfExponentialFunction tintTransform = new PdfExponentialFunction();
            tintTransform.Domain = new double[] { 0, 1 };
            tintTransform.Range = new double[] { 0, 1, 0, 1, 0, 1, 0, 1 };
            tintTransform.Exponent = 1;
            tintTransform.C0 = new double[] { 0, 0, 0, 0 };
            tintTransform.C1 = new double[] { 1, 0.5, 0, 0.1 };

            PdfSeparationColorSpace separationColorSpace = new PdfSeparationColorSpace();
            separationColorSpace.AlternateColorSpace = new PdfCmykColorSpace();
            separationColorSpace.Colorant = "Custom Blue";
            separationColorSpace.TintTransform = tintTransform;

            PdfSeparationColor separationColor1 = new PdfSeparationColor(separationColorSpace);
            separationColor1.Tint = 0.23;
            PdfSeparationColor separationColor2 = new PdfSeparationColor(separationColorSpace);
            separationColor2.Tint = 0.74;

            PdfPen separationPen = new PdfPen(separationColor1, 4);
            PdfBrush separationBrush = new PdfBrush(separationColor2);
            page.Graphics.DrawRectangle(separationPen, separationBrush, 20, 605, 250, 100);

            page.Graphics.DrawString("Pantone", sectionFont, brush, 340, 590);
            PdfPen pantonePen = new PdfPen(PdfPantoneColor.ReflexBlue, 4);
            PdfBrush pantoneBrush = new PdfBrush(PdfPantoneColor.RhodamineRed);
            page.Graphics.DrawRectangle(pantonePen, pantoneBrush, 340, 605, 250, 100);

            page.Graphics.CompressAndClose();
        }
コード例 #35
0
        private static void DrawBezierCurves(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);
            PdfBrush blueBrush = new PdfBrush(PdfRgbColor.DarkBlue);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);

            page.Graphics.DrawString("Bezier curves", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 20, 210, 600, 210);
            page.Graphics.DrawLine(blackPen, 306, 70, 306, 350);
            page.Graphics.DrawRectangle(blueBrush, 39, 339, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 279, 79, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 499, 299, 2, 2);
            page.Graphics.DrawRectangle(blueBrush, 589, 69, 2, 2);
            page.Graphics.DrawBezier(redPen, 40, 340, 280, 80, 500, 300, 590, 70);

            page.Graphics.DrawString("Random bezier curves clipped to view", sectionFont, brush, 20, 385);
            PdfPath rectPath = new PdfPath();
            rectPath.AddRectangle(20, 400, 570, 300);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(rectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                double x1 = rnd.NextDouble() * page.Width;
                double y1 = 380 + rnd.NextDouble() * 350;
                double x2 = rnd.NextDouble() * page.Width;
                double y2 = 380 + rnd.NextDouble() * 350;
                double x3 = rnd.NextDouble() * page.Width;
                double y3 = 380 + rnd.NextDouble() * 350;
                double x4 = rnd.NextDouble() * page.Width;
                double y4 = 380 + rnd.NextDouble() * 350;

                page.Graphics.DrawBezier(randomPen, x1, y1, x2, y2, x3, y3, x4, y4);
            }

            page.Graphics.RestoreGraphicsState();

            blackPen.DashPattern = null;
            page.Graphics.DrawPath(blackPen, rectPath);

            page.Graphics.CompressAndClose();
        }
コード例 #36
0
ファイル: Type3Fonts.cs プロジェクト: baitun/BGUEP-Journal
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfPage page = document.Pages.Add();

            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 20);
            PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black);
            page.Graphics.DrawString("The digits below, from 0 to 9, are drawn using a Type3 font.", helvetica, blackBrush, 50, 100);

            PdfType3Font t3 = new PdfType3Font("DemoT3");
            t3.Size = 24;
            t3.FirstChar = (byte)' ';
            t3.LastChar = (byte)'9';
            t3.FontMatrix = new PdfMatrix(0.01, 0, 0, 0.01, 0, 0);
            double[] widths = new double[] { 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };
            t3.Widths = widths;

            PdfPen hollowPen = new PdfPen(null, 8);
            PdfBrush hollowBrush = new PdfBrush(null);
            // space
            PdfType3Glyph t3s = new PdfType3Glyph(0x20, new PdfSize(100, 100));
            t3.Glyphs.Add(t3s);
            // 0
            PdfType3Glyph t30 = new PdfType3Glyph(0x30, new PdfSize(100, 100));
            t30.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t30.Graphics.CompressAndClose();
            t3.Glyphs.Add(t30);
            // 1
            PdfType3Glyph t31 = new PdfType3Glyph(0x31, new PdfSize(100, 100));
            t31.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t31.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20);
            t31.Graphics.CompressAndClose();
            t3.Glyphs.Add(t31);
            // 2
            PdfType3Glyph t32 = new PdfType3Glyph(0x32, new PdfSize(100, 100));
            t32.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t32.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t32.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t32.Graphics.CompressAndClose();
            t3.Glyphs.Add(t32);
            // 3
            PdfType3Glyph t33 = new PdfType3Glyph(0x33, new PdfSize(100, 100));
            t33.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t33.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t33.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20);
            t33.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t33.Graphics.CompressAndClose();
            t3.Glyphs.Add(t33);
            // 4
            PdfType3Glyph t34 = new PdfType3Glyph(0x34, new PdfSize(100, 100));
            t34.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t34.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t34.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t34.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t34.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t34.Graphics.CompressAndClose();
            t3.Glyphs.Add(t34);
            // 5
            PdfType3Glyph t35 = new PdfType3Glyph(0x35, new PdfSize(100, 100));
            t35.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t35.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t35.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t35.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20);
            t35.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t35.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t35.Graphics.CompressAndClose();
            t3.Glyphs.Add(t35);
            // 6
            PdfType3Glyph t36 = new PdfType3Glyph(0x36, new PdfSize(100, 100));
            t36.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t36.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t36.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t36.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20);
            t36.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20);
            t36.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t36.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t36.Graphics.CompressAndClose();
            t3.Glyphs.Add(t36);
            // 7
            PdfType3Glyph t37 = new PdfType3Glyph(0x37, new PdfSize(100, 100));
            t37.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t37.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t37.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t37.Graphics.CompressAndClose();
            t3.Glyphs.Add(t37);
            // 8
            PdfType3Glyph t38 = new PdfType3Glyph(0x38, new PdfSize(100, 100));
            t38.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t38.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 40, 15, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 40, 65, 20, 20);
            t38.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t38.Graphics.CompressAndClose();
            t3.Glyphs.Add(t38);
            // 9
            PdfType3Glyph t39 = new PdfType3Glyph(0x39, new PdfSize(100, 100));
            t39.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90);
            t39.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 40, 15, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 40, 65, 20, 20);
            t39.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20);
            t39.Graphics.CompressAndClose();
            t3.Glyphs.Add(t39);

            PdfBrush paleVioletRedbrush = new PdfBrush(PdfRgbColor.PaleVioletRed);
            page.Graphics.DrawString("0 1 2 3 4 5 6 7 8 9", t3, paleVioletRedbrush, 50, 150);
            PdfBrush midnightBluebrush = new PdfBrush(PdfRgbColor.MidnightBlue);
            page.Graphics.DrawString("0 1 2 3 4 5 6 7 8 9", t3, midnightBluebrush, 50, 200);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.type3fonts.pdf") };
            return output;
        }
コード例 #37
0
        private static void DrawFormXObjects(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Form XObjects", titleFont, brush, 20, 50);
            page.Graphics.DrawString("Scaling", sectionFont, brush, 20, 70);

            // Create the XObject content - random rectangles
            PdfFormXObject xobject = new PdfFormXObject(300, 300);
            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                double left = rnd.NextDouble() * xobject.Width;
                double top = rnd.NextDouble() * xobject.Height;
                double width = rnd.NextDouble() * xobject.Width;
                double height = rnd.NextDouble() * xobject.Height;
                double orientation = rnd.Next(360);
                xobject.Graphics.DrawRectangle(randomPen, randomBrush, left, top, width, height, orientation);
            }

            xobject.Graphics.DrawRectangle(blackPen, 0, 0, xobject.Width, xobject.Height);
            xobject.Graphics.CompressAndClose();

            // Draw the form XObject 3 times on the page at different sizes.
            page.Graphics.DrawFormXObject(xobject, 3, 90, 100, 100);
            page.Graphics.DrawFormXObject(xobject, 106, 90, 200, 200);
            page.Graphics.DrawFormXObject(xobject, 309, 90, 300, 300);

            page.Graphics.DrawString("Flipping", sectionFont, brush, 20, 420);
            page.Graphics.DrawFormXObject(xobject, 20, 440, 150, 150);
            page.Graphics.DrawFormXObject(xobject, 200, 440, 150, 150, 0, PdfFlipDirection.VerticalFlip);
            page.Graphics.DrawFormXObject(xobject, 20, 620, 150, 150, 0, PdfFlipDirection.HorizontalFlip);
            page.Graphics.DrawFormXObject(xobject, 200, 620, 150, 150, 0, PdfFlipDirection.VerticalFlip | PdfFlipDirection.HorizontalFlip);

            page.Graphics.CompressAndClose();
        }
コード例 #38
0
        private static void DrawLines(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen bluePen = new PdfPen(PdfRgbColor.LightBlue, 16);

            page.Graphics.DrawString("Lines", titleFont, brush, 20, 50);

            page.Graphics.DrawString("Line styles:", sectionFont, brush, 20, 70);
            page.Graphics.DrawString("Solid", sectionFont, brush, 20, 90);
            page.Graphics.DrawLine(blackPen, 100, 95, 400, 95);
            page.Graphics.DrawString("Dashed", sectionFont, brush, 20, 110);
            blackPen.DashPattern = new double[] { 3, 3 };
            page.Graphics.DrawLine(blackPen, 100, 115, 400, 115);

            page.Graphics.DrawString("Line cap styles:", sectionFont, brush, 20, 150);
            page.Graphics.DrawString("Flat", sectionFont, brush, 20, 175);
            page.Graphics.DrawLine(bluePen, 100, 180, 400, 180);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 180, 400, 180);
            page.Graphics.DrawString("Square", sectionFont, brush, 20, 195);
            bluePen.LineCap = PdfLineCap.Square;
            page.Graphics.DrawLine(bluePen, 100, 200, 400, 200);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 200, 400, 200);
            page.Graphics.DrawString("Round", sectionFont, brush, 20, 215);
            bluePen.LineCap = PdfLineCap.Round;
            page.Graphics.DrawLine(bluePen, 100, 220, 400, 220);
            blackPen.DashPattern = null;
            page.Graphics.DrawLine(blackPen, 100, 220, 400, 220);

            page.Graphics.DrawString("Line join styles:", sectionFont, brush, 20, 250);
            page.Graphics.DrawString("Miter", sectionFont, brush, 20, 280);
            PdfPath miterPath = new PdfPath();
            miterPath.StartSubpath(150, 320);
            miterPath.AddLineTo(250, 260);
            miterPath.AddLineTo(350, 320);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Miter;
            page.Graphics.DrawPath(bluePen, miterPath);

            page.Graphics.DrawString("Bevel", sectionFont, brush, 20, 360);
            PdfPath bevelPath = new PdfPath();
            bevelPath.StartSubpath(150, 400);
            bevelPath.AddLineTo(250, 340);
            bevelPath.AddLineTo(350, 400);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Bevel;
            page.Graphics.DrawPath(bluePen, bevelPath);

            page.Graphics.DrawString("Round", sectionFont, brush, 20, 440);
            PdfPath roundPath = new PdfPath();
            roundPath.StartSubpath(150, 480);
            roundPath.AddLineTo(250, 420);
            roundPath.AddLineTo(350, 480);
            bluePen.LineCap = PdfLineCap.Flat;
            bluePen.LineJoin = PdfLineJoin.Round;
            page.Graphics.DrawPath(bluePen, roundPath);

            page.Graphics.DrawString("Random lines clipped to rectangle", sectionFont, brush, 20, 520);
            PdfPath clipPath = new PdfPath();
            clipPath.AddRectangle(20, 550, 570, 230);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(clipPath);

            PdfRgbColor randomColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomColor, 1);
            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomColor.R = (byte)rnd.Next(256);
                randomColor.G = (byte)rnd.Next(256);
                randomColor.B = (byte)rnd.Next(256);

                page.Graphics.DrawLine(randomPen, rnd.NextDouble() * page.Width, 550 + rnd.NextDouble() * 250, rnd.NextDouble() * page.Width, 550 + rnd.NextDouble() * 250);
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, clipPath);

            page.Graphics.CompressAndClose();
        }
コード例 #39
0
ファイル: Barcodes.cs プロジェクト: baitun/BGUEP-Journal
        private static void DrawPostAndTransportantionBarcodes(PdfPage page, PdfFont titleFont, PdfFont barcodeFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen lightGrayPen = new PdfPen(PdfRgbColor.LightGray, 0.5);

            page.Graphics.DrawString("Post and transportation barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 7; i++)
            {
                page.Graphics.DrawLine(lightGrayPen, 40, 50 + 100 * i, 570, 50 + 100 * i);
            }
            page.Graphics.DrawLine(lightGrayPen, 306, 50, 306, 750);

            string[] barcodes = new string[] { "FedEx Ground 96", "IATA 25", "Identcode", "Leitcode", "KIX", "Planet",
                "PostNet", "RM4SCC", "SCC-14", "SingaporePost", "SSCC-18", "USPS FIM", "USPS Horizontal", "USPS PIC" };
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = brush;
            sao.Font = barcodeFont;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;
            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 100 * (i / 2);

                page.Graphics.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign = -sign;
            }

            // FedEx Ground 96
            PdfFedExGround96Barcode fedexGround96Barcode = new PdfFedExGround96Barcode();
            fedexGround96Barcode.Data = "962343237687543423123";
            fedexGround96Barcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(fedexGround96Barcode, 173 - fedexGround96Barcode.Width / 2, 70);

            // IATA 25
            PdfIata25Barcode iata25Barcode = new PdfIata25Barcode();
            iata25Barcode.Data = "54366436563";
            iata25Barcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(iata25Barcode, 173 + 266 - iata25Barcode.Width / 2, 70);

            // Identcode
            PdfIdentcodeBarcode identcodeBarcode = new PdfIdentcodeBarcode();
            identcodeBarcode.Data = "12435678214";
            identcodeBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(identcodeBarcode, 173 - identcodeBarcode.Width / 2, 170);

            // Leitcode
            PdfLeitcodeBarcode leitcodeBarcode = new PdfLeitcodeBarcode();
            leitcodeBarcode.Data = "1243657687321";
            leitcodeBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(leitcodeBarcode, 173 + 266 - leitcodeBarcode.Width / 2, 170);

            // KIX
            PdfKixBarcode kixBarcode = new PdfKixBarcode();
            kixBarcode.Data = "XFINIUMPDF";
            kixBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(kixBarcode, 173 - kixBarcode.Width / 2, 270);

            // Planet
            PdfPlanetBarcode planetBarcode = new PdfPlanetBarcode();
            planetBarcode.Data = "645316643300";
            planetBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(planetBarcode, 173 + 266 - planetBarcode.Width / 2, 270);

            // PostNet
            PdfPostNetBarcode postNetBarcode = new PdfPostNetBarcode();
            postNetBarcode.Data = "04231454322";
            postNetBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(postNetBarcode, 173 - postNetBarcode.Width / 2, 370);

            // RM4SCC
            PdfRm4sccBarcode rm4sccBarcode = new PdfRm4sccBarcode();
            rm4sccBarcode.Data = "XFINIUMPDF";
            rm4sccBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(rm4sccBarcode, 173 + 266 - rm4sccBarcode.Width / 2, 370);

            // SCC-14
            PdfScc14Barcode scc14Barcode = new PdfScc14Barcode();
            scc14Barcode.Data = "3255091205412";
            scc14Barcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(scc14Barcode, 173 - scc14Barcode.Width / 2, 470);

            // Singapore Post
            PdfSingaporePostBarcode singaporePostBarcode = new PdfSingaporePostBarcode();
            singaporePostBarcode.Data = "XFINIUMPDF";
            singaporePostBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(singaporePostBarcode, 173 + 266 - singaporePostBarcode.Width / 2, 470);

            // SSCC-18
            PdfSscc18Barcode sscc18Barcode = new PdfSscc18Barcode();
            sscc18Barcode.Data = "09876543219832435";
            sscc18Barcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(sscc18Barcode, 173 - sscc18Barcode.Width / 2, 570);

            // USPS FIM
            PdfUspsFimBarcode uspsFimBarcode = new PdfUspsFimBarcode();
            uspsFimBarcode.Data = "A";
            uspsFimBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(uspsFimBarcode, 173 + 266 - uspsFimBarcode.Width / 2, 570);

            // USPS Horizontal
            PdfUspsHorizontalBarcode uspsHorizontalBarcode = new PdfUspsHorizontalBarcode();
            uspsHorizontalBarcode.Data = "1111";
            uspsHorizontalBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.None;
            page.Graphics.DrawBarcode(uspsHorizontalBarcode, 173 - uspsHorizontalBarcode.Width / 2, 670);

            // USPS PIC
            PdfUspsPicBarcode uspsPicBarcode = new PdfUspsPicBarcode();
            uspsPicBarcode.Data = "914354657901234354019";
            uspsPicBarcode.BarcodeTextPosition = PdfBarcodeTextPosition.Bottom;
            page.Graphics.DrawBarcode(uspsPicBarcode, 173 + 266 - uspsPicBarcode.Width / 2, 670);

            page.Graphics.CompressAndClose();
        }
コード例 #40
0
ファイル: Actions.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateGoToActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            Random rnd = new Random();
            for (int i = 0; i < document.Pages.Count; i++)
            {
                int destinationPage = rnd.Next(document.Pages.Count);

                document.Pages[i].Graphics.DrawString("Go To actions:", font, blackBrush, 400, 240);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 260, 200, 20);
                slo.X = 500;
                slo.Y = 270;
                document.Pages[i].Graphics.DrawString("Go To page: " + (destinationPage + 1).ToString(), sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 260, 200, 20);

                // Create a GoTo action and attach it to the link.
                PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();
                pageDestination.Page = document.Pages[destinationPage];
                pageDestination.Left = 0;
                pageDestination.Top = 0;
                pageDestination.Zoom = 0; // Keep current zoom
                PdfGoToAction gotoPageAction = new PdfGoToAction();
                gotoPageAction.Destination = pageDestination;
                link.Action = gotoPageAction;
            }
        }
コード例 #41
0
        private static void DrawShadings(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Shadings", titleFont, brush, 20, 50);

            page.Graphics.DrawString("Horizontal", sectionFont, brush, 25, 70);

            PdfAxialShading horizontalShading = new PdfAxialShading();
            horizontalShading.StartColor = new PdfRgbColor(255, 0, 0);
            horizontalShading.EndColor = new PdfRgbColor(0, 0, 255);
            horizontalShading.StartPoint = new PdfPoint(25, 90);
            horizontalShading.EndPoint = new PdfPoint(175, 90);

            // Clip the shading to desired area.
            PdfPath hsArea = new PdfPath();
            hsArea.AddRectangle(25, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(hsArea);
            page.Graphics.DrawShading(horizontalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Vertical", sectionFont, brush, 225, 70);

            PdfAxialShading verticalShading = new PdfAxialShading();
            verticalShading.StartColor = new PdfRgbColor(255, 0, 0);
            verticalShading.EndColor = new PdfRgbColor(0, 0, 255);
            verticalShading.StartPoint = new PdfPoint(225, 90);
            verticalShading.EndPoint = new PdfPoint(225, 240);

            // Clip the shading to desired area.
            PdfPath vsArea = new PdfPath();
            vsArea.AddRectangle(225, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(vsArea);
            page.Graphics.DrawShading(verticalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Diagonal", sectionFont, brush, 425, 70);

            PdfAxialShading diagonalShading = new PdfAxialShading();
            diagonalShading.StartColor = new PdfRgbColor(255, 0, 0);
            diagonalShading.EndColor = new PdfRgbColor(0, 0, 255);
            diagonalShading.StartPoint = new PdfPoint(425, 90);
            diagonalShading.EndPoint = new PdfPoint(575, 240);

            // Clip the shading to desired area.
            PdfPath dsArea = new PdfPath();
            dsArea.AddRectangle(425, 90, 150, 150);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(dsArea);
            page.Graphics.DrawShading(diagonalShading);
            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawString("Extended shading", sectionFont, brush, 25, 260);

            PdfAxialShading extendedShading = new PdfAxialShading();
            extendedShading.StartColor = new PdfRgbColor(255, 0, 0);
            extendedShading.EndColor = new PdfRgbColor(0, 0, 255);
            extendedShading.StartPoint = new PdfPoint(225, 280);
            extendedShading.EndPoint = new PdfPoint(375, 280);
            extendedShading.ExtendStart = true;
            extendedShading.ExtendEnd = true;

            // Clip the shading to desired area.
            PdfPath esArea = new PdfPath();
            esArea.AddRectangle(25, 280, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(esArea);
            page.Graphics.DrawShading(extendedShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, esArea);

            page.Graphics.DrawString("Limited shading", sectionFont, brush, 25, 330);

            PdfAxialShading limitedShading = new PdfAxialShading();
            limitedShading.StartColor = new PdfRgbColor(255, 0, 0);
            limitedShading.EndColor = new PdfRgbColor(0, 0, 255);
            limitedShading.StartPoint = new PdfPoint(225, 350);
            limitedShading.EndPoint = new PdfPoint(375, 350);
            limitedShading.ExtendStart = false;
            limitedShading.ExtendEnd = false;

            // Clip the shading to desired area.
            PdfPath lsArea = new PdfPath();
            lsArea.AddRectangle(25, 350, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(lsArea);
            page.Graphics.DrawShading(limitedShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, lsArea);

            page.Graphics.DrawString("Multi-stop shading", sectionFont, brush, 25, 400);
            // Multi-stop shadings use a stitching function to combine the functions that define each gradient part.
            // Function for red to blue shading.
            PdfExponentialFunction redToBlueFunc = new PdfExponentialFunction();
            // Linear function
            redToBlueFunc.Exponent = 1;
            redToBlueFunc.Domain = new double[] { 0, 1 };
            // Red color for start
            redToBlueFunc.C0 = new double[] { 1, 0, 0 };
            // Blue color for start
            redToBlueFunc.C1 = new double[] { 0, 0, 1 };
            // Function for blue to green shading.
            PdfExponentialFunction blueToGreenFunc = new PdfExponentialFunction();
            // Linear function
            blueToGreenFunc.Exponent = 1;
            blueToGreenFunc.Domain = new double[] { 0, 1 };
            // Blue color for start
            blueToGreenFunc.C0 = new double[] { 0, 0, 1 };
            // Green color for start
            blueToGreenFunc.C1 = new double[] { 0, 1, 0 };

            //Stitching function for the shading.
            PdfStitchingFunction shadingFunction = new PdfStitchingFunction();
            shadingFunction.Functions.Add(redToBlueFunc);
            shadingFunction.Functions.Add(blueToGreenFunc);
            shadingFunction.Domain = new double[] { 0, 1 };
            shadingFunction.Encode = new double[] { 0, 1, 0, 1 };

            // Entire shading goes from 0 to 1 (100%).
            // We set the first shading (red->blue) to cover 30% (0 - 0.3) and
            // the second shading to cover 70% (0.3 - 1).
            shadingFunction.Bounds = new double[] { 0.3 };
            // The multistop shading
            PdfAxialShading multiStopShading = new PdfAxialShading();
            multiStopShading.StartPoint = new PdfPoint(25, 420);
            multiStopShading.EndPoint = new PdfPoint(575, 420);
            // The colorspace must match the colors specified in C0 & C1
            multiStopShading.ColorSpace = new PdfRgbColorSpace();
            multiStopShading.Function = shadingFunction;

            // Clip the shading to desired area.
            PdfPath mssArea = new PdfPath();
            mssArea.AddRectangle(25, 420, 550, 30);
            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(mssArea);
            page.Graphics.DrawShading(multiStopShading);
            page.Graphics.RestoreGraphicsState();
            page.Graphics.DrawPath(blackPen, lsArea);

            page.Graphics.DrawString("Radial shading", sectionFont, brush, 25, 470);

            PdfRadialShading rs1 = new PdfRadialShading();
            rs1.StartColor = new PdfRgbColor(0, 255, 0);
            rs1.EndColor = new PdfRgbColor(255, 0, 255);
            rs1.StartCircleCenter = new PdfPoint(50, 500);
            rs1.StartCircleRadius = 10;
            rs1.EndCircleCenter = new PdfPoint(500, 570);
            rs1.EndCircleRadius = 100;

            page.Graphics.DrawShading(rs1);

            PdfRadialShading rs2 = new PdfRadialShading();
            rs2.StartColor = new PdfRgbColor(0, 255, 0);
            rs2.EndColor = new PdfRgbColor(255, 0, 255);
            rs2.StartCircleCenter = new PdfPoint(80, 600);
            rs2.StartCircleRadius = 10;
            rs2.EndCircleCenter = new PdfPoint(110, 690);
            rs2.EndCircleRadius = 100;

            page.Graphics.DrawShading(rs2);

            page.Graphics.CompressAndClose();
        }
コード例 #42
0
ファイル: Actions.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateUriActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Graphics.DrawString("Go to xfiniumpdf.com", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PdfUriAction uriAction = new PdfUriAction();
                uriAction.URI = "http://www.xfiniumpdf.com";
                link.Action = uriAction;
            }
        }
コード例 #43
0
ファイル: Annotations.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] textAnnotationNames = new string[]
                {
                    "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph",
                    "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow"
                };

            page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            Random rnd = new Random();
            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                rnd.NextBytes(rgb);
                ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700);
            PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation();
            customTextAnnotation.Author = "Xfinium.Pdf";
            customTextAnnotation.Contents = "Text annotation with custom icon.";
            page.Annotations.Add(customTextAnnotation);
            customTextAnnotation.IconName = "Custom icon appearance";
            customTextAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customTextAnnotation.NormalAppearance = customAppearance;
        }
コード例 #44
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            document.OptionalContentProperties = new PdfOptionalContentProperties();

            PdfStandardFont helveticaBold  = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18);
            PdfBrush blackBrush = new PdfBrush();
            PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen);
            PdfBrush yellowBrush = new PdfBrush(PdfRgbColor.Yellow);
            PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5);
            PdfPen redPen = new PdfPen(PdfRgbColor.DarkRed, 5);

            PdfPage page = document.Pages.Add();
            page.Graphics.DrawString("Simple optional content: the green rectangle", helveticaBold, blackBrush, 20, 50);

            PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup();
            ocgPage1.Name = "Page 1 - Green Rectangle";
            page.Graphics.BeginOptionalContentGroup(ocgPage1);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 400);
            page.Graphics.EndOptionalContentGroup();

            page = document.Pages.Add();
            page.Graphics.DrawString("Multipart optional content: the green rectangles", helveticaBold, blackBrush, 20, 50);

            PdfOptionalContentGroup ocgPage2 = new PdfOptionalContentGroup();
            ocgPage2.Name = "Page 2 - Green Rectangles";
            page.Graphics.BeginOptionalContentGroup(ocgPage2);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680);

            page.Graphics.BeginOptionalContentGroup(ocgPage2);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            page = document.Pages.Add();
            page.Graphics.DrawString("Imbricated optional content: the green and yellow rectangles", helveticaBold, blackBrush, 20, 50);

            PdfOptionalContentGroup ocgPage31 = new PdfOptionalContentGroup();
            ocgPage31.Name = "Page 3 - Green Rectangle";
            page.Graphics.BeginOptionalContentGroup(ocgPage31);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 600);

            PdfOptionalContentGroup ocgPage32 = new PdfOptionalContentGroup();
            ocgPage32.Name = "Page 3 - Yellow Rectangle";
            page.Graphics.BeginOptionalContentGroup(ocgPage32);
            page.Graphics.DrawRectangle(redPen, yellowBrush, 100, 200, 400, 300);
            page.Graphics.EndOptionalContentGroup(); // ocgPage32

            page.Graphics.EndOptionalContentGroup(); // ocgPage31

            page = document.Pages.Add();
            page.Graphics.DrawString("Multipage optional content: the green rectangles on page 4 & 5", helveticaBold, blackBrush, 20, 50);

            PdfOptionalContentGroup ocgPage45 = new PdfOptionalContentGroup();
            ocgPage45.Name = "Page 4 & 5 - Green Rectangles";
            page.Graphics.BeginOptionalContentGroup(ocgPage45);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680);

            page.Graphics.BeginOptionalContentGroup(ocgPage45);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            page = document.Pages.Add();
            page.Graphics.DrawString("Multipage optional content: continued", helveticaBold, blackBrush, 20, 50);

            page.Graphics.BeginOptionalContentGroup(ocgPage45);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680);

            page.Graphics.BeginOptionalContentGroup(ocgPage45);
            page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200);
            page.Graphics.EndOptionalContentGroup();

            // Build the display tree for the optional content,
            // how its structure and relationships between optional content groups are presented to the user.
            PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1);
            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node);
            PdfOptionalContentDisplayTreeNode ocgPage2Node = new PdfOptionalContentDisplayTreeNode(ocgPage2);
            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage2Node);
            PdfOptionalContentDisplayTreeNode ocgPage31Node = new PdfOptionalContentDisplayTreeNode(ocgPage31);
            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage31Node);
            PdfOptionalContentDisplayTreeNode ocgPage32Node = new PdfOptionalContentDisplayTreeNode(ocgPage32);
            ocgPage31Node.Nodes.Add(ocgPage32Node);
            PdfOptionalContentDisplayTreeNode ocgPage45Node = new PdfOptionalContentDisplayTreeNode(ocgPage45);
            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage45Node);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontent.pdf") };
            return output;
        }
コード例 #45
0
ファイル: Form1.cs プロジェクト: e-iceblue/Spire.PDF-for-.NET
        private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);
            doc.Template.Left = leftSpace;

            PdfPageTemplateElement topSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Top);
            topSpace.Foreground = true;
            doc.Template.Top = topSpace;

            //draw header label
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
            String label = "Demo of Spire.Pdf";
            SizeF size = font.MeasureString(label, format);
            float y = topSpace.Height - font.Height - 1;
            PdfPen pen = new PdfPen(Color.Black, 0.75f);
            topSpace.Graphics.SetTransparency(0.5f);
            topSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y);
            y = y - 1 - size.Height;
            topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);
            doc.Template.Right = rightSpace;

            PdfPageTemplateElement bottomSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Bottom);
            bottomSpace.Foreground = true;
            doc.Template.Bottom = bottomSpace;

            //draw footer label
            y = font.Height + 1;
            bottomSpace.Graphics.SetTransparency(0.5f);
            bottomSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y);
            y = y + 1;
            PdfPageNumberField pageNumber = new PdfPageNumberField();
            PdfPageCountField pageCount = new PdfPageCountField();
            PdfCompositeField pageNumberLabel = new PdfCompositeField();
            pageNumberLabel.AutomaticFields
                = new PdfAutomaticField[] { pageNumber, pageCount };
            pageNumberLabel.Brush = PdfBrushes.Black;
            pageNumberLabel.Font = font;
            pageNumberLabel.StringFormat = format;
            pageNumberLabel.Text = "page {0} of {1}";
            pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - margin.Right, y);

            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PointF pageLeftTop = new PointF(-margin.Left, -margin.Top);
            PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension);
            header.Foreground = false;
            header.Graphics.SetTransparency(0.5f);
            header.Graphics.DrawImage(headerImage, 0, 0);
            doc.Template.Stamps.Add(header);

            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");
            y = pageSize.Height - footerImage.PhysicalDimension.Height;
            PointF footerLocation = new PointF(-margin.Left, y);
            PdfPageTemplateElement footer = new PdfPageTemplateElement(footerLocation, footerImage.PhysicalDimension);
            footer.Foreground = false;
            footer.Graphics.SetTransparency(0.5f);
            footer.Graphics.DrawImage(footerImage, 0, 0);
            doc.Template.Stamps.Add(footer);
        }
コード例 #46
0
        public ActionResult DrawingShapes(string InsideBrowser)
        {
            // Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            int         i;
            // Create a new page.
            PdfPage page = doc.Pages.Add();
            // Obtain PdfGraphics object.
            PdfGraphics g    = page.Graphics;
            PdfFont     font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);

            #region Polygon
            PdfPen pen = new PdfPen(Color.Black);
            pen.Width = 3;
            PointF p1 = new PointF(05, 10);
            PointF p2 = new PointF(05, 10);
            PointF p3 = new PointF(60, 70);
            PointF p4 = new PointF(40, 70);

            PointF[] points = { p1, p2, p3, p4 };

            int pointNum = 16;
            points = new PointF[pointNum];
            double       f      = 360.0 / pointNum * Math.PI / 180.0;
            const double r      = 100;
            PointF       center = new PointF(140, 140);

            for (i = 0; i < pointNum; ++i)
            {
                PointF p     = new PointF();
                double theta = i * f;

                p.Y = (float)(Math.Sin(theta) * r + center.Y);
                p.X = (float)(Math.Cos(theta) * r + center.X);

                points[i] = p;
            }

            PdfSolidBrush brush = new PdfSolidBrush(Color.Green);
            pen.Color    = Color.Brown;
            pen.Width    = 10;
            pen.LineJoin = PdfLineJoin.Round;
            g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0));
            g.DrawPolygon(pen, brush, points);

            #endregion

            #region  Pie

            RectangleF rect = new RectangleF(200, 50, 200, 200);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            pen.Width   = 10;

            rect.Location = new PointF(20, 280);
            pen.LineJoin  = PdfLineJoin.Round;
            g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250));
            g.DrawPie(pen, brush, rect, 180, 60);
            g.DrawPie(pen, brush, rect, 360 - 60, 60);
            g.DrawPie(pen, brush, rect, 60, 60);

            #endregion

            #region Arc

            g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0));
            pen         = new PdfPen(Color.Black);
            pen.Width   = 11;
            pen.LineCap = PdfLineCap.Round;
            pen.Color   = Color.Brown;
            rect        = new RectangleF(310, 40, 200, 200);
            g.DrawArc(pen, rect, 0, 90);

            pen.Color = Color.DarkGreen;
            rect.X   -= 10;
            g.DrawArc(pen, rect, 90, 90);

            pen.Color = Color.Brown;
            rect.Y   -= 10;
            g.DrawArc(pen, rect, 180, 90);

            pen.Color = Color.DarkGreen;
            rect.X   += 10;
            g.DrawArc(pen, rect, 270, 90);

            #endregion

            #region Rectangle
            rect        = new RectangleF(310, 280, 200, 100);
            brush.Color = Color.Green;
            pen.Color   = Color.Brown;
            g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255));
            g.DrawRectangle(pen, brush, rect);
            #endregion

            #region ellipse
            pen  = new PdfPen(Color.Black);
            rect = new RectangleF(270, 400, 160, 1000);
            g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390));
            PdfEllipse      ellipse = new PdfEllipse(rect);
            PdfLayoutFormat format  = new PdfLayoutFormat();
            format.Break  = PdfLayoutBreakType.FitPage;
            format.Layout = PdfLayoutType.Paginate;
            ellipse.Brush = PdfBrushes.Brown;
            ellipse.Draw(page, 20, 20, format);

            brush         = new PdfSolidBrush(Color.Black);
            ellipse.Brush = PdfBrushes.DarkGreen;
            ellipse.Draw(page, 40, 40, format);

            #endregion

            #region Transaparency

            page = doc.Pages[1];
            g    = page.Graphics;
            g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80));
            PdfBrush gBrush;
            rect = new RectangleF(10, 150, 100, 100);

            pen    = new PdfPen(Color.Black);
            gBrush = new PdfSolidBrush(Color.DarkGreen);

            g.DrawRectangle(pen, gBrush, rect);
            gBrush  = new PdfSolidBrush(Color.Brown);
            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Brown);
            g.SetTransparency(0.7f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            gBrush  = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal);
            g.SetTransparency(0.5f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Blue);
            gBrush  = new PdfSolidBrush(Color.Gray);
            g.SetTransparency(0.25f);
            g.DrawRectangle(pen, gBrush, rect);

            rect.X += 20;
            rect.Y += 20;
            pen     = new PdfPen(Color.Black);
            gBrush  = new PdfSolidBrush(Color.Green);
            g.SetTransparency(0.1f);
            g.DrawRectangle(pen, gBrush, rect);

            #endregion

            #region Rectangle with Color space



            PointF location = new PointF(10, 50);
            page = doc.Pages.Add();
            g    = page.Graphics;

            doc.ColorSpace = (PdfColorSpace)i;

            // SolidBrush
            gBrush = new PdfSolidBrush(Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // LinearGradient
            location = new PointF(180, 50);

            PointF point2 = location;

            point2.X += 180;
            gBrush    = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red);
            DrawRectangles(location, g, font, gBrush, pen, doc);

            // Raidal Gradient
            location = new PointF(360, 50);
            point2   = location;

            point2 = new PointF(location.X + 50, location.Y + 50);
            //point2.Y += 250;
            //point2.X = 150;
            gBrush = new PdfRadialGradientBrush(point2, 0, point2, 100, Color.Blue, Color.Red);
            (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.Both;
            DrawRectangles(location, g, font, gBrush, pen, doc);

            g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0));
            #endregion

            //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 = "Shapes.pdf";
            return(fileStreamResult);
        }
コード例 #47
0
ファイル: Actions.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateNamedActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Named actions:", font, blackBrush, 400, 20);

                /////////////
                // First page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 40, 200, 20);
                slo.X = 500;
                slo.Y = 50;
                document.Pages[i].Graphics.DrawString("Go To First Page", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 40, 200, 20);

                // Create a named action and attach it to the link.
                PdfNamedAction namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.FirstPage;
                link.Action = namedAction;

                /////////////
                // Prev page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 80, 200, 20);
                slo.Y = 90;
                document.Pages[i].Graphics.DrawString("Go To Previous Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 80, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.PrevPage;
                link.Action = namedAction;

                /////////////
                // Next page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 120, 200, 20);
                slo.Y = 130;
                document.Pages[i].Graphics.DrawString("Go To Next Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 120, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.NextPage;
                link.Action = namedAction;

                /////////////
                // Last page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 160, 200, 20);
                slo.Y = 170;
                document.Pages[i].Graphics.DrawString("Go To Last Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 160, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.LastPage;
                link.Action = namedAction;

                /////////////
                // Print document
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 200, 200, 20);
                slo.Y = 210;
                document.Pages[i].Graphics.DrawString("Print Document", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 200, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.Print;
                link.Action = namedAction;
            }
        }
コード例 #48
0
ファイル: Measurements.cs プロジェクト: baitun/BGUEP-Journal
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            // Create the pdf document
            PdfFixedDocument document = new PdfFixedDocument();
            // Create a new page in the document
            PdfPage page = document.Pages.Add();

            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 4);
            PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 2);
            PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black);
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16);

            // Draw viewport border.
            page.Graphics.DrawRectangle(blackPen, 50, 50, 500, 500);
            // Draw the line to be measured.
            page.Graphics.DrawLine(greenPen, 70, 70, 530, 530);
            // Draw point A (line start) in the viewport.
            page.Graphics.DrawLine(redPen, 60, 70, 80, 70);
            page.Graphics.DrawLine(redPen, 70, 60, 70, 80);
            // Draw point B (line end) in the viewport.
            page.Graphics.DrawLine(redPen, 520, 530, 540, 530);
            page.Graphics.DrawLine(redPen, 530, 520, 530, 540);

            page.Graphics.DrawString("A", helvetica, blackBrush, 85, 65);
            page.Graphics.DrawString("B", helvetica, blackBrush, 505, 525);
            page.Graphics.DrawString("Viewport", helvetica, blackBrush, 50, 560);
            helvetica.Size = 10;
            page.Graphics.DrawString(
                "Open the file with Adobe Acrobat and measure the distance from A to B using the Distance tool.",
                helvetica, blackBrush, 50, 580);
            page.Graphics.DrawString("The measured distance should be 9 mi 186 ft 1 1/4 in.",
                helvetica, blackBrush, 50, 590);

            // Create a viewport that matches the rectangle above.
            PdfViewport vp = new PdfViewport();
            vp.Name = "Sample viewport";
            PdfPoint ll = page.ConvertVisualPointToStandardPoint(new PdfPoint(50, 50));
            PdfPoint ur = page.ConvertVisualPointToStandardPoint(new PdfPoint(550, 550));
            vp.Bounds = new PdfStandardRectangle(ll, ur);

            // Add the viewport to the page
            page.Viewports = new PdfViewportCollection();
            page.Viewports.Add(vp);

            // Create a rectilinear measure for the viewport (CAD drawing for example).
            PdfRectilinearMeasure rlm = new PdfRectilinearMeasure();
            // Attach the measure to the viewport.
            vp.Measure = rlm;
            // Set the measure scale: 1 inch (72 points) in PDF corresponds to 1 mile
            rlm.ScaleRatio = "1 in = 1 mi";

            // Create a number format that controls the display of units for X axis.
            PdfNumberFormat xNumberFormat = new PdfNumberFormat();
            xNumberFormat.MeasureUnit = "mi";
            xNumberFormat.ConversionFactor = 1/72.0; // Conversion from user space units to miles
            xNumberFormat.FractionDisplay = PdfFractionDisplay.Decimal;
            xNumberFormat.Precision = 100000;
            rlm.X = new PdfNumberFormatCollection();
            rlm.X.Add(xNumberFormat);

            // Create a chain of number formats that control the display of units for distance.
            rlm.Distance = new PdfNumberFormatCollection();
            PdfNumberFormat miNumberFormat = new PdfNumberFormat();
            miNumberFormat.MeasureUnit = "mi";
            miNumberFormat.ConversionFactor = 1; // Initial unit is miles; no conversion needed
            rlm.Distance.Add(miNumberFormat);
            PdfNumberFormat ftNumberFormat = new PdfNumberFormat();
            ftNumberFormat.MeasureUnit = "ft";
            ftNumberFormat.ConversionFactor = 5280; // Conversion from miles to feet
            rlm.Distance.Add(ftNumberFormat);
            PdfNumberFormat inNumberFormat = new PdfNumberFormat();
            inNumberFormat.MeasureUnit = "in";
            inNumberFormat.ConversionFactor = 12; // Conversion from feet to inches
            inNumberFormat.FractionDisplay = PdfFractionDisplay.Fraction;
            inNumberFormat.Denominator = 8; // Fractions of inches rounded to nearest 1/8
            rlm.Distance.Add(inNumberFormat);

            // Create a number format that controls the display of units area.
            PdfNumberFormat areaNumberFormat = new PdfNumberFormat();
            areaNumberFormat.MeasureUnit = "acres";
            areaNumberFormat.ConversionFactor = 640; // Conversion from square miles to acres
            rlm.Area = new PdfNumberFormatCollection();
            rlm.Area.Add(xNumberFormat);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.measurements.pdf") };
            return output;
        }
コード例 #49
0
        /// <summary>
        /// Create ZugFerd Invoice Pdf
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public PdfDocument CreateZugFerdInvoicePDF(PdfDocument document)
        {
            //Add page to the PDF
            PdfPage page = document.Pages.Add();

            PdfGraphics graphics = page.Graphics;

            //Create border color
            PdfColor borderColor = Syncfusion.Drawing.Color.FromArgb(255, 142, 170, 219);

            //Get the page width and height
            float pageWidth  = page.GetClientSize().Width;
            float pageHeight = page.GetClientSize().Height;

            //Set the header height
            float headerHeight = 90;


            PdfColor lightBlue      = Syncfusion.Drawing.Color.FromArgb(255, 91, 126, 215);
            PdfBrush lightBlueBrush = new PdfSolidBrush(lightBlue);

            PdfColor darkBlue      = Syncfusion.Drawing.Color.FromArgb(255, 65, 104, 209);
            PdfBrush darkBlueBrush = new PdfSolidBrush(darkBlue);

            PdfBrush whiteBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 255, 255));

#if COMMONSB
            Stream fontStream = typeof(ZugFerd).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.arial.ttf");
#else
            Stream fontStream = typeof(ZugFerd).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.arial.ttf");
#endif

            PdfTrueTypeFont headerFont = new PdfTrueTypeFont(fontStream, 30, PdfFontStyle.Regular);

            PdfTrueTypeFont arialRegularFont = new PdfTrueTypeFont(fontStream, 18, PdfFontStyle.Regular);
            PdfTrueTypeFont arialBoldFont    = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Bold);

            //Create string format.
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment     = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            float y = 0;
            float x = 0;

            //Set the margins of address.
            float margin = 30;

            //Set the line space
            float lineSpace = 7;

            PdfPen borderPen = new PdfPen(borderColor, 1f);

            //Draw page border
            graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight));


            PdfGrid grid = new PdfGrid();

            grid.DataSource = GetProductReport();

            #region Header

            //Fill the header with light Brush
            graphics.DrawRectangle(lightBlueBrush, new RectangleF(0, 0, pageWidth, headerHeight));

            string title = "INVOICE";

            SizeF textSize = headerFont.MeasureString(title);

            RectangleF headerTotalBounds = new RectangleF(400, 0, pageWidth - 400, headerHeight);

            graphics.DrawString(title, headerFont, whiteBrush, new RectangleF(0, 0, textSize.Width + 50, headerHeight), format);

            graphics.DrawRectangle(darkBlueBrush, headerTotalBounds);

            graphics.DrawString("$" + GetTotalAmount(grid).ToString(), arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight + 10), format);

            arialRegularFont = new PdfTrueTypeFont(fontStream, 9, PdfFontStyle.Regular);

            format.LineAlignment = PdfVerticalAlignment.Bottom;
            graphics.DrawString("Amount", arialRegularFont, whiteBrush, new RectangleF(400, 0, pageWidth - 400, headerHeight / 2 - arialRegularFont.Height), format);

            #endregion


            SizeF size = arialRegularFont.MeasureString("Invoice Number: 2058557939");
            y = headerHeight + margin;
            x = (pageWidth - margin) - size.Width;

            graphics.DrawString("Invoice Number: 2058557939", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            size = arialRegularFont.MeasureString("Date :" + DateTime.Now.ToString("dddd dd, MMMM yyyy"));
            x    = (pageWidth - margin) - size.Width;
            y   += arialRegularFont.Height + lineSpace;

            graphics.DrawString("Date: " + DateTime.Now.ToString("dddd dd, MMMM yyyy"), arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y = headerHeight + margin;
            x = margin;
            graphics.DrawString("Bill To:", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("Abraham Swearegin,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("United States, California, San Mateo,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("9920 BridgePointe Parkway,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
            y += arialRegularFont.Height + lineSpace;
            graphics.DrawString("9365550136", arialRegularFont, PdfBrushes.Black, new PointF(x, y));


            #region Grid

            grid.Columns[0].Width = 110;
            grid.Columns[1].Width = 150;
            grid.Columns[2].Width = 110;
            grid.Columns[3].Width = 70;
            grid.Columns[4].Width = 100;

            for (int i = 0; i < grid.Headers.Count; i++)
            {
                grid.Headers[i].Height = 20;
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    PdfStringFormat pdfStringFormat = new PdfStringFormat();
                    pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle;

                    pdfStringFormat.Alignment = PdfTextAlignment.Left;
                    if (j == 0 || j == 2)
                    {
                        grid.Headers[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1);
                    }

                    grid.Headers[i].Cells[j].StringFormat = pdfStringFormat;

                    grid.Headers[i].Cells[j].Style.Font = arialBoldFont;
                }
                grid.Headers[0].Cells[0].Value = "Product Id";
            }
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Height = 23;
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    PdfStringFormat pdfStringFormat = new PdfStringFormat();
                    pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle;

                    pdfStringFormat.Alignment = PdfTextAlignment.Left;
                    if (j == 0 || j == 2)
                    {
                        grid.Rows[i].Cells[j].Style.CellPadding = new PdfPaddings(30, 1, 1, 1);
                    }

                    grid.Rows[i].Cells[j].StringFormat = pdfStringFormat;
                    grid.Rows[i].Cells[j].Style.Font   = arialRegularFont;
                }
            }
            grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.ListTable4Accent5);
            grid.BeginCellLayout += Grid_BeginCellLayout;


            PdfGridLayoutResult result = grid.Draw(page, new PointF(0, y + 40));

            y                = result.Bounds.Bottom + lineSpace;
            format           = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Center;
            RectangleF bounds = new RectangleF(QuantityCellBounds.X, y, QuantityCellBounds.Width, QuantityCellBounds.Height);

            page.Graphics.DrawString("Grand Total:", arialBoldFont, PdfBrushes.Black, bounds, format);

            bounds = new RectangleF(TotalPriceCellBounds.X, y, TotalPriceCellBounds.Width, TotalPriceCellBounds.Height);
            page.Graphics.DrawString(GetTotalAmount(grid).ToString(), arialBoldFont, PdfBrushes.Black, bounds);


            #endregion



            borderPen.DashStyle   = PdfDashStyle.Custom;
            borderPen.DashPattern = new float[] { 3, 3 };

            graphics.DrawLine(borderPen, new PointF(0, pageHeight - 100), new PointF(pageWidth, pageHeight - 100));

            y = pageHeight - 100 + margin;

            size = arialRegularFont.MeasureString("800 Interchange Blvd.");

            x = pageWidth - size.Width - margin;

            graphics.DrawString("800 Interchange Blvd.", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y += arialRegularFont.Height + lineSpace;

            size = arialRegularFont.MeasureString("Suite 2501,  Austin, TX 78721");

            x = pageWidth - size.Width - margin;

            graphics.DrawString("Suite 2501,  Austin, TX 78721", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            y += arialRegularFont.Height + lineSpace;

            size = arialRegularFont.MeasureString("Any Questions? [email protected]");

            x = pageWidth - size.Width - margin;
            graphics.DrawString("Any Questions? [email protected]", arialRegularFont, PdfBrushes.Black, new PointF(x, y));

            return(document);
        }
コード例 #50
0
ファイル: Actions.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateLaunchActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Launch actions:", font, blackBrush, 400, 360);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 380, 200, 20);
                slo.X = 500;
                slo.Y = 390;
                document.Pages[i].Graphics.DrawString("Launch samples explorer", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 380, 200, 20);

                // Create a launch action and attach it to the link.
                PdfLaunchAction launchAction = new PdfLaunchAction();
                launchAction.FileName = "Xfinium.Pdf.SamplesExplorer.Win.exe";
                link.Action = launchAction;
            }
        }
コード例 #51
0
ファイル: Annotations.cs プロジェクト: littlefeihu/checktask
        private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();
            Random   rnd        = new Random();

            // Random binary data to be used a file content for file attachment annotations.
            byte[] fileData = new byte[256];

            PdfPage page = document.Pages.Add();

            string[] fileAttachmentAnnotationNames = new string[]
            {
                "Graph", "Paperclip", "PushPin", "Tag"
            };

            page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author   = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload  = fileData;
                faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat";
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author   = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload  = fileData;
                faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat";
                rnd.NextBytes(rgb);
                faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700);
            PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation();

            customFileAttachmentAnnotation.Author   = "Xfinium.Pdf";
            customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon.";
            page.Annotations.Add(customFileAttachmentAnnotation);
            customFileAttachmentAnnotation.IconName = "Custom icon appearance";
            customFileAttachmentAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen  = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);

            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customFileAttachmentAnnotation.NormalAppearance = customAppearance;
        }
コード例 #52
0
ファイル: Actions.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action = jsAction;
            }
        }
コード例 #53
0
ファイル: Annotations.cs プロジェクト: littlefeihu/checktask
        private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            string[] textAnnotationNames = new string[]
            {
                "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph",
                "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow"
            };

            page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author   = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            Random rnd = new Random();

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < textAnnotationNames.Length; i++)
            {
                PdfTextAnnotation ta = new PdfTextAnnotation();
                ta.Author   = "Xfinium.Pdf";
                ta.Contents = "I am a " + textAnnotationNames[i] + " annotation.";
                ta.IconName = textAnnotationNames[i];
                rnd.NextBytes(rgb);
                ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(ta);
                ta.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700);
            PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation();

            customTextAnnotation.Author   = "Xfinium.Pdf";
            customTextAnnotation.Contents = "Text annotation with custom icon.";
            page.Annotations.Add(customTextAnnotation);
            customTextAnnotation.IconName = "Custom icon appearance";
            customTextAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen  = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);

            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customTextAnnotation.NormalAppearance = customAppearance;
        }
コード例 #54
0
ファイル: PageObjects.cs プロジェクト: baitun/BGUEP-Journal
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10);

            PdfFixedDocument document = new PdfFixedDocument(input);

            PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]);
            PdfVisualObjectCollection voc = ce.ExtractVisualObjects(false);

            PdfPath contour = null;
            for (int i = 0; i < voc.Count; i++)
            {
                switch (voc[i].Type)
                {
                    case PdfVisualObjectType.Image:
                        PdfImageVisualObject ivo = voc[i] as PdfImageVisualObject;
                        contour = new PdfPath();
                        contour.StartSubpath(ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5);
                        contour.AddLineTo(ivo.Image.ImageCorners[1].X + 5, ivo.Image.ImageCorners[1].Y + 5);
                        contour.AddLineTo(ivo.Image.ImageCorners[2].X + 5, ivo.Image.ImageCorners[2].Y - 5);
                        contour.AddLineTo(ivo.Image.ImageCorners[3].X - 5, ivo.Image.ImageCorners[3].Y - 5);
                        contour.CloseSubpath();
                        document.Pages[0].Graphics.DrawPath(redPen, contour);

                        document.Pages[0].Graphics.DrawString("Image", helvetica, brush,
                            ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5);
                        break;
                    case PdfVisualObjectType.Text:
                        PdfTextVisualObject tvo = voc[i] as PdfTextVisualObject;
                        contour = new PdfPath();
                        contour.StartSubpath(tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5);
                        contour.AddLineTo(tvo.TextFragment.FragmentCorners[1].X + 5, tvo.TextFragment.FragmentCorners[1].Y + 5);
                        contour.AddLineTo(tvo.TextFragment.FragmentCorners[2].X + 5, tvo.TextFragment.FragmentCorners[2].Y - 5);
                        contour.AddLineTo(tvo.TextFragment.FragmentCorners[3].X - 5, tvo.TextFragment.FragmentCorners[3].Y - 5);
                        contour.CloseSubpath();
                        document.Pages[0].Graphics.DrawPath(redPen, contour);

                        document.Pages[0].Graphics.DrawString("Text", helvetica, brush,
                            tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5);
                        break;
                    case PdfVisualObjectType.Path:
                        PdfPathVisualObject pvo = voc[i] as PdfPathVisualObject;
                        // Examine all the path points and determine the minimum rectangle that bounds the path.
                        double minX = 999999, minY = 999999, maxX = -999999, maxY = -999999;
                        for (int j = 0; j < pvo.PathItems.Count; j++)
                        {
                            PdfPathItem pi = pvo.PathItems[j];
                            if (pi.Points != null)
                            {
                                for (int k = 0; k < pi.Points.Length; k++)
                                {
                                    if (minX >= pi.Points[k].X)
                                    {
                                        minX = pi.Points[k].X;
                                    }
                                    if (minY >= pi.Points[k].Y)
                                    {
                                        minY = pi.Points[k].Y;
                                    }
                                    if (maxX <= pi.Points[k].X)
                                    {
                                        maxX = pi.Points[k].X;
                                    }
                                    if (maxY <= pi.Points[k].Y)
                                    {
                                        maxY = pi.Points[k].Y;
                                    }
                                }
                            }
                        }

                        contour = new PdfPath();
                        contour.StartSubpath(minX - 5, minY - 5);
                        contour.AddLineTo(maxX + 5, minY - 5);
                        contour.AddLineTo(maxX + 5, maxY + 5);
                        contour.AddLineTo(minX - 5, maxY + 5);
                        contour.CloseSubpath();
                        document.Pages[0].Graphics.DrawPath(redPen, contour);

                        document.Pages[0].Graphics.DrawString("Path", helvetica, brush, minX - 5, maxY + 5);
                        // Skip the rest of path objects, they are the evaluation message
                        i = voc.Count;
                        break;
                }
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageobjects.pdf") };
            return output;
        }
コード例 #55
0
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream LayersPDF()
        {
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();

            doc.PageSettings = new PdfPageSettings(new SizeF(350, 300));

            PdfPage page = doc.Pages.Add();

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

            page.Graphics.DrawString("Layers", font, PdfBrushes.DarkBlue, new PointF(150, 10));

            //Add the first layer
            PdfPageLayer layer = page.Layers.Add("Layer1");

            PdfGraphics graphics = layer.Graphics;

            graphics.TranslateTransform(100, 60);

            //Draw Arc
            PdfPen     pen  = new PdfPen(Color.Red, 50);
            RectangleF rect = new RectangleF(0, 0, 50, 50);

            graphics.DrawArc(pen, rect, 360, 360);

            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, 360, 360);

            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            //Add another layer on the page
            layer = page.Layers.Add("Layer2");

            graphics = layer.Graphics;
            graphics.TranslateTransform(100, 180);
            graphics.SkewTransform(0, 50);

            //Draw another set of elements
            pen = new PdfPen(Color.Red, 50);
            graphics.DrawArc(pen, rect, 360, 360);
            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);
            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, 360, 360);
            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, 360, 360);

            //Add another layer
            layer    = page.Layers.Add("Layer3");
            graphics = layer.Graphics;
            graphics.TranslateTransform(160, 120);

            //Draw another set of elements.
            pen = new PdfPen(Color.Red, 50);
            graphics.DrawArc(pen, rect, -60, 60);
            pen = new PdfPen(Color.Blue, 30);
            graphics.DrawArc(pen, 0, 0, 50, 50, -60, 60);
            pen = new PdfPen(Color.Yellow, 20);
            graphics.DrawArc(pen, rect, -60, 60);
            pen = new PdfPen(Color.Green, 10);
            graphics.DrawArc(pen, 0, 0, 50, 50, -60, 60);

            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            doc.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            doc.Close(true);
            return(stream);
        }
コード例 #56
0
ファイル: Form1.cs プロジェクト: e-iceblue/Spire.PDF-for-.NET
        private void DrawPage(PdfPageBase page)
        {
            float pageWidth = page.Canvas.ClientSize.Width;
            float y = 0;

            //page header
            PdfPen pen1 = new PdfPen(Color.LightGray, 1f);
            PdfBrush brush1 = new PdfSolidBrush(Color.LightGray);
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right);
            String text = "Demo of Spire.Pdf";
            page.Canvas.DrawString(text, font1, brush1, pageWidth, y, format1);
            SizeF size = font1.MeasureString(text, format1);
            y = y + size.Height + 1;
            page.Canvas.DrawLine(pen1, 0, y, pageWidth, y);

            //title
            y = y + 5;
            PdfBrush brush2 = new PdfSolidBrush(Color.Black);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center);
            format2.CharacterSpacing = 1f;
            text = "Summary of Science";
            page.Canvas.DrawString(text, font2, brush2, pageWidth / 2, y, format2);
            size = font2.MeasureString(text, format2);
            y = y + size.Height + 6;

            //icon
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Wikipedia_Science.png");
            page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y));
            float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2;
            float imageBottom = image.PhysicalDimension.Height + y;

            //refenrence content
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat format3 = new PdfStringFormat();
            format3.ParagraphIndent = font3.Size * 2;
            format3.MeasureTrailingSpaces = true;
            format3.LineSpacing = font3.Size * 1.5f;
            String text1 = "(All text and picture from ";
            String text2 = "Wikipedia";
            String text3 = ", the free encyclopedia)";
            page.Canvas.DrawString(text1, font3, brush2, 0, y, format3);

            size = font3.MeasureString(text1, format3);
            float x1 = size.Width;
            format3.ParagraphIndent = 0;
            PdfTrueTypeFont font4 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Underline));
            PdfBrush brush3 = PdfBrushes.Blue;
            page.Canvas.DrawString(text2, font4, brush3, x1, y, format3);
            size = font4.MeasureString(text2, format3);
            x1 = x1 + size.Width;

            page.Canvas.DrawString(text3, font3, brush2, x1, y, format3);
            y = y + size.Height;

            //content
            PdfStringFormat format4 = new PdfStringFormat();
            text = System.IO.File.ReadAllText(@"..\..\..\..\..\..\Data\Summary_of_Science.txt");
            PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f));
            format4.LineSpacing = font5.Size * 1.5f;
            PdfStringLayouter textLayouter = new PdfStringLayouter();
            float imageLeftBlockHeight = imageBottom - y;
            PdfStringLayoutResult result
                = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            if (result.ActualSize.Height < imageBottom - y)
            {
                imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight;
                result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
            }
            foreach (LineInfo line in result.Lines)
            {
                page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4);
                y = y + result.LineHeight;
            }
            PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2);
            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
            textWidget.StringFormat = format4;
            textWidget.Draw(page, bounds, textLayout);
        }
コード例 #57
0
ファイル: Barcodes.cs プロジェクト: baitun/BGUEP-Journal
        private static void Draw2DBarcodes(PdfPage page, PdfFont titleFont, PdfFont barcodeFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen lightGrayPen = new PdfPen(PdfRgbColor.LightGray, 0.5);

            page.Graphics.DrawString("2D barcodes", titleFont, brush, 40, 20);
            for (int i = 0; i < 3; i++)
            {
                page.Graphics.DrawLine(lightGrayPen, 40, 50 + 150 * i, 570, 50 + 150 * i);
            }
            page.Graphics.DrawLine(lightGrayPen, 306, 50, 306, 500);

            string[] barcodes = new string[] { "Codablock F", "Code 16K", "PDF417", "Micro PDF417", "DataMatrix", "QR" };
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = brush;
            sao.Font = barcodeFont;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Top;

            slo.X = 173;
            int sign = 1;
            for (int i = 0; i < barcodes.Length; i++)
            {
                slo.Y = 55 + 150 * (i / 2);

                page.Graphics.DrawString(barcodes[i], sao, slo);

                slo.X = slo.X + sign * 266;
                sign = -sign;
            }

            // Codablock F
            PdfCodablockFBarcode codablockFBarcode = new PdfCodablockFBarcode();
            codablockFBarcode.Data = "*** Xfinium.Pdf ***";
            codablockFBarcode.Columns = 10;
            codablockFBarcode.Rows = 5;
            page.Graphics.DrawBarcode(codablockFBarcode, 173 - codablockFBarcode.Width / 2, 70);

            // Code 16K
            PdfCode16KBarcode code16KBarcode = new PdfCode16KBarcode();
            code16KBarcode.Data = "*** Xfinium.Pdf ***";
            code16KBarcode.Rows = 6;
            page.Graphics.DrawBarcode(code16KBarcode, 173 + 266 - code16KBarcode.Width / 2, 70);

            // PDF 417
            Pdf417RegularBarcode pdf417Barcode = new Pdf417RegularBarcode();
            pdf417Barcode.Data = "*** Xfinium.Pdf ***";
            pdf417Barcode.Columns = 10;
            pdf417Barcode.Rows = 0;
            page.Graphics.DrawBarcode(pdf417Barcode, 173 - pdf417Barcode.Width / 2, 220);

            // MicroPDF 417
            Pdf417MicroBarcode microPdf417Barcode = new Pdf417MicroBarcode();
            microPdf417Barcode.Data = "* Xfinium.Pdf *";
            microPdf417Barcode.BarcodeSize = Pdf417MicroBarcodeSize.Rows6Columns4;
            page.Graphics.DrawBarcode(microPdf417Barcode, 173 + 266 - microPdf417Barcode.Width / 2, 220);

            // DataMatrix
            PdfDataMatrixBarcode datamatrixBarcode = new PdfDataMatrixBarcode();
            datamatrixBarcode.Data = "*** Xfinium.Pdf ***";
            datamatrixBarcode.XDimension = 2;
            datamatrixBarcode.BarcodeSize = DataMatrixBarcodeSize.Auto;
            page.Graphics.DrawBarcode(datamatrixBarcode, 173 - datamatrixBarcode.Width / 2, 370);

            // QR Barcode
            PdfQrBarcode qrBarcode = new PdfQrBarcode();
            qrBarcode.XDimension = 2;
            qrBarcode.Data = "Xfinium.Pdf: http://www.xfiniumpdf.com/";
            qrBarcode.CharacterSet = PdfQrBarcodeCharacterSet.ISO88591;
            page.Graphics.DrawBarcode(qrBarcode, 173 + 266 - qrBarcode.Width / 2, 370);

            page.Graphics.CompressAndClose();
        }
コード例 #58
0
ファイル: Annotations.cs プロジェクト: baitun/BGUEP-Journal
        private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();
            Random rnd = new Random();
            // Random binary data to be used a file content for file attachment annotations.
            byte[] fileData = new byte[256];

            PdfPage page = document.Pages.Add();

            string[] fileAttachmentAnnotationNames = new string[]
                {
                    "Graph", "Paperclip", "PushPin", "Tag"
                };

            page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload = fileData;
                faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat";
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(50, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i);
            }

            byte[] rgb = new byte[3];
            page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50);
            for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++)
            {
                rnd.NextBytes(fileData);

                PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation();
                faa.Author = "Xfinium.Pdf";
                faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation.";
                faa.IconName = fileAttachmentAnnotationNames[i];
                faa.Payload = fileData;
                faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat";
                rnd.NextBytes(rgb);
                faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                rnd.NextBytes(rgb);
                faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]);
                page.Annotations.Add(faa);
                faa.Location = new PdfPoint(300, 100 + 40 * i);
                page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i);
            }

            page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700);
            PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation();
            customFileAttachmentAnnotation.Author = "Xfinium.Pdf";
            customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon.";
            page.Annotations.Add(customFileAttachmentAnnotation);
            customFileAttachmentAnnotation.IconName = "Custom icon appearance";
            customFileAttachmentAnnotation.Location = new PdfPoint(50, 720);

            PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50);
            PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10);
            PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10);
            customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40);
            customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height);
            customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0);
            customAppearance.Graphics.CompressAndClose();
            customFileAttachmentAnnotation.NormalAppearance = customAppearance;
        }
コード例 #59
0
        public ActionResult InteractiveFeatures(string InsideBrowser)
        {
            #region Field Definitions
            document = new PdfDocument();
            document.PageSettings.Margins.All = 0;
            document.PageSettings.Size        = new SizeF(PdfPageSize.A4.Width, 600);
            interactivePage = document.Pages.Add();
            PdfGraphics g    = interactivePage.Graphics;
            RectangleF  rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100);

            PdfBrush whiteBrush  = new PdfSolidBrush(white);
            PdfPen   whitePen    = new PdfPen(white, 5);
            PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160));
            PdfFont  font        = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60);
            Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73);
            #endregion

            #region Header
            g.DrawRectangle(purpleBrush, rect);
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180);
            g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200));
            g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10));

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;
            dataPath = basePath + @"/PDF/";

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

            g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130));
            #endregion

            #region Body

            //Invoice Number
            Random invoiceNumber = new Random();
            g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210));
            g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210));

            //Current Date
            PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date");
            textBoxField.Font          = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
            textBoxField.Bounds        = new RectangleF(384, 204, 150, 30);
            textBoxField.ForeColor     = new PdfColor(maroonColor);
            textBoxField.ReadOnly      = true;
            document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); 
            var thisfieldis = this.getField('date');  
            
            var theday = util.printd('dddd',newdate); 
            var thedate = util.printd('d',newdate); 
            var themonth = util.printd('mmmm',newdate);
            var theyear = util.printd('yyyy',newdate);  
            
            thisfieldis.strokeColor=color.transparent;
            thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;");
            document.Form.Fields.Add(textBoxField);

            //invoice table
            PdfLightTable table = new PdfLightTable();
            table.Style.ShowHeader = true;
            g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140));

            //Header Style
            PdfCellStyle headerStyle = new PdfCellStyle();
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            headerStyle.TextBrush       = whiteBrush;
            headerStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor);
            headerStyle.BorderPen       = new PdfPen(whiteBrush, 0);
            table.Style.HeaderStyle     = headerStyle;

            //Cell Style
            PdfCellStyle bodyStyle = new PdfCellStyle();
            bodyStyle.Font           = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            bodyStyle.StringFormat   = new PdfStringFormat(PdfTextAlignment.Left);
            bodyStyle.BorderPen      = new PdfPen(whiteBrush, 0);
            table.Style.DefaultStyle = bodyStyle;
            table.DataSource         = GetProductReport(_hostingEnvironment.WebRootPath);
            table.Columns[0].Width   = 90;
            table.Columns[1].Width   = 160;
            table.Columns[3].Width   = 100;
            table.Columns[4].Width   = 65;
            table.Style.CellPadding  = 3;
            table.BeginCellLayout   += table_BeginCellLayout;

            PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140));

            g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom));
            CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, "");


            //Send to Server
            PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline");
            sendButton.Bounds      = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25);
            sendButton.BorderColor = white;
            sendButton.BackColor   = maroonColor;
            sendButton.ForeColor   = white;
            sendButton.Text        = "Order Online";
            PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php");
            submitAction.DataFormat    = SubmitDataFormat.Html;
            sendButton.Actions.MouseUp = submitAction;
            document.Form.Fields.Add(sendButton);

            //Order by Mail
            PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail");
            sendMail.Bounds      = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25);
            sendMail.Text        = "Order By Mail";
            sendMail.BorderColor = white;
            sendMail.BackColor   = maroonColor;
            sendMail.ForeColor   = white;

            // Create a javascript action.
            PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");"
                                                                     + "var aSubmitFields = [];"
                                                                     + "for( var i = 0 ; i < this.numFields; i++){"
                                                                     + "aSubmitFields[i] = this.getNthFieldName(i);"
                                                                     + "}"
                                                                     + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}");

            sendMail.Actions.MouseUp = javaAction;
            document.Form.Fields.Add(sendMail);

            //Print
            PdfButtonField printButton = new PdfButtonField(interactivePage, "print");
            printButton.Bounds          = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25);
            printButton.BorderColor     = white;
            printButton.BackColor       = maroonColor;
            printButton.ForeColor       = white;
            printButton.Text            = "Print";
            printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); ");
            document.Form.Fields.Add(printButton);
            file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file);
            attachment.ModificationDate = DateTime.Now;
            attachment.Description      = "Specification";
            document.Attachments.Add(attachment);

            //Open Specification
            PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification");
            openSpecificationButton.Bounds          = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15);
            openSpecificationButton.TextAlignment   = PdfTextAlignment.Left;
            openSpecificationButton.Font            = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
            openSpecificationButton.BorderStyle     = PdfBorderStyle.Underline;
            openSpecificationButton.BorderColor     = orangeColor;
            openSpecificationButton.BackColor       = new PdfColor(255, 255, 255);
            openSpecificationButton.ForeColor       = orangeColor;
            openSpecificationButton.Text            = "Open Specification";
            openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });");
            document.Form.Fields.Add(openSpecificationButton);

            RectangleF     uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20);
            PdfTextWebLink linkAnnot = new PdfTextWebLink();
            linkAnnot.Url   = "http://www.adventure-works.com";
            linkAnnot.Text  = "http://www.adventure-works.com";
            linkAnnot.Font  = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
            linkAnnot.Brush = PdfBrushes.White;
            linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location);
            #endregion

            #region Footer
            g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100));
            g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180);
            #endregion

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

            document.Save(ms);

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

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

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");
            fileStreamResult.FileDownloadName = "Interactive features.pdf";
            return(fileStreamResult);
        }
コード例 #60
0
        private static void DrawRoundRectangles(PdfPage page, PdfFont titleFont, PdfFont sectionFont)
        {
            PdfBrush brush = new PdfBrush();
            PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1);
            PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1);

            PdfRgbColor randomPenColor = new PdfRgbColor();
            PdfPen randomPen = new PdfPen(randomPenColor, 1);
            PdfRgbColor randomBrushColor = new PdfRgbColor();
            PdfBrush randomBrush = new PdfBrush(randomBrushColor);

            page.Graphics.DrawString("Round rectangles", titleFont, brush, 20, 50);

            page.Graphics.DrawLine(blackPen, 20, 150, 300, 150);
            page.Graphics.DrawLine(blackPen, 80, 70, 80, 350);
            page.Graphics.DrawRoundRectangle(redPen, 80, 150, 180, 100, 20, 20);

            page.Graphics.DrawLine(blackPen, 320, 150, 600, 150);
            page.Graphics.DrawLine(blackPen, 380, 70, 380, 350);
            page.Graphics.DrawRoundRectangle(redPen, 380, 150, 180, 100, 20, 20, 30);

            page.Graphics.DrawString("Random round rectangles clipped to view", sectionFont, brush, 20, 385);
            PdfPath roundRectPath = new PdfPath();
            roundRectPath.AddRoundRectangle(20, 400, 570, 300, 20, 20);

            page.Graphics.SaveGraphicsState();
            page.Graphics.SetClip(roundRectPath);

            Random rnd = new Random();
            for (int i = 0; i < 100; i++)
            {
                randomPenColor.R = (byte)rnd.Next(256);
                randomPenColor.G = (byte)rnd.Next(256);
                randomPenColor.B = (byte)rnd.Next(256);

                randomBrushColor.R = (byte)rnd.Next(256);
                randomBrushColor.G = (byte)rnd.Next(256);
                randomBrushColor.B = (byte)rnd.Next(256);

                int mode = rnd.Next(3);
                double left = rnd.NextDouble() * page.Width;
                double top = 380 + rnd.NextDouble() * 350;
                double width = rnd.NextDouble() * page.Width;
                double height = rnd.NextDouble() * 250;
                double orientation = rnd.Next(360);
                switch (mode)
                {
                    case 0:
                        // Stroke rectangle outline
                        page.Graphics.DrawRoundRectangle(randomPen, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                    case 1:
                        // Fill rectangle interior
                        page.Graphics.DrawRoundRectangle(randomBrush, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                    case 2:
                        // Stroke and fill rectangle
                        page.Graphics.DrawRoundRectangle(randomPen, randomBrush, left, top, width, height, width * 0.1, height * 0.1, orientation);
                        break;
                }
            }

            page.Graphics.RestoreGraphicsState();

            page.Graphics.DrawPath(blackPen, roundRectPath);

            page.Graphics.CompressAndClose();
        }