コード例 #1
0
    public Example_36()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_36.pdf", FileMode.Create)));

        Page page1 = new Page(pdf, A4.PORTRAIT, false);

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

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

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

        Image image3 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/mt-map.bmp", FileMode.Open, FileAccess.Read)),
            ImageType.BMP);

        TextLine text = new TextLine(f1,
                                     "The map below is an embedded PNG image");

        text.SetLocation(90f, 30f);
        text.DrawOn(page1);

        image1.SetLocation(90f, 40f);
        image1.ScaleBy(2f / 3f);
        image1.DrawOn(page1);

        text.SetText(
            "JPG image file embedded once and drawn 3 times");
        text.SetLocation(90f, 550f);
        text.DrawOn(page1);

        image2.SetLocation(90f, 560f);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page1);

        image2.SetLocation(260f, 560f);
        image2.ScaleBy(0.5f);
        image2.SetRotateCW90(true);
        image2.DrawOn(page1);

        image2.SetLocation(350f, 560f);
        image2.SetRotateCW90(false);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page1);

        image3.SetLocation(390f, 630f);
        image3.ScaleBy(0.5f);
        image3.DrawOn(page1);

        Page page2 = new Page(pdf, A4.PORTRAIT, false);

        image1.DrawOn(page2);

        text.SetText("Hello, World!!");
        text.SetLocation(90f, 800f);
        text.DrawOn(page2);

        text.SetText(
            "The map on the right is an embedded BMP image");
        text.SetUnderline(true);
        text.SetStrikeout(true);
        text.SetTextDirection(15);
        text.SetLocation(90f, 800f);
        text.DrawOn(page1);

        pdf.AddPage(page2);
        pdf.AddPage(page1);

        pdf.Complete();
    }
コード例 #2
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);

        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();

        List <Page> pages = new List <Page>();

        table.DrawOn(pdf, pages, A4.PORTRAIT);
        foreach (Page page in pages)
        {
            pdf.AddPage(page);
        }

        pdf.Complete();
    }
コード例 #3
0
    public Example_08()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_08.pdf", FileMode.Create)), Compliance.PDF_A_1B);

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

        f1.SetSize(7f);

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

        f2.SetSize(7f);

        Font f3 = new Font(pdf, CoreFont.HELVETICA_BOLD_OBLIQUE);

        f3.SetSize(7f);

/* TODO:
 *      Font f1 = new Font(pdf,
 *              getClass().getResourceAsStream("fonts/OpenSans/OpenSans-Bold.ttf.stream"),
 *              Font.STREAM);
 *      f1.setSize(7f);
 *
 *      Font f2 = new Font(pdf,
 *              getClass().getResourceAsStream("fonts/OpenSans/OpenSans-Regular.ttf.stream"),
 *              Font.STREAM);
 *      f2.setSize(7f);
 *
 *      Font f3 = new Font(pdf,
 *              getClass().getResourceAsStream("fonts/OpenSans/OpenSans-BoldItalic.ttf.stream"),
 *              Font.STREAM);
 *      f3.setSize(7f);
 */
        image1 = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/fruit.jpg", FileMode.Open, FileAccess.Read)),
            ImageType.JPG);
        image1.ScaleBy(0.20f);

        barCode = new BarCode(BarCode.CODE128, "Hello, World!");
        barCode.SetModuleLength(0.75f);
        // Uncomment the line below if you want to print the text underneath the barcode.
        // barCode.SetFont(f1);

        Table table = new Table();
        List <List <Cell> > tableData = GetData(
            "data/world-communications.txt", "|", Table.DATA_HAS_2_HEADER_ROWS, f1, f2);

        table.SetData(tableData, Table.DATA_HAS_2_HEADER_ROWS);
        table.RemoveLineBetweenRows(0, 1);
        table.SetLocation(100f, 0f);
        table.SetRightMargin(20f);
        table.SetBottomMargin(0f);
        table.SetCellBordersWidth(0f);
        table.SetTextColorInRow(12, Color.blue);
        table.SetTextColorInRow(13, Color.red);
        table.GetCellAt(13, 0).GetTextBlock().SetURIAction("http://pdfjet.com");
        table.SetFontInRow(14, f3);
        table.GetCellAt(21, 0).SetColSpan(6);
        table.GetCellAt(21, 6).SetColSpan(2);

        // Set the column widths manually:
        // table.SetColumnWidth(0, 70f);
        // table.SetColumnWidth(1, 50f);
        // table.SetColumnWidth(2, 70f);
        // table.SetColumnWidth(3, 70f);
        // table.SetColumnWidth(4, 70f);
        // table.SetColumnWidth(5, 70f);
        // table.SetColumnWidth(6, 50f);
        // table.SetColumnWidth(7, 50f);

        // Auto adjust the column widths to be just wide enough to fit the text without truncation.
        // Columns with colspan > 1 will not be adjusted.
        // table.AutoAdjustColumnWidths();

        // Auto adjust the column widths in a way that allows the table to fit perfectly on the page.
        // Columns with colspan > 1 will not be adjusted.
        table.FitToPage(Letter.PORTRAIT);

        List <Page> pages = new List <Page>();

        table.DrawOn(pdf, pages, Letter.PORTRAIT);
        for (int i = 0; i < pages.Count; i++)
        {
            Page page = pages[i];
            // page.AddFooter(new TextLine(f1, "Page " + (i + 1) + " of " + pages.Count));
            pdf.AddPage(page);
        }

        pdf.Complete();
    }
コード例 #4
0
    public Example_34()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_34.pdf", FileMode.Create)), Compliance.PDF_A_1B);

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

        f1.SetSize(7f);

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

        f2.SetSize(7f);

        Font f3 = new Font(pdf, CoreFont.HELVETICA_BOLD_OBLIQUE);

        f3.SetSize(7f);


        Table table = new Table();
        List <List <Cell> > tableData = GetData(
            "data/world-communications.txt", "|", Table.DATA_HAS_2_HEADER_ROWS, f1, f2);

        Point p1 = new Point();

        p1.SetShape(Point.CIRCLE);
        p1.SetRadius(2f);
        p1.SetColor(Color.darkolivegreen);
        p1.SetFillShape(true);
        p1.SetAlignment(Align.RIGHT);
        p1.SetURIAction("https://en.wikipedia.org/wiki/India");
        tableData[4][3].SetPoint(p1);

        p1 = new Point();
        p1.SetShape(Point.DIAMOND);
        p1.SetRadius(2.5f);
        p1.SetColor(Color.blue);
        p1.SetFillShape(true);
        p1.SetAlignment(Align.RIGHT);
        p1.SetURIAction("https://en.wikipedia.org/wiki/European_Union");
        tableData[5][3].SetPoint(p1);

        p1 = new Point();
        p1.SetShape(Point.STAR);
        p1.SetRadius(3f);
        p1.SetColor(Color.red);
        p1.SetFillShape(true);
        p1.SetAlignment(Align.RIGHT);
        p1.SetURIAction("https://en.wikipedia.org/wiki/United_States");
        tableData[6][3].SetPoint(p1);

        table.SetData(tableData, Table.DATA_HAS_2_HEADER_ROWS);
        table.RemoveLineBetweenRows(0, 1);
        table.SetLocation(0f, 0f);
        table.SetFirstPageTopMargin(50f);
        // table.SetRightMargin(175f);
        table.SetBottomMargin(0f);
        table.SetCellBordersWidth(0.2f);
        table.SetTextColorInRow(6, Color.blue);
        table.SetTextColorInRow(39, Color.red);
        table.SetFontInRow(26, f3);
        table.RightAlignNumbers();
        table.FitToPage(Letter.PORTRAIT);

        List <Page> pages = new List <Page>();

        table.DrawOn(pdf, pages, Letter.PORTRAIT);
        for (int i = 0; i < pages.Count; i++)
        {
            Page page = pages[i];
            // page.AddFooter(new TextLine(f1, "Page " + (i + 1) + " of " + pages.Count));
            pdf.AddPage(page);
        }

        pdf.Complete();
    }