예제 #1
0
    private static void ShowDescription(HPdfPage page, float x, float y,
                                        string text)
    {
        string buf;

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

        page.SetFontAndSize(page.GetCurrentFont(), 8);
        page.SetRGBFill(0, 0, 0);

        page.BeginText();

        buf = "(x=" + x + ",y=" + y + ")";
        page.MoveTextPos(x - page.TextWidth(buf) - 5,
                         y - 10);
        page.ShowText(buf);
        page.EndText();

        page.BeginText();
        page.MoveTextPos(x - 20, y - 25);
        page.ShowText(text);
        page.EndText();
    }
예제 #2
0
    private static void DrawLine2(HPdfPage page, float x, float y, string label)
    {
        page.BeginText();
        page.MoveTextPos(x, y);
        page.ShowText(label);
        page.EndText();

        page.MoveTo(x + 30, y - 25);
        page.LineTo(x + 160, y - 25);
        page.Stroke();
    }
예제 #3
0
        private static void ShowStripePattern(HPdfPage page, float x, float y)
        {
            var iy = 0;

            while (iy < 50)
            {
                page.SetRGBStroke(0.0f, 0.0f, 0.5f);
                page.SetLineWidth(1);
                page.MoveTo(x, y + iy);
                page.LineTo(x + page.TextWidth("ABCabc123"),
                            y + iy);
                page.Stroke();
                iy += 3;
            }

            page.SetLineWidth(2.5f);
        }
예제 #4
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);
        }
    }
예제 #5
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);
        }
    }