Пример #1
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            HPdfDoc pdf = new HPdfDoc();

            pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_USE_OUTLINE);

            /* add a new page object. */
            /* Add 3 pages to the document. */
            HPdfPage page0 = pdf.AddPage();
            page0.SetFontAndSize(font, 30);
            PrintPage(page0, 1);

            HPdfPage page1 = pdf.AddPage();
            page1.SetFontAndSize(font, 30);
            PrintPage(page1, 2);

            HPdfPage page2 = pdf.AddPage();
            page2.SetFontAndSize(font, 30);
            PrintPage(page2, 3);

            /* create outline root. */
            HPdfOutline root = pdf.CreateOutline(null, "OutlineRoot", null);
            root.SetOpened(true);

            HPdfOutline outline0 = pdf.CreateOutline(root, "page1", null);
            HPdfOutline outline1 = pdf.CreateOutline(root, "page2", null);

            /* create outline with test which is ISO8859-2 encoding */
            HPdfOutline outline2 = pdf.CreateOutline(root, "ISO8859-2 text гдежзий",
                                                     pdf.GetEncoder("ISO8859-2"));

            /* create destination objects on each pages
             * and link it to outline items.
             */
            HPdfDestination dst = page0.CreateDestination();
            dst.SetXYZ(0, page0.GetHeight(), 1);
            outline0.SetDestination(dst);

            dst = page1.CreateDestination();
            dst.SetXYZ(0, page1.GetHeight(), 1);
            outline1.SetDestination(dst);

            dst = page2.CreateDestination();
            dst.SetXYZ(0, page2.GetHeight(), 1);
            outline2.SetDestination(dst);

            /* save the document to a file */
            pdf.SaveToFile("OutlineDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #2
0
    public static void Main()
    {
        string owner_passwd = "owner";
        string user_passwd  = "";
        string text         = "User cannot print and copy this document.";

        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            HPdfDoc pdf = new HPdfDoc();

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            /* add a new page object. */
            HPdfPage page = pdf.AddPage();

            page.SetSize(HPdfPageSizes.HPDF_PAGE_SIZE_B5,
                         HPdfPageDirection.HPDF_PAGE_LANDSCAPE);

            page.BeginText();
            page.SetFontAndSize(font, 20);
            float tw = page.TextWidth(text);
            page.MoveTextPos((page.GetWidth() - tw) / 2,
                             (page.GetHeight() - 20) / 2);
            page.ShowText(text);
            page.EndText();

            pdf.SetPassword(owner_passwd, user_passwd);
            pdf.SetPermission(HPdfDoc.HPDF_ENABLE_READ);

            /* use 128 bit revision 3 encryption */
            pdf.SetEncryptionMode(HPdfEncryptMode.HPDF_ENCRYPT_R3, 16);

            /* save the document to a file */
            pdf.SaveToFile("Permission.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #3
0
    public static void Main()
    {
        string owner_passwd = "owner";
        string user_passwd  = "user";
        string text         = "This is an encrypt document example.";

        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            HPdfDoc pdf = new HPdfDoc();

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            /* add a new page object. */
            HPdfPage page = pdf.AddPage();

            page.SetSize(HPdfPageSizes.HPDF_PAGE_SIZE_B5,
                         HPdfPageDirection.HPDF_PAGE_LANDSCAPE);

            page.BeginText();
            page.SetFontAndSize(font, 20);
            float tw = page.TextWidth(text);
            page.MoveTextPos((page.GetWidth() - tw) / 2,
                             (page.GetHeight() - 20) / 2);
            page.ShowText(text);
            page.EndText();

            pdf.SetPassword(owner_passwd, user_passwd);

            /* save the document to a file */
            pdf.SaveToFile("Encryption.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #4
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        byte[] raw_image_data = new byte[] {
            0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfc,
            0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0,
            0xf3, 0xf3, 0xff, 0xe0, 0xf3, 0xf3, 0xff, 0xc0,
            0xf3, 0xf3, 0xff, 0x80, 0xf3, 0x33, 0xff, 0x00,
            0xf3, 0x33, 0xfe, 0x00, 0xf3, 0x33, 0xfc, 0x00,
            0xf8, 0x07, 0xf8, 0x00, 0xf8, 0x07, 0xf0, 0x00,
            0xfc, 0xcf, 0xe0, 0x00, 0xfc, 0xcf, 0xc0, 0x00,
            0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00,
            0xff, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00,
            0xff, 0xf8, 0x0f, 0xe0, 0xff, 0xf0, 0x0f, 0xe0,
            0xff, 0xe0, 0x0c, 0x30, 0xff, 0xc0, 0x0c, 0x30,
            0xff, 0x80, 0x0f, 0xe0, 0xff, 0x00, 0x0f, 0xe0,
            0xfe, 0x00, 0x0c, 0x30, 0xfc, 0x00, 0x0c, 0x30,
            0xf8, 0x00, 0x0f, 0xe0, 0xf0, 0x00, 0x0f, 0xe0,
            0xe0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
            0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        };

        try {
            HPdfDoc pdf = new HPdfDoc();

            pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            /* add a new page object. */
            HPdfPage page = pdf.AddPage();

            page.SetWidth(172);
            page.SetHeight(80);

            page.BeginText();
            page.SetFontAndSize(font, 20);
            page.MoveTextPos(220, page.GetHeight() - 70);
            page.ShowText("RawImageDemo");
            page.EndText();

            /* load RGB raw-image file. */
            HPdfImage image = pdf.LoadRawImageFromFile("rawimage\\32_32_rgb.dat",
                                                       32, 32, HPdfColorSpace.HPDF_CS_DEVICE_RGB);

            float x = 20;
            float y = 20;

            /* Draw image to the canvas. (normal-mode with actual size.)*/
            page.DrawImage(image, x, y, 32, 32);

            /* load GrayScale raw-image file. */
            image = pdf.LoadRawImageFromFile("rawimage\\32_32_gray.dat",
                                             32, 32, HPdfColorSpace.HPDF_CS_DEVICE_GRAY);

            x = 70;
            y = 20;

            /* Draw image to the canvas. (normal-mode with actual size.)*/
            page.DrawImage(image, x, y, 32, 32);

            /* load GrayScale raw-image (1bit) file from memory. */
            image = pdf.LoadRawImageFromMem(raw_image_data, 32, 32,
                                            HPdfColorSpace.HPDF_CS_DEVICE_GRAY, 1);

            x = 120;
            y = 20;

            /* Draw image to the canvas. (normal-mode with actual size.)*/
            page.DrawImage(image, x, y, 32, 32);

            /* save the document to a file */
            pdf.SaveToFile("RawImageDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #5
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            HPdfDoc pdf = new HPdfDoc();

            pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            /* add a new page object. */
            HPdfPage page = pdf.AddPage();

            page.SetWidth(550);
            page.SetHeight(500);

            HPdfDestination dst = page.CreateDestination();
            dst.SetXYZ(0, page.GetHeight(), 1);
            pdf.SetOpenAction(dst);

            page.BeginText();
            page.SetFontAndSize(font, 20);
            page.MoveTextPos(220, page.GetHeight() - 70);
            page.ShowText("ImageDemo");
            page.EndText();

            /* load image file. */
            HPdfImage image = pdf.LoadPngImageFromFile("pngsuite\\basn3p02.png");

            /* image1 is masked by image2. */
            HPdfImage image1 = pdf.LoadPngImageFromFile("pngsuite\\basn3p02.png");

            /* image2 is a mask image. */
            HPdfImage image2 = pdf.LoadPngImageFromFile("pngsuite\\basn0g01.png");

            /* image3 is a RGB-color image. we use this image for color-mask
             * demo.
             */
            HPdfImage image3 = pdf.LoadPngImageFromFile("pngsuite\\maskimage.png");

            float iw = image.GetWidth();
            float ih = image.GetHeight();

            page.SetLineWidth(0.5f);

            float x = 100;
            float y = page.GetHeight() - 150;

            /* Draw image to the canvas. (normal-mode with actual size.)*/
            page.DrawImage(image, x, y, iw, ih);

            ShowDescription(page, x, y, "Actual Size");

            x += 150;

            /* Scalling image (X direction) */
            page.DrawImage(image, x, y, iw * 1.5f, ih);

            ShowDescription(page, x, y, "Scalling image (X direction)");

            x += 150;

            /* Scalling image (Y direction). */
            page.DrawImage(image, x, y, iw, ih * 1.5f);
            ShowDescription(page, x, y, "Scalling image (Y direction)");

            x  = 100;
            y -= 120;

            /* Skewing image. */
            float angle1 = 10;
            float angle2 = 20;
            float rad1   = angle1 / 180 * 3.141592f;
            float rad2   = angle2 / 180 * 3.141592f;

            page.GSave();

            page.Concat(iw, (float)Math.Tan(rad1) * iw, (float)Math.Tan(rad2) * ih,
                        ih, x, y);

            page.ExecuteXObject(image);
            page.GRestore();

            ShowDescription(page, x, y, "Skewing image");

            x += 150;

            /* Rotating image */
            float angle = 30;                      /* rotation of 30 degrees. */
            float rad   = angle / 180 * 3.141592f; /* Calcurate the radian value. */

            page.GSave();

            page.Concat((float)(iw * Math.Cos(rad)),
                        (float)(iw * Math.Sin(rad)),
                        (float)(ih * -Math.Sin(rad)),
                        (float)(ih * Math.Cos(rad)),
                        x, y);

            page.ExecuteXObject(image);
            page.GRestore();

            ShowDescription(page, x, y, "Rotating image");

            x += 150;

            /* draw masked image. */

            /* Set image2 to the mask image of image1 */
            image1.SetMaskImage(image2);

            page.SetRGBFill(0, 0, 0);
            page.BeginText();
            page.MoveTextPos(x - 6, y + 14);
            page.ShowText("MASKMASK");
            page.EndText();

            page.DrawImage(image1, x - 3, y - 3, iw + 6, ih + 6);

            ShowDescription(page, x, y, "masked image");

            x  = 100;
            y -= 120;

            /* color mask. */
            page.SetRGBFill(0, 0, 0);
            page.BeginText();
            page.MoveTextPos(x - 6, y + 14);
            page.ShowText("MASKMASK");
            page.EndText();

            image3.SetColorMask(0, 255, 0, 0, 0, 255);
            page.DrawImage(image3, x, y, iw, ih);

            ShowDescription(page, x, y, "Color Mask");

            /* save the document to a file */
            pdf.SaveToFile("ImageDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #6
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            const string page_title = "LineDemo";

            HPdfDoc pdf = new HPdfDoc();

            /* create default-font */
            HPdfFont font = pdf.GetFont("Helvetica", null);

            /* add a new page object. */
            HPdfPage page = pdf.AddPage();

            /* print the lines of the page. */
            page.SetLineWidth(1);
            page.Rectangle(50, 50, page.GetWidth() - 100,
                           page.GetHeight() - 110);
            page.Stroke();

            /* print the title of the page (with positioning center). */
            page.SetFontAndSize(font, 24);
            float tw = page.TextWidth(page_title);
            page.BeginText();
            page.MoveTextPos((page.GetWidth() - tw) / 2,
                             page.GetHeight() - 50);
            page.ShowText(page_title);
            page.EndText();

            page.SetFontAndSize(font, 10);

            /* Draw verious widths of lines. */
            page.SetLineWidth(0);
            DrawLine(page, 60, 770, "line width = 0");

            page.SetLineWidth(1.0f);
            DrawLine(page, 60, 740, "line width = 1.0");

            page.SetLineWidth(2.0f);
            DrawLine(page, 60, 710, "line width = 2.0");

            /* Line dash pattern */
            ushort[] dash_mode1 = new ushort[] { 3 };
            ushort[] dash_mode2 = new ushort[] { 3, 7 };
            ushort[] dash_mode3 = new ushort[] { 8, 7, 2, 7 };

            page.SetLineWidth(1.0f);

            page.SetDash(dash_mode1, 1);
            DrawLine(page, 60, 680, "dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...");

            Console.Error.WriteLine("001");
            page.SetDash(dash_mode2, 2);
            DrawLine(page, 60, 650, "dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,...");

            page.SetDash(dash_mode3, 0);
            DrawLine(page, 60, 620, "dash_ptn=[8, 7, 2, 7], phase=0");

            page.SetDash(null, 0);

            page.SetLineWidth(30);
            page.SetRGBStroke(0.0f, 0.5f, 0.0f);

            /* Line Cap Style */
            page.SetLineCap(HPdfLineCap.HPDF_BUTT_END);
            DrawLine2(page, 60, 570, "HPDF_BUTT_END");

            page.SetLineCap(HPdfLineCap.HPDF_ROUND_END);
            DrawLine2(page, 60, 505, "HPDF_ROUND_END");

            page.SetLineCap(HPdfLineCap.HPDF_PROJECTING_SQUARE_END);
            DrawLine2(page, 60, 440, "HPDF_PROJECTING_SQUARE_END");

            /* Line Join Style */
            page.SetLineWidth(30);
            page.SetRGBStroke(0.0f, 0.0f, 0.5f);

            page.SetLineJoin(HPdfLineJoin.HPDF_MITER_JOIN);
            page.MoveTo(120, 300);
            page.LineTo(160, 340);
            page.LineTo(200, 300);
            page.Stroke();

            page.BeginText();
            page.MoveTextPos(60, 360);
            page.ShowText("HPDF_MITER_JOIN");
            page.EndText();

            page.SetLineJoin(HPdfLineJoin.HPDF_ROUND_JOIN);
            page.MoveTo(120, 195);
            page.LineTo(160, 235);
            page.LineTo(200, 195);
            page.Stroke();

            page.BeginText();
            page.MoveTextPos(60, 255);
            page.ShowText("HPDF_ROUND_JOIN");
            page.EndText();

            page.SetLineJoin(HPdfLineJoin.HPDF_BEVEL_JOIN);
            page.MoveTo(120, 90);
            page.LineTo(160, 130);
            page.LineTo(200, 90);
            page.Stroke();

            page.BeginText();
            page.MoveTextPos(60, 150);
            page.ShowText("HPDF_BEVEL_JOIN");
            page.EndText();

            /* Draw Rectangle */
            page.SetLineWidth(2);
            page.SetRGBStroke(0, 0, 0);
            page.SetRGBFill(0.75f, 0.0f, 0.0f);

            DrawRect(page, 300, 770, "Stroke");
            page.Stroke();

            DrawRect(page, 300, 720, "Fill");
            page.Fill();

            DrawRect(page, 300, 670, "Fill then Stroke");
            page.FillStroke();

            /* Clip Rect */
            page.GSave();  /* Save the current graphic state */
            DrawRect(page, 300, 620, "Clip Rectangle");
            page.Clip();
            page.Stroke();
            page.SetFontAndSize(font, 13);

            page.BeginText();
            page.MoveTextPos(290, 600);
            page.SetTextLeading(12);
            page.ShowText("Clip Clip Clip Clip Clip Clipi Clip Clip Clip");
            page.ShowTextNextLine("Clip Clip Clip Clip Clip Clip Clip Clip Clip");
            page.ShowTextNextLine("Clip Clip Clip Clip Clip Clip Clip Clip Clip");
            page.EndText();
            page.GRestore();

            /* Curve Example(CurveTo2) */
            float x  = 330;
            float y  = 440;
            float x1 = 430;
            float y1 = 530;
            float x2 = 480;
            float y2 = 470;
            float x3 = 480;
            float y3 = 90;

            page.SetRGBFill(0, 0, 0);

            page.BeginText();
            page.MoveTextPos(300, 540);
            page.ShowText("CurveTo2(x1, y1, x2. y2)");
            page.EndText();

            page.BeginText();
            page.MoveTextPos(x + 5, y - 5);
            page.ShowText("Current point");
            page.MoveTextPos(x1 - x, y1 - y);
            page.ShowText("(x1, y1)");
            page.MoveTextPos(x2 - x1, y2 - y1);
            page.ShowText("(x2, y2)");
            page.EndText();

            page.SetDash(dash_mode1, 0);

            page.SetLineWidth(0.5f);
            page.MoveTo(x1, y1);
            page.LineTo(x2, y2);
            page.Stroke();

            page.SetDash(null, 0);

            page.SetLineWidth(1.5f);

            page.MoveTo(x, y);
            page.CurveTo2(x1, y1, x2, y2);
            page.Stroke();

            /* Curve Example(CurveTo3) */
            y  -= 150;
            y1 -= 150;
            y2 -= 150;

            page.BeginText();
            page.MoveTextPos(300, 390);
            page.ShowText("CurveTo3(x1, y1, x2. y2)");
            page.EndText();

            page.BeginText();
            page.MoveTextPos(x + 5, y - 5);
            page.ShowText("Current point");
            page.MoveTextPos(x1 - x, y1 - y);
            page.ShowText("(x1, y1)");
            page.MoveTextPos(x2 - x1, y2 - y1);
            page.ShowText("(x2, y2)");
            page.EndText();

            page.SetDash(dash_mode1, 0);

            page.SetLineWidth(0.5f);
            page.MoveTo(x, y);
            page.LineTo(x1, y1);
            page.Stroke();

            page.SetDash(null, 0);

            page.SetLineWidth(1.5f);
            page.MoveTo(x, y);
            page.CurveTo3(x1, y1, x2, y2);
            page.Stroke();

            /* Curve Example(CurveTo) */
            y  -= 150;
            y1 -= 160;
            y2 -= 130;
            x2 += 10;

            page.BeginText();
            page.MoveTextPos(300, 240);
            page.ShowText("CurveTo(x1, y1, x2. y2, x3, y3)");
            page.EndText();

            page.BeginText();
            page.MoveTextPos(x + 5, y - 5);
            page.ShowText("Current point");
            page.MoveTextPos(x1 - x, y1 - y);
            page.ShowText("(x1, y1)");
            page.MoveTextPos(x2 - x1, y2 - y1);
            page.ShowText("(x2, y2)");
            page.MoveTextPos(x3 - x2, y3 - y2);
            page.ShowText("(x3, y3)");
            page.EndText();

            page.SetDash(dash_mode1, 0);

            page.SetLineWidth(0.5f);
            page.MoveTo(x, y);
            page.LineTo(x1, y1);
            page.Stroke();
            page.MoveTo(x2, y2);
            page.LineTo(x3, y3);
            page.Stroke();

            page.SetDash(null, 0);

            page.SetLineWidth(1.5f);
            page.MoveTo(x, y);
            page.CurveTo(x1, y1, x2, y2, x3, y3);
            page.Stroke();

            pdf.SaveToFile("LineDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #7
0
        public static void Main()
        {
            const string pageTitle        = "Text Demo";
            const string simpleRandomText = "abcdefgABCDEFG123!#$%&+-@?";
            const string sampText         = "The quick brown fox jumps over the lazy dog.";

            try
            {
                var pdf = new HPdfDoc();

                pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);

                /* create default-font */
                var font = pdf.GetFont("Helvetica", null);

                /* add a new page object. */
                var page = pdf.AddPage();

                /*print the title of the page (with positioning center). */
                page.SetFontAndSize(font, 24);
                var tw = page.TextWidth(pageTitle);
                page.BeginText();
                page.TextOut((page.GetWidth() - tw) / 2,
                             page.GetHeight() - 50, pageTitle);
                page.EndText();

                page.BeginText();
                page.MoveTextPos(60, page.GetHeight() - 60);

                /*
                 * font size
                 */
                float fsize = 8;
                while (fsize < 60)
                {
                    /* set style and size of font. */
                    page.SetFontAndSize(font, fsize);

                    /* set the position of the text. */
                    page.MoveTextPos(0, -5 - fsize);

                    /* measure the number of characters which included in the page. */
                    var tlen = page.MeasureText(simpleRandomText,
                                                page.GetWidth() - 120, false);

                    page.ShowText(simpleRandomText.Substring(0, (int)tlen));

                    /* print the description. */
                    page.MoveTextPos(0, -10);
                    page.SetFontAndSize(font, 8);
                    page.ShowText("Fontsize=" + fsize);

                    fsize *= 1.5f;
                }

                /*
                 * font color
                 */
                page.SetFontAndSize(font, 8);
                page.MoveTextPos(0, -30);
                page.ShowText("Font color");

                page.SetFontAndSize(font, 18);
                page.MoveTextPos(0, -20);
                var len = simpleRandomText.Length;

                for (var i = 0; i < len; i++)
                {
                    var r   = i / (float)len;
                    var g   = 1 - i / (float)len;
                    var buf = simpleRandomText.Substring(i, 1);

                    page.SetRGBFill(r, g, 0);
                    page.ShowText(buf);
                }
                page.MoveTextPos(0, -25);

                for (var i = 0; i < len; i++)
                {
                    var r   = i / (float)len;
                    var b   = 1 - i / (float)len;
                    var buf = simpleRandomText.Substring(i, 1);

                    page.SetRGBFill(r, 0, b);
                    page.ShowText(buf);
                }
                page.MoveTextPos(0, -25);

                for (var i = 0; i < len; i++)
                {
                    var b   = i / (float)len;
                    var g   = 1 - i / (float)len;
                    var buf = simpleRandomText.Substring(i, 1);

                    page.SetRGBFill(0, g, b);
                    page.ShowText(buf);
                }

                page.EndText();

                const int ypos = 450;

                /*
                 * Font rendering mode
                 */
                page.SetFontAndSize(font, 32);
                page.SetRGBFill(0.5f, 0.5f, 0);
                page.SetLineWidth(1.5f);

                /* PDF_FILL */
                ShowDescription(page, 60, ypos,
                                "RenderingMode=PDF_FILL");
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL);
                page.BeginText();
                page.TextOut(60, ypos, "ABCabc123");
                page.EndText();

                /*PDF_STROKE */
                ShowDescription(page, 60, ypos - 50,
                                "RenderingMode=PDF_STROKE");
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_STROKE);
                page.BeginText();
                page.TextOut(60, ypos - 50, "ABCabc123");
                page.EndText();

                /*PDF_FILL_THEN_STROKE */
                ShowDescription(page, 60, ypos - 100,
                                "RenderingMode=PDF_FILL_THEN_STROKE");
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_THEN_STROKE);
                page.BeginText();
                page.TextOut(60, ypos - 100, "ABCabc123");
                page.EndText();

                /*PDF_FILL_CLIPPING */
                ShowDescription(page, 60, ypos - 150,
                                "RenderingMode=PDF_FILL_CLIPPING");
                page.GSave();
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_CLIPPING);
                page.BeginText();
                page.TextOut(60, ypos - 150, "ABCabc123");
                page.EndText();
                ShowStripePattern(page, 60, ypos - 150);
                page.GRestore();

                /*PDF_STROKE_CLIPPING */
                ShowDescription(page, 60, ypos - 200,
                                "RenderingMode=PDF_STROKE_CLIPPING");
                page.GSave();
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_STROKE_CLIPPING);
                page.BeginText();
                page.TextOut(60, ypos - 200, "ABCabc123");
                page.EndText();
                ShowStripePattern(page, 60, ypos - 200);
                page.GRestore();

                /*PDF_FILL_STROKE_CLIPPING */
                ShowDescription(page, 60, ypos - 250,
                                "RenderingMode=PDF_FILL_STROKE_CLIPPING");
                page.GSave();
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL_STROKE_CLIPPING);
                page.BeginText();
                page.TextOut(60, ypos - 250, "ABCabc123");
                page.EndText();
                ShowStripePattern(page, 60, ypos - 250);
                page.GRestore();

                /*Reset text attributes */
                page.SetTextRenderingMode(HPdfTextRenderingMode.HPDF_FILL);
                page.SetRGBFill(0, 0, 0);
                page.SetFontAndSize(font, 30);


                /*
                 * Rotating text
                 */
                float angle1 = 30;                       /* A rotation of 30 degrees. */
                var   rad1   = angle1 / 180 * 3.141592f; /* Calcurate the radian value. */

                ShowDescription(page, 320, ypos - 60, "Rotating text");
                page.BeginText();
                page.SetTextMatrix((float)Math.Cos(rad1), (float)Math.Sin(rad1),
                                   -(float)Math.Sin(rad1), (float)Math.Cos(rad1),
                                   330, ypos - 60);
                page.ShowText("ABCabc123");
                page.EndText();


                /*
                 * Skewing text.
                 */
                ShowDescription(page, 320, ypos - 120, "Skewing text");
                page.BeginText();

                angle1 = 10;
                float angle2 = 20;
                rad1 = angle1 / 180 * 3.141592f;
                var rad2 = angle2 / 180 * 3.141592f;

                page.SetTextMatrix(1, (float)Math.Tan(rad1), (float)Math.Tan(rad2), 1,
                                   320, ypos - 120);
                page.ShowText("ABCabc123");
                page.EndText();


                /*
                 * scaling text (X direction)
                 */
                ShowDescription(page, 320, ypos - 175, "Scaling text (X direction)");
                page.BeginText();
                page.SetTextMatrix(1.5f, 0, 0, 1, 320, ypos - 175);
                page.ShowText("ABCabc12");
                page.EndText();


                /*
                 * scaling text (Y direction)
                 */
                ShowDescription(page, 320, ypos - 250, "Scaling text (Y direction)");
                page.BeginText();
                page.SetTextMatrix(1, 0, 0, 2, 320, ypos - 250);
                page.ShowText("ABCabc123");
                page.EndText();


                /*
                 * char spacing, word spacing
                 */

                ShowDescription(page, 60, 140, "char-spacing 0");
                ShowDescription(page, 60, 100, "char-spacing 1.5");
                ShowDescription(page, 60, 60, "char-spacing 1.5, word-spacing 2.5");

                page.SetFontAndSize(font, 20);
                page.SetRGBFill(0.1f, 0.3f, 0.1f);

                /*char-spacing 0 */
                page.BeginText();
                page.TextOut(60, 140, sampText);
                page.EndText();

                /*char-spacing 1.5 */
                page.SetCharSpace(1.5f);

                page.BeginText();
                page.TextOut(60, 100, sampText);
                page.EndText();

                /*char-spacing 1.5, word-spacing 3.5 */
                page.SetWordSpace(2.5f);

                page.BeginText();
                page.TextOut(60, 60, sampText);
                page.EndText();

                /* save the document to a file */
                pdf.SaveToFile("TextDemo.pdf");

                Console.WriteLine("Done DEAL!");
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
Пример #8
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        rand = new Random();

        try {
            HPdfDoc    pdf  = new HPdfDoc();
            HPdfPage[] page = new HPdfPage[17];

            /* create default-font */
            HPdfFont font = pdf.GetFont("Courier", null);

            /* Add 17 pages to the document. */
            page[0]  = pdf.AddPage();
            page[1]  = pdf.AddPage();
            page[2]  = pdf.AddPage();
            page[3]  = pdf.AddPage();
            page[4]  = pdf.AddPage();
            page[5]  = pdf.AddPage();
            page[6]  = pdf.AddPage();
            page[7]  = pdf.AddPage();
            page[8]  = pdf.AddPage();
            page[9]  = pdf.AddPage();
            page[10] = pdf.AddPage();
            page[11] = pdf.AddPage();
            page[12] = pdf.AddPage();
            page[13] = pdf.AddPage();
            page[14] = pdf.AddPage();
            page[15] = pdf.AddPage();
            page[16] = pdf.AddPage();

            PrintPage(page[0], "HPDF_TS_WIPE_RIGHT", font,
                      HPdfTransitionStyle.HPDF_TS_WIPE_RIGHT, null, page[1]);
            PrintPage(page[1], "HPDF_TS_WIPE_UP", font,
                      HPdfTransitionStyle.HPDF_TS_WIPE_UP, page[0], page[2]);
            PrintPage(page[2], "HPDF_TS_WIPE_LEFT", font,
                      HPdfTransitionStyle.HPDF_TS_WIPE_LEFT, page[1], page[3]);
            PrintPage(page[3], "HPDF_TS_WIPE_DOWN", font,
                      HPdfTransitionStyle.HPDF_TS_WIPE_DOWN, page[2], page[4]);
            PrintPage(page[4], "HPDF_TS_BARN_DOORS_HORIZONTAL_OUT", font,
                      HPdfTransitionStyle.HPDF_TS_BARN_DOORS_HORIZONTAL_OUT, page[3], page[5]);
            PrintPage(page[5], "HPDF_TS_BARN_DOORS_HORIZONTAL_IN", font,
                      HPdfTransitionStyle.HPDF_TS_BARN_DOORS_HORIZONTAL_IN, page[4], page[6]);
            PrintPage(page[6], "HPDF_TS_BARN_DOORS_VERTICAL_OUT", font,
                      HPdfTransitionStyle.HPDF_TS_BARN_DOORS_VERTICAL_OUT, page[5], page[7]);
            PrintPage(page[7], "HPDF_TS_BARN_DOORS_VERTICAL_IN", font,
                      HPdfTransitionStyle.HPDF_TS_BARN_DOORS_VERTICAL_IN, page[6], page[8]);
            PrintPage(page[8], "HPDF_TS_BOX_OUT", font,
                      HPdfTransitionStyle.HPDF_TS_BOX_OUT, page[7], page[9]);
            PrintPage(page[9], "HPDF_TS_BOX_IN", font,
                      HPdfTransitionStyle.HPDF_TS_BOX_IN, page[8], page[10]);
            PrintPage(page[10], "HPDF_TS_BLINDS_HORIZONTAL", font,
                      HPdfTransitionStyle.HPDF_TS_BLINDS_HORIZONTAL, page[9], page[11]);
            PrintPage(page[11], "HPDF_TS_BLINDS_VERTICAL", font,
                      HPdfTransitionStyle.HPDF_TS_BLINDS_VERTICAL, page[10], page[12]);
            PrintPage(page[12], "HPDF_TS_DISSOLVE", font,
                      HPdfTransitionStyle.HPDF_TS_DISSOLVE, page[11], page[13]);
            PrintPage(page[13], "HPDF_TS_GLITTER_RIGHT", font,
                      HPdfTransitionStyle.HPDF_TS_GLITTER_RIGHT, page[12], page[14]);
            PrintPage(page[14], "HPDF_TS_GLITTER_DOWN", font,
                      HPdfTransitionStyle.HPDF_TS_GLITTER_DOWN, page[13], page[15]);
            PrintPage(page[15], "HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT", font,
                      HPdfTransitionStyle.HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT, page[14], page[16]);
            PrintPage(page[16], "HPDF_TS_REPLACE", font,
                      HPdfTransitionStyle.HPDF_TS_REPLACE, page[15], null);


            pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_FULL_SCREEN);

            /* save the document to a file */
            pdf.SaveToFile("SlideShowDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #9
0
    public static void Main()
    {
        string[] font_list = new string[] {
            "Courier",
            "Courier-Bold",
            "Courier-Oblique",
            "Courier-BoldOblique",
            "Helvetica",
            "Helvetica-Bold",
            "Helvetica-Oblique",
            "Helvetica-BoldOblique",
            "Times-Roman",
            "Times-Bold",
            "Times-Italic",
            "Times-BoldItalic",
            "Symbol",
            "ZapfDingbats"
        };

        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            const string page_title = "FontDemo";

            HPdfDoc pdf = new HPdfDoc();

            HPdfPage page = pdf.AddPage();

            float height = page.GetHeight();
            float width  = page.GetWidth();

            /* Print the lines of the page. */
            page.SetLineWidth(1);
            page.Rectangle(50, 50, width - 100, height - 110);
            page.Stroke();

            /* Print the title of the page (with positioning center). */
            HPdfFont def_font = pdf.GetFont("Helvetica", null);
            page.SetFontAndSize(def_font, 24);

            float tw = page.TextWidth(page_title);
            page.BeginText();
            page.TextOut((width - tw) / 2, height - 50, page_title);
            page.EndText();

            /* output subtitle. */
            page.BeginText();
            page.SetFontAndSize(def_font, 16);
            page.TextOut(60, height - 80, "<Standerd Type1 fonts samples>");
            page.EndText();

            page.BeginText();
            page.MoveTextPos(60, height - 105);

            for (int i = 0; i < font_list.Length; i++)
            {
                const string samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
                HPdfFont     font      = pdf.GetFont(font_list[i], null);

                /* print a label of text */
                page.SetFontAndSize(def_font, 9);
                page.ShowText(font_list[i]);
                page.MoveTextPos(0, -18);

                /* print a sample text. */
                page.SetFontAndSize(font, 20);
                page.ShowText(samp_text);
                page.MoveTextPos(0, -20);
            }

            page.EndText();

            pdf.SaveToFile("FontDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }
Пример #10
0
    public static void Main()
    {
        Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());

        try {
            const int  PAGE_HEIGHT = 210;
            string     samp_text   = "アメンボ赤いなあいうえお。浮き藻に小エビもおよいでる。";
            HPdfFont[] detail_font = new HPdfFont[16];

            HPdfDoc pdf = new HPdfDoc();

            /*declaration for using Japanese font, encoding. */
            pdf.UseJPEncodings();
            pdf.UseJPFonts();

            detail_font[0] = pdf.GetFont("MS-Mincyo", "90ms-RKSJ-H");
            detail_font[1] = pdf.GetFont("MS-Mincyo,Bold", "90ms-RKSJ-H");
            detail_font[2] = pdf.GetFont("MS-Mincyo,Italic", "90ms-RKSJ-H");
            detail_font[3] = pdf.GetFont("MS-Mincyo,BoldItalic", "90ms-RKSJ-H");
            detail_font[4] = pdf.GetFont("MS-PMincyo", "90msp-RKSJ-H");
            detail_font[5] = pdf.GetFont("MS-PMincyo,Bold", "90msp-RKSJ-H");
            detail_font[6] = pdf.GetFont("MS-PMincyo,Italic", "90msp-RKSJ-H");
            detail_font[7] = pdf.GetFont("MS-PMincyo,BoldItalic",
                                         "90msp-RKSJ-H");
            detail_font[8]  = pdf.GetFont("MS-Gothic", "90ms-RKSJ-H");
            detail_font[9]  = pdf.GetFont("MS-Gothic,Bold", "90ms-RKSJ-H");
            detail_font[10] = pdf.GetFont("MS-Gothic,Italic", "90ms-RKSJ-H");
            detail_font[11] = pdf.GetFont("MS-Gothic,BoldItalic", "90ms-RKSJ-H");
            detail_font[12] = pdf.GetFont("MS-PGothic", "90msp-RKSJ-H");
            detail_font[13] = pdf.GetFont("MS-PGothic,Bold", "90msp-RKSJ-H");
            detail_font[14] = pdf.GetFont("MS-PGothic,Italic", "90msp-RKSJ-H");
            detail_font[15] = pdf.GetFont("MS-PGothic,BoldItalic",
                                          "90msp-RKSJ-H");

            /*configure pdf-document to be compressed. */
            pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);

            /*Set page mode to use outlines. */
            pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_USE_OUTLINE);

            /*create outline root. */
            HPdfOutline root = pdf.CreateOutline(null, "JP font demo", null);
            root.SetOpened(true);

            for (int i = 0; i <= 15; i++)
            {
                float x_pos;

                /*add a new page object. */
                HPdfPage page = pdf.AddPage();

                /*create outline entry */
                HPdfOutline outline = pdf.CreateOutline(root,
                                                        detail_font[i].GetFontName(), null);
                HPdfDestination dst = page.CreateDestination();
                outline.SetDestination(dst);

                HPdfFont title_font = pdf.GetFont("Helvetica", null);
                page.SetFontAndSize(title_font, 10);

                page.BeginText();

                /*move the position of the text to top of the page. */
                page.MoveTextPos(10, 190);
                page.ShowText(detail_font[i].GetFontName());

                page.SetFontAndSize(detail_font[i], 15);
                page.MoveTextPos(10, -20);
                page.ShowText("abcdefghijklmnopqrstuvwxyz");
                page.MoveTextPos(0, -20);
                page.ShowText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                page.MoveTextPos(0, -20);
                page.ShowText("1234567890");
                page.MoveTextPos(0, -20);

                page.SetFontAndSize(detail_font[i], 10);
                page.ShowText(samp_text);
                page.MoveTextPos(0, -18);

                page.SetFontAndSize(detail_font[i], 16);
                page.ShowText(samp_text);
                page.MoveTextPos(0, -27);

                page.SetFontAndSize(detail_font[i], 23);
                page.ShowText(samp_text);
                page.MoveTextPos(0, -36);

                page.SetFontAndSize(detail_font[i], 30);
                page.ShowText(samp_text);

                HPdfPoint p = page.GetCurrentTextPos();

                /*finish to print text. */
                page.EndText();

                page.SetLineWidth(0.5f);

                x_pos = 20;
                for (int j = 0; j <= samp_text.Length / 2; j++)
                {
                    page.MoveTo(x_pos, p.y - 10);
                    page.LineTo(x_pos, p.y - 12);
                    page.Stroke();
                    x_pos = x_pos + 30;
                }

                page.SetWidth(p.x + 20);
                page.SetHeight(PAGE_HEIGHT);

                page.MoveTo(10, PAGE_HEIGHT - 25);
                page.LineTo(p.x + 10, PAGE_HEIGHT - 25);
                page.Stroke();

                page.MoveTo(10, PAGE_HEIGHT - 85);
                page.LineTo(p.x + 10, PAGE_HEIGHT - 85);
                page.Stroke();

                page.MoveTo(10, p.y - 12);
                page.LineTo(p.x + 10, p.y - 12);
                page.Stroke();
            }

            pdf.SaveToFile("JPFontDemo.pdf");
        } catch (Exception e) {
            Console.Error.WriteLine(e.Message);
        }
    }