Example #1
0
    public Example_19()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_19.pdf", FileMode.Create)));

        // Font f1 = new Font(pdf, CoreFont.HELVETICA);
        // f1.SetSize(10f);

        Font f1 = new Font(pdf, new FileStream(
                               // "fonts/Droid/DroidSerif-Regular.ttf.stream",
                               "fonts/OpenSans/OpenSans-Regular.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        f1.SetSize(10f);

        Font f2 = new Font(pdf, new FileStream(
                               "fonts/Droid/DroidSansFallback.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        f2.SetSize(10f);

        Page page = new Page(pdf, Letter.PORTRAIT);

        // Columns x coordinates
        float x1 = 75f;
        float y1 = 75f;

        float x2 = 325f;

        // Width of the second column:
        float w2 = 200f;

        Image image1 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/fruit.jpg", FileMode.Open, FileAccess.Read)),
            ImageType.JPG);
        Image image2 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/ee-map.png", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);


        // Draw the first image and text:
        image1.SetLocation(x1, y1);
        image1.ScaleBy(0.75f);
        image1.DrawOn(page);


        TextBlock textBlock = new TextBlock(f1);

        textBlock.SetText("Geometry arose independently in a number of early cultures as a practical way for dealing with lengths, areas, and volumes.");
        textBlock.SetLocation(x2, y1);
        // textBlock.SetWidth(w2);
        textBlock.SetWidth(40f);
        textBlock.SetDrawBorder(true);
        // textBlock.SetTextAlignment(Align.LEFT);
        // textBlock.SetTextAlignment(Align.RIGHT);
        // textBlock.SetTextAlignment(Align.CENTER);
        float[] xy = textBlock.DrawOn(page);

        // Draw the second row image and text:
        image2.SetLocation(x1, xy[1] + 10f);
        image2.ScaleBy(1f / 3f);
        image2.DrawOn(page);

        textBlock = new TextBlock(f1);
        textBlock.SetText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum interdum elit, quis vehicula urna interdum quis. Phasellus gravida ligula quam, nec blandit nulla. Sed posuere, lorem eget feugiat placerat, ipsum nulla euismod nisi, in semper mi nibh sed elit. Mauris libero est, sodales dignissim congue sed, pulvinar non ipsum. Sed risus nisi, ultrices nec eleifend at, viverra sed neque. Integer vehicula massa non arcu viverra ullamcorper. Ut id tellus id ante mattis commodo. Donec dignissim aliquam tortor, eu pharetra ipsum ullamcorper in. Vivamus ultrices imperdiet iaculis.\n\n");
        textBlock.SetLocation(x2, xy[1] + 10f);
        textBlock.SetWidth(w2);
        textBlock.SetDrawBorder(true);
        textBlock.DrawOn(page);


        textBlock = new TextBlock(f1);
        textBlock.SetFallbackFont(f2);
        textBlock.SetText("保健所によると、女性は13日に旅行先のタイから札幌に戻り、16日午後5~8時ごろ同店を訪れ、帰宅後に発熱などの症状が出て、23日に医療機関ではしかと診断された。はしかのウイルスは発症日の1日前から感染者の呼吸などから放出され、本人がいなくなっても、2時間程度空気中に漂い、空気感染する。保健所は16日午後5~11時に同店を訪れた人に、発熱などの異常が出た場合、早期にマスクをして医療機関を受診するよう呼びかけている。(本郷由美子)");
        textBlock.SetLocation(x1, 600f);
        textBlock.SetWidth(350f);
        textBlock.SetDrawBorder(true);
        textBlock.DrawOn(page);

        pdf.Complete();
    }
Example #2
0
    public Example_78()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_78.pdf", FileMode.Create)));

        Font f1 = new Font(pdf, CoreFont.HELVETICA_BOLD);

        Font f2 = new Font(pdf, new FileStream(
                               "fonts/OpenSans/OpenSans-Regular.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read),
                           Font.STREAM);

        String       fileName = "linux-logo.png";
        EmbeddedFile file1    = new EmbeddedFile(
            pdf,
            fileName,
            new FileStream("images/" + fileName, FileMode.Open, FileAccess.Read),
            false);         // Don't compress images.

        fileName = "Example_02.cs";
        EmbeddedFile file2 = new EmbeddedFile(
            pdf,
            fileName,
            new FileStream(fileName, FileMode.Open, FileAccess.Read),
            true);          // Compress text files.

        Page page = new Page(pdf, Letter.PORTRAIT);

        f1.SetSize(10f);

        FileAttachment attachment = new FileAttachment(pdf, file1);

        attachment.SetLocation(0f, 0f);
        attachment.SetIconPushPin();
        attachment.SetTitle("Attached File: " + file1.GetFileName());
        attachment.SetDescription(
            "Right mouse click or double click on the icon to save the attached file.");
        float[] point = attachment.DrawOn(page);

        attachment = new FileAttachment(pdf, file2);
        attachment.SetLocation(0f, point[1]);
        attachment.SetIconPaperclip();
        attachment.SetTitle("Attached File: " + file2.GetFileName());
        attachment.SetDescription(
            "Right mouse click or double click on the icon to save the attached file.");
        point = attachment.DrawOn(page);


        CheckBox checkbox = new CheckBox(f1, "Hello");

        checkbox.SetLocation(0f, point[1]);
        checkbox.SetCheckmark(Color.blue);
        checkbox.Check(Mark.CHECK);
        point = checkbox.DrawOn(page);

        checkbox = new CheckBox(f1, "Hello");
        checkbox.SetLocation(0.0, point[1]);
        checkbox.SetCheckmark(Color.blue);
        checkbox.Check(Mark.X);
        point = checkbox.DrawOn(page);

        Box box = new Box();

        box.SetLocation(0f, point[1]);
        box.SetSize(20f, 20f);
        point = box.DrawOn(page);

        RadioButton radiobutton = new RadioButton(f1, "Yes");

        radiobutton.SetLocation(0f, point[1]);
        radiobutton.SetURIAction("http://pdfjet.com");
        radiobutton.Select(true);
        point = radiobutton.DrawOn(page);

        QRCode qr = new QRCode(
            "https://kazuhikoarase.github.io",
            ErrorCorrectLevel.L);       // Low

        qr.SetModuleLength(3f);
        qr.SetLocation(0f, point[1]);
        point = qr.DrawOn(page);

        Dictionary <String, Int32> colors = new Dictionary <String, Int32>();

        colors["brown"] = Color.brown;
        colors["fox"]   = Color.maroon;
        colors["lazy"]  = Color.darkolivegreen;
        colors["jumps"] = Color.darkviolet;
        colors["dog"]   = Color.chocolate;
        colors["sight"] = Color.blue;

        StringBuilder buf = new StringBuilder();

        buf.Append("The quick brown fox jumps over the lazy dog. What a sight!\n\n");

        TextBox textbox = new TextBox(f1, buf.ToString());

        textbox.SetLocation(0f, point[1]);
        // textbox.SetWidth(f1.StringWidth(buf.ToString()));
        textbox.SetBgColor(Color.whitesmoke);
        textbox.SetTextColors(colors);
        point = textbox.DrawOn(page);


        buf = new StringBuilder();
        buf.Append("Calculus, originally called infinitesimal calculus or \"the calculus of infinitesimals\", ");
        buf.Append("is the mathematical study of continuous change, in the same way that geometry is the ");
        buf.Append("study of shape and algebra is the study of generalizations of arithmetic operations. ");
        buf.Append("It has two major branches, differential calculus and integral calculus; ");
        buf.Append("the former concerns instantaneous rates of change, and the slopes of curves, ");
        buf.Append("while integral calculus concerns accumulation of quantities, and areas under or between ");
        buf.Append("curves. These two branches are related to each other by the fundamental theorem of calculus, ");
        buf.Append("and they make use of the fundamental notions of convergence of infinite sequences and ");
        buf.Append("infinite series to a well-defined limit.");

        TextBlock textBlock = new TextBlock(f1);

        textBlock.SetText(buf.ToString());
        textBlock.SetLocation(0f, point[1]);
        // textBlock.SetWidth(50f);
        point = textBlock.DrawOn(page);

        BarCode code = new BarCode(BarCode.CODE128, "Hello, World!");

        code.SetLocation(0f, point[1]);
        code.SetModuleLength(0.75f);
        code.SetFont(f1);
        point = code.DrawOn(page);

        buf = new StringBuilder();
        buf.Append("Using another font ...\n\nThis is a test.");
        textbox = new TextBox(f2, buf.ToString());
        textbox.SetLocation(0f, point[1]);
        point = textbox.DrawOn(page);

        code = new BarCode(BarCode.CODE128, "G86513JVW0C");
        code.SetLocation(0f, point[1]);
        code.SetModuleLength(0.75f);
        code.SetDirection(BarCode.TOP_TO_BOTTOM);
        code.SetFont(f1);
        point = code.DrawOn(page);

        buf = new StringBuilder();
        StreamReader reader = new StreamReader(
            new FileStream("Example_12.cs", FileMode.Open));
        String line = null;

        while ((line = reader.ReadLine()) != null)
        {
            buf.Append(line);
            // Both CR and LF are required by the scanner!
            buf.Append((char)13);
            buf.Append((char)10);
        }

        BarCode2D code2D = new BarCode2D(buf.ToString());

        code2D.SetModuleWidth(0.5f);
        code2D.SetLocation(0f, point[1]);
        point = code2D.DrawOn(page);

        pdf.Complete();
    }
Example #3
0
    public Example_50()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_50.pdf", FileMode.Create)));

        // Font f1 = new Font(pdf, CoreFont.HELVETICA);
        // f1.SetSize(10f);

        Font f1 = new Font(pdf, new FileStream(
                               "fonts/Droid/DroidSerif-Regular.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        f1.SetSize(10f);

        Font f2 = new Font(pdf, new FileStream(
                               "fonts/Droid/DroidSansFallback.ttf.stream",
                               FileMode.Open,
                               FileAccess.Read), Font.STREAM);

        f2.SetSize(10f);

        Page page = new Page(pdf, Letter.PORTRAIT);

        // Columns x coordinates
        float x1 = 75f;
        float x2 = 325f;

        float y1 = 75f;

        // Width of the second column:
        float w2 = 200f;

        Image image1 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/fruit.jpg", FileMode.Open, FileAccess.Read)),
            ImageType.JPG);

        image1.SetLocation(x1, y1);
        image1.ScaleBy(0.75f);
        image1.DrawOn(page);


        TextBlock textBlock = new TextBlock(f1);

        textBlock.SetText("Donec a urna ac ipsum fringilla ultricies non vel diam. Morbi vitae lacus ac elit luctus dignissim. Quisque rutrum egestas facilisis. Curabitur tempus, tortor ac fringilla fringilla, libero elit gravida sem, vel aliquam leo nibh sed libero. Proin pretium, augue quis eleifend hendrerit, leo libero auctor magna,\n\nvitae porttitor lorem urna eget urna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt venenatis odio in dignissim. Ut cursus egestas eros, ac blandit nisi ullamcorper a.");
        textBlock.SetLocation(x2, y1);
        textBlock.SetWidth(w2);
        // textBlock.SetTextAlignment(Align.LEFT);
        // textBlock.SetTextAlignment(Align.RIGHT);
        // textBlock.SetTextAlignment(Align.CENTER);

        // We can find out the height of the block before we draw it!
        float y2 = y1 + textBlock.GetHeight();

        // Diagnostics Code:
        // Line line = new Line(x2, y2, x2 + w2, y2);
        // line.SetWidth(0.2f);
        // line.DrawOn(page);

        y2 += 10f;   // Add a bit of space between the rows.

        textBlock.DrawOn(page);


        // Draw the second row image and text:
        Image image2 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/ee-map.png", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);

        image2.SetLocation(x1, y2);
        image2.ScaleBy(1f / 3f);
        image2.DrawOn(page);

        textBlock = new TextBlock(f1);
        textBlock.SetText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum interdum elit, quis vehicula urna interdum quis. Phasellus gravida ligula quam, nec blandit nulla. Sed posuere, lorem eget feugiat placerat, ipsum nulla euismod nisi, in semper mi nibh sed elit. Mauris libero est, sodales dignissim congue sed, pulvinar non ipsum. Sed risus nisi, ultrices nec eleifend at, viverra sed neque. Integer vehicula massa non arcu viverra ullamcorper. Ut id tellus id ante mattis commodo. Donec dignissim aliquam tortor, eu pharetra ipsum ullamcorper in. Vivamus ultrices imperdiet iaculis.\n\n");
        textBlock.SetWidth(w2);
        textBlock.SetLocation(x2, y2);
        textBlock.DrawOn(page);


        textBlock = new TextBlock(f1);
        textBlock.SetFallbackFont(f2);
        textBlock.SetText("保健所によると、女性は13日に旅行先のタイから札幌に戻り、16日午後5~8時ごろ同店を訪れ、帰宅後に発熱などの症状が出て、23日に医療機関ではしかと診断された。はしかのウイルスは発症日の1日前から感染者の呼吸などから放出され、本人がいなくなっても、2時間程度空気中に漂い、空気感染する。保健所は16日午後5~11時に同店を訪れた人に、発熱などの異常が出た場合、早期にマスクをして医療機関を受診するよう呼びかけている。(本郷由美子)");
        textBlock.SetWidth(350f);
        textBlock.SetLocation(x1, 600f);
        textBlock.DrawOn(page);


        pdf.Close();
    }