Beispiel #1
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Hyperlink.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.AutoCreateUriActions = true;

                PdfPage page = pdf.Pages[0];
                page.Canvas.DrawString(10, 50, "Url: http://bitmiracle.com");

                PdfRectangle rectWithLink = new PdfRectangle(10, 70, 200, 100);
                page.Canvas.DrawRectangle(rectWithLink, PdfDrawMode.Stroke);

                var options = new PdfTextDrawingOptions(rectWithLink)
                {
                    HorizontalAlignment = PdfTextAlign.Center,
                    VerticalAlignment   = PdfVerticalAlign.Center
                };
                page.Canvas.DrawText("Go to Google", options);

                page.AddHyperlink(rectWithLink, new Uri("http://google.com"));

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }
Beispiel #2
0
        private static void drawCenteredText(PdfCanvas canvas, string text, PdfRectangle bounds)
        {
            var options = new PdfTextDrawingOptions(bounds)
            {
                HorizontalAlignment = PdfTextAlign.Center,
                VerticalAlignment   = PdfVerticalAlign.Center
            };

            canvas.DrawText(text, options);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "DrawText.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                canvas.DrawString(10, 50, "Hello, world!");

                const string LongString        = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
                var          singleLineOptions = new PdfTextDrawingOptions(new PdfRectangle(10, 70, 40, 150))
                {
                    Multiline           = false,
                    HorizontalAlignment = PdfTextAlign.Left,
                    VerticalAlignment   = PdfVerticalAlign.Top
                };
                canvas.DrawText(LongString, singleLineOptions);

                var multiLineOptions = new PdfTextDrawingOptions(new PdfRectangle(70, 70, 40, 150))
                {
                    HorizontalAlignment = PdfTextAlign.Left,
                    VerticalAlignment   = PdfVerticalAlign.Top
                };
                canvas.DrawText(LongString, multiLineOptions);

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }