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

        Font f1 = new Font(pdf, CoreFont.HELVETICA);
        Font f2 = new Font(pdf, CoreFont.HELVETICA_BOLD);
        Font f3 = new Font(pdf, CoreFont.HELVETICA);
        Font f4 = new Font(pdf, CoreFont.HELVETICA_BOLD);
        Font f5 = new Font(pdf, CoreFont.HELVETICA);
        Font f6 = new Font(pdf, CoreFont.HELVETICA_BOLD);

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

        CompositeTextLine composite = new CompositeTextLine(50f, 50f);

        composite.SetFontSize(14f);

        TextLine text1 = new TextLine(f1, "C");
        TextLine text2 = new TextLine(f2, "6");
        TextLine text3 = new TextLine(f3, "H");
        TextLine text4 = new TextLine(f4, "12");
        TextLine text5 = new TextLine(f5, "O");
        TextLine text6 = new TextLine(f6, "6");

        text1.SetColor(Color.dodgerblue);
        text3.SetColor(Color.dodgerblue);
        text5.SetColor(Color.dodgerblue);

        text2.SetTextEffect(Effect.SUBSCRIPT);
        text4.SetTextEffect(Effect.SUBSCRIPT);
        text6.SetTextEffect(Effect.SUBSCRIPT);

        composite.AddComponent(text1);
        composite.AddComponent(text2);
        composite.AddComponent(text3);
        composite.AddComponent(text4);
        composite.AddComponent(text5);
        composite.AddComponent(text6);

        float[] xy = composite.DrawOn(page);

        Box box = new Box();

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

        CompositeTextLine composite2 = new CompositeTextLine(50f, 100f);

        composite2.SetFontSize(14f);

        text1 = new TextLine(f1, "SO");
        text2 = new TextLine(f2, "4");
        text3 = new TextLine(f4, "2-"); // Use bold font here

        text2.SetTextEffect(Effect.SUBSCRIPT);
        text3.SetTextEffect(Effect.SUPERSCRIPT);

        composite2.AddComponent(text1);
        composite2.AddComponent(text2);
        composite2.AddComponent(text3);

        composite2.DrawOn(page);
        composite2.SetLocation(100f, 150f);
        composite2.DrawOn(page);

        float[] yy    = composite2.GetMinMax();
        Line    line1 = new Line(50f, yy[0], 200f, yy[0]);
        Line    line2 = new Line(50f, yy[1], 200f, yy[1]);

        line1.DrawOn(page);
        line2.DrawOn(page);

        pdf.Complete();
    }
    public Example_23()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_23.pdf", FileMode.Create)));

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

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

        f3.SetSize(7f * 0.583f);

        List <List <Cell> > tableData = new List <List <Cell> >();

        List <Cell> row  = new List <Cell>();
        Cell        cell = new Cell(f1, "Hello");

        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "World");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "Next Column");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "CompositeTextLine");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);

        row.Add(cell);

        tableData.Add(row);

        row  = new List <Cell>();
        cell = new Cell(f2, "This is a test:");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        cell = new Cell(f2,
                        "Here we are going to test the WrapAroundCellText method.\n\nWe will create a table and place it near the bottom of the page. When we draw this table the text will wrap around the column edge and stay within the column.\n\nSo - let's  see how this is working?");
        cell.SetColSpan(2);
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        row.Add(new Cell(f2));  // We need an empty cell here because the previous cell had colSpan == 2
        cell = new Cell(f2, "Test 456");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        tableData.Add(row);

        row = new List <Cell>();
        row.Add(new Cell(f2,
                         "Another row.\n\n\nMake sure that this line of text will be wrapped around correctly too."));
        row.Add(new Cell(f2, "Yahoo!"));
        row.Add(new Cell(f2, "Test 789"));

        CompositeTextLine composite = new CompositeTextLine(0f, 0f);

        composite.SetFontSize(12f);
        TextLine line1 = new TextLine(f1, "Composite Text Line");
        TextLine line2 = new TextLine(f3, "Superscript");
        TextLine line3 = new TextLine(f3, "Subscript");

        line2.SetTextEffect(Effect.SUPERSCRIPT);
        line3.SetTextEffect(Effect.SUBSCRIPT);
        composite.AddComponent(line1);
        composite.AddComponent(line2);
        composite.AddComponent(line3);

        cell = new Cell(f2);
        cell.SetCompositeTextLine(composite);
        cell.SetBgColor(Color.peachpuff);
        row.Add(cell);

        tableData.Add(row);

        Table table = new Table();

        table.SetData(tableData, Table.DATA_HAS_1_HEADER_ROWS);
        // table.SetLocation(70f, 730f);
        table.SetLocation(70f, 70f);
        table.SetColumnWidth(0, 100f);
        table.SetColumnWidth(1, 100f);
        table.SetColumnWidth(2, 100f);
        table.SetColumnWidth(3, 150f);
        table.WrapAroundCellText();

        int numOfPages = table.GetNumberOfPages(page);

        while (true)
        {
            table.DrawOn(page);
            if (!table.HasMoreData())
            {
                break;
            }
            page = new Page(pdf, Letter.PORTRAIT);
            table.SetLocation(70f, 30f);
        }

        pdf.Close();
    }
Beispiel #3
0
    public Example_23()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_23.pdf", FileMode.Create)));

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

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

        f3.SetSize(7f * 0.583f);

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

        image1.ScaleBy(0.75f);

        List <List <Cell> > tableData = new List <List <Cell> >();

        List <Cell> row  = new List <Cell>();
        Cell        cell = new Cell(f1, "Hello");

        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "World");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "Next Column");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);

        cell = new Cell(f1, "CompositeTextLine");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);

        row.Add(cell);

        tableData.Add(row);

        row  = new List <Cell>();
        cell = new Cell(f2, "This is a test:");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        cell = new Cell(f2,
                        "Here we are going to test the WrapAroundCellText method.\n\nWe will create a table and place it near the bottom of the page. When we draw this table the text will wrap around the column edge and stay within the column.\n\nSo - let's  see how this is working?");
        cell.SetColSpan(2);
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        row.Add(new Cell(f2));  // We need an empty cell here because the previous cell had colSpan == 2
        cell = new Cell(f2, "Test 456");
        cell.SetTopPadding(5f);
        cell.SetBottomPadding(5f);
        row.Add(cell);
        tableData.Add(row);

        row = new List <Cell>();
        row.Add(new Cell(f2,
                         "Another row.\n\n\nMake sure that this line of text will be wrapped around correctly too."));
        row.Add(new Cell(f2, "Yahoo!"));
        row.Add(new Cell(f2, "Test 789"));

        CompositeTextLine composite = new CompositeTextLine(0f, 0f);

        composite.SetFontSize(12f);
        TextLine line1 = new TextLine(f1, "Composite Text Line");
        TextLine line2 = new TextLine(f3, "Superscript");
        TextLine line3 = new TextLine(f3, "Subscript");

        line2.SetTextEffect(Effect.SUPERSCRIPT);
        line3.SetTextEffect(Effect.SUBSCRIPT);
        composite.AddComponent(line1);
        composite.AddComponent(line2);
        composite.AddComponent(line3);

        cell = new Cell(f2);
        cell.SetCompositeTextLine(composite);
        cell.SetBgColor(Color.peachpuff);
        row.Add(cell);

        tableData.Add(row);

        Table table = new Table();

        table.SetData(tableData, Table.DATA_HAS_1_HEADER_ROWS);
        table.SetLocation(50f, 50f);
        table.SetColumnWidth(0, 100f);
        table.SetColumnWidth(1, 100f);
        table.SetColumnWidth(2, 100f);
        table.SetColumnWidth(3, 150f);
        table.WrapAroundCellText();

        int numOfPages = table.GetNumberOfPages(page);

        while (true)
        {
            table.DrawOn(page);
            if (!table.HasMoreData())
            {
                break;
            }
            page = new Page(pdf, Letter.PORTRAIT);
            table.SetLocation(50f, 50f);
        }


        tableData = new List <List <Cell> >();

        row = new List <Cell>();
        row.Add(new Cell(f1));
        row.Add(new Cell(f2));
        tableData.Add(row);

        row = new List <Cell>();
        row.Add(new Cell(f1, "Hello, World!"));
        row.Add(new Cell(f2, "This is a test."));
        tableData.Add(row);

        tableData[0][0].SetImage(image1);

        table = new Table();
        table.SetData(tableData);
        table.SetLocation(50f, 450f);
        table.SetColumnWidth(0, 260f);
        table.SetColumnWidth(1, 260f);

        StringBuilder buf = new StringBuilder();

        buf.Append("Name: 20200306_050741\n");
        buf.Append("Recorded: 2018:09:28 18:28:43\n");

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

        textBox.SetWidth(400f);
        textBox.SetNoBorders();

        tableData[0][1].SetDrawable(textBox);

        table.DrawOn(page);

        pdf.Complete();
    }
Beispiel #4
0
    public Example_15()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_15.pdf", FileMode.Create)));

        Font f1 = new Font(pdf, CoreFont.HELVETICA_BOLD);
        Font f2 = new Font(pdf, CoreFont.HELVETICA);
        Font f3 = new Font(pdf, CoreFont.HELVETICA);
        Font f4 = new Font(pdf, CoreFont.HELVETICA_BOLD);
        Font f5 = new Font(pdf, CoreFont.HELVETICA);

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

        List <List <Cell> > tableData = new List <List <Cell> >();
        List <Cell>         row       = null;
        Cell cell = null;

        for (int i = 0; i < 60; i++)
        {
            row = new List <Cell>();
            for (int j = 0; j < 5; j++)
            {
                if (i == 0)
                {
                    cell = new Cell(f1);
                }
                else
                {
                    cell = new Cell(f2);
                }

                cell.SetTopPadding(10f);
                cell.SetBottomPadding(10f);
                cell.SetLeftPadding(10f);
                cell.SetRightPadding(10f);

                //  cell.SetNoBorders();
                cell.SetText("Hello " + i + " " + j);

                CompositeTextLine composite = new CompositeTextLine(0f, 0f);
                composite.SetFontSize(12.0f);
                TextLine line1 = new TextLine(f3, "H");
                TextLine line2 = new TextLine(f4, "2");
                TextLine line3 = new TextLine(f5, "O");
                line2.SetTextEffect(Effect.SUBSCRIPT);
                composite.AddComponent(line1);
                composite.AddComponent(line2);
                composite.AddComponent(line3);

                if (i == 0 || j == 0)
                {
                    cell.SetCompositeTextLine(composite);
                    cell.SetBgColor(Color.deepskyblue);
                }
                else
                {
                    cell.SetBgColor(Color.dodgerblue);
                }
                cell.SetPenColor(Color.lightgray);
                cell.SetBrushColor(Color.black);
                row.Add(cell);
            }
            tableData.Add(row);
        }

        Table table = new Table();

        table.SetData(tableData, Table.DATA_HAS_2_HEADER_ROWS);
        table.SetCellBordersWidth(0.2f);
        table.SetLocation(70f, 30f);
        table.AutoAdjustColumnWidths();

        while (true)
        {
            Point    point = table.DrawOn(page);
            TextLine text  = new TextLine(f1, "Hello, World.");
            text.SetLocation(point.GetX() + table.GetWidth(), point.GetY());
            text.DrawOn(page);

            if (!table.HasMoreData())
            {
                break;
            }
            page = new Page(pdf, A4.PORTRAIT);
        }

        pdf.Close();
    }