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

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

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

        Box flag = new Box();
        flag.SetPosition(100.0, 100.0);
        flag.SetSize(190.0, 100.0);
        flag.SetColor(RGB.WHITE);
        flag.DrawOn(page);

        double sw = 7.69;   // stripe width
        Line stripe = new Line(0.0, sw/2, 190.0, sw/2);
        stripe.SetWidth(sw);
        stripe.SetColor(RGB.OLD_GLORY_RED);
        for (int row = 0; row < 7; row++) {
            stripe.PlaceIn(flag, 0.0, row * 2 * sw);
            stripe.DrawOn(page);
        }

        Box union = new Box();
        union.SetSize(76.0, 53.85);
        union.SetColor(RGB.OLD_GLORY_BLUE);
        union.SetFillShape(true);
        union.PlaceIn(flag, 0.0, 0.0);
        union.DrawOn(page);

        double h_si = 12.6; // horizontal star interval
        double v_si = 10.8; // vertical star interval
        Point star = new Point(h_si/2, v_si/2);
        star.SetShape(Point.STAR);
        star.SetRadius(3.0);
        star.SetColor(RGB.WHITE);
        star.SetFillShape(true);

        for (int row = 0; row < 6; row++) {
            for (int col = 0; col < 5; col++) {
                star.PlaceIn(union, row * h_si, col * v_si);
                star.DrawOn(page);
            }
        }
        star.SetPosition(h_si, v_si);
        for (int row = 0; row < 5; row++) {
            for (int col = 0; col < 4; col++) {
                star.PlaceIn(union, row * h_si, col * v_si);
                star.DrawOn(page);
            }
        }

        pdf.Flush();
        bos.Close();
    }
コード例 #2
0
    public Example_04()
    {
        String fileName = "data/happy-new-year.txt";

        FileStream fos = new FileStream("Example_04.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        Font f1 = new Font(
                pdf,
                "AdobeMingStd-Light",       // Chinese (Traditional) font
                CodePage.UNICODE);
        Font f2 = new Font(
                pdf,
                "AdobeSongStd-Light",       // Chinese (Simplified) font
                CodePage.UNICODE);
        Font f3 = new Font(
                pdf,
                "KozMinProVI-Regular",      // Japanese font
                CodePage.UNICODE);
        Font f4 = new Font(
                pdf,
                "AdobeMyungjoStd-Medium",   // Korean font
                CodePage.UNICODE);

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

        f1.SetSize(14);
        f2.SetSize(14);
        f3.SetSize(14);
        f4.SetSize(14);

        double x_pos = 100.0;
        double y_pos = 20.0;
        StreamReader reader = new StreamReader(
                new FileStream(fileName, FileMode.Open));
        TextLine text = new TextLine(f1);
        String line = null;
        while ((line = reader.ReadLine()) != null) {
            if (line.IndexOf("Simplified") != -1) {
                text.SetFont(f2);
            } else if (line.IndexOf("Japanese") != -1) {
                text.SetFont(f3);
            } else if (line.IndexOf("Korean") != -1) {
                text.SetFont(f4);
            }
            text.SetText(line);
            text.SetPosition(x_pos, y_pos += 24);
            text.DrawOn(page);
        }
        reader.Close();

        pdf.Flush();
        bos.Close();
    }
コード例 #3
0
    public Example_08()
    {
        FileStream fos = new FileStream("Example_08.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        // Before you enable this flag please read README.ZLIB.TXT
        // in the 'optional' directory.

        Font f1 = new Font(pdf, "Helvetica-Bold");
        f1.SetSize(7.0);
        Font f2 = new Font(pdf, "Helvetica");
        f2.SetSize(7.0);
        Font f3 = new Font(pdf, "Helvetica-BoldOblique");
        f3.SetSize(7.0);

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

        Table table = new Table(f1, f2);
        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.SetLineWidth(0.2);
        table.SetPosition(70.0, 30.0);
        table.SetTextColorInRow(6, RGB.BLUE);
        table.SetTextColorInRow(39, RGB.RED);
        table.SetTextFontInRow(26, f3, 7);
        table.RemoveLineBetweenRows(0, 1);
        table.AutoAdjustColumnWidths();
        table.SetColumnWidth(0, 120);
        table.RightAlignNumbers();
        int numOfPages = table.GetNumberOfPages(page);
        while (true) {
            table.DrawOn(page);
            // TO DO: Draw "Page 1 of N" here
            if (!table.HasMoreData()) break;
            page = new Page(pdf, Letter.PORTRAIT);
        }

        pdf.Flush();
        bos.Close();
    }
コード例 #4
0
    public Example_02()
    {
        FileStream fos = new FileStream("Example_02.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

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

        Box flag = new Box(85, 85, 64, 32);

        PDFjet.NET.Path path = new PDFjet.NET.Path();
        path.Add(new Point(13.0,  0.0));
        path.Add(new Point(15.5,  4.5));
        path.Add(new Point(18.0,  3.5));

        path.Add(new Point(15.5, 13.5, Point.IS_CURVE_POINT));
        path.Add(new Point(15.5, 13.5, Point.IS_CURVE_POINT));
        path.Add(new Point(20.5,  7.5, Point.IS_CURVE_POINT));

        path.Add(new Point(21.0,  9.5));
        path.Add(new Point(25.0,  9.0));
        path.Add(new Point(24.0, 13.0));
        path.Add(new Point(25.5, 14.0));
        path.Add(new Point(19.0, 19.0));
        path.Add(new Point(20.0, 21.5));
        path.Add(new Point(13.5, 20.5));
        path.Add(new Point(13.5, 27.0));
        path.Add(new Point(12.5, 27.0));
        path.Add(new Point(12.5, 20.5));
        path.Add(new Point( 6.0, 21.5));
        path.Add(new Point( 7.0, 19.0));
        path.Add(new Point( 0.5, 14.0));
        path.Add(new Point( 2.0, 13.0));
        path.Add(new Point( 1.0,  9.0));
        path.Add(new Point( 5.0,  9.5));
        path.Add(new Point( 5.5,  7.5));

        path.Add(new Point(10.5, 13.5, Point.IS_CURVE_POINT));
        path.Add(new Point(10.5, 13.5, Point.IS_CURVE_POINT));
        path.Add(new Point( 8.0,  3.5, Point.IS_CURVE_POINT));

        path.Add(new Point(10.5,  4.5));
        path.setClosePath(true);
        path.SetColor(RGB.RED);
        path.SetFillShape(true);
        path.PlaceIn(flag, 19.0, 3.0);
        path.DrawOn(page);

        Box box = new Box();
        box.SetSize(16, 32);
        box.SetColor(RGB.RED);
        box.SetFillShape(true);
        box.PlaceIn(flag, 0.0, 0.0);
        box.DrawOn(page);
        box.PlaceIn(flag, 48.0, 0.0);
        box.DrawOn(page);

        path.ScaleBy(15.0);
        path.SetFillShape(false);
        path.DrawOn(page);

        pdf.Flush();
        bos.Close();
    }
コード例 #5
0
    public Example_03()
    {
        FileStream fos = new FileStream("Example_03.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        // Before you enable this flag please read README.ZLIB.TXT
        // in the 'optional' directory.

        //        Font f1 = new Font(pdf, "Helvetica");
        /*
        Font f1 = new Font(pdf, new FileStream(
                "fonts/DroidFonts/DroidSans.otf", FileMode.Open),
                CodePage.UNICODE,
                Embed.YES);
        */
        String fileName = "images/eu-map.png";
        FileStream fis1 = new FileStream(fileName, FileMode.Open);
        Image image1 = new Image(pdf, fis1, ImageType.PNG);

        fileName = "images/fruit.jpg";
        FileStream fis2 = new FileStream(fileName, FileMode.Open);
        Image image2 = new Image(pdf, fis2, ImageType.JPEG);

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

        Page page = new Page(pdf, A4.PORTRAIT);
        /*
        TextLine text = new TextLine(f1,
                "The map below is an embedded PNG image");
        text.SetPosition(90, 30);
        text.DrawOn(page);
        */
        image1.SetPosition(90, 40);
        image1.DrawOn(page);
        /*
        text.SetText(
                "JPG image file embedded once and drawn 3 times");
        text.SetPosition(90, 550);
        text.DrawOn(page);
        */
        image2.SetPosition(90, 560);
        image2.ScaleBy(0.5);
        image2.DrawOn(page);

        image2.SetPosition(260, 560);
        image2.ScaleBy(0.5);
        image2.DrawOn(page);

        image2.SetPosition(350, 560);
        image2.ScaleBy(0.5);
        image2.DrawOn(page);
        /*
        text.SetText(
                "The map on the right is an embedded BMP image");
        text.SetUnderline(true);
        text.SetStrikeLine(true);
        text.SetTextDirection(15);
        text.SetPosition(90, 800);
        text.DrawOn(page);
        */
        image3.SetPosition(390, 630);
        image3.ScaleBy(0.5);
        image3.DrawOn(page);

        pdf.Flush();
        bos.Close();
    }
コード例 #6
0
    public Example_05()
    {
        FileStream fos = new FileStream("Example_05.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        // Before you enable this flag please read README.ZLIB.TXT
        // in the 'optional' directory.

        // If PDF/A is not required use Helvetica, TimesRoman or Courier
        Font f1 = new Font(pdf, "Helvetica");

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

        TextLine text = new TextLine(f1);
        text.SetPosition(300.0, 300.0);
        for (int i = 0; i < 360; i += 15) {
            text.SetTextDirection(i);
            text.SetUnderline(true);
            // text.SetStrikeLine(true);
            text.SetText("             Hello, World -- " + i + " degrees.");
            text.DrawOn(page);
        }

        text = new TextLine(f1, "WAVE AWAY");
        text.SetPosition(70.0, 50.0);
        text.DrawOn(page);

        f1.SetKernPairs(true);
        text.SetPosition(70.0, 70.0);
        text.DrawOn(page);

        f1.SetKernPairs(false);
        text.SetPosition(70.0, 90.0);
        text.DrawOn(page);

        f1.SetSize(8);
        text = new TextLine(f1, "-- font.SetKernPairs(false);");
        text.SetPosition(150.0, 50.0);
        text.DrawOn(page);
        text.SetPosition(150.0, 90.0);
        text.DrawOn(page);
        text = new TextLine(f1, "-- font.SetKernPairs(true);");
        text.SetPosition(150.0, 70.0);
        text.DrawOn(page);

        Point point = new Point(300.0, 300.0);
        point.SetShape(Point.CIRCLE);
        point.SetFillShape(true);
        point.SetColor(RGB.BLUE);
        point.SetRadius(37.0);
        point.DrawOn(page);
        point.SetRadius(25.0);
        point.SetColor(RGB.WHITE);
        point.DrawOn(page);

        pdf.Flush();
        bos.Close();
    }
コード例 #7
0
    public Example_13()
    {
        FileStream fos = new FileStream("Example_13.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        Font f1 = new Font(pdf, "Helvetica-Bold");
        Font f2 = new Font(pdf, "Helvetica");
        f1.SetSize(7.0);
        f2.SetSize(7.0);

        List<List<Cell>> tableData = new List<List<Cell>>();
        StreamReader reader = new StreamReader(
                new FileStream("data/winter-2009.txt", FileMode.Open));
        String line;
        while (( line = reader.ReadLine()) != null) {
            List<Cell> row = new List<Cell>();
            String[] columns = line.Split(new Char[] {'|'});
            for ( int i = 0; i < columns.Length; i++ ) {
                row.Add(new Cell(f2, columns[i]));
            }
            tableData.Add(row);
        }
        reader.Close();

        Table table = new Table(f1, f2);
        table.SetData(tableData, Table.DATA_HAS_2_HEADER_ROWS);
        table.SetPosition(100.0, 50.0);
        table.setCellMargin(2.0);

        table.RemoveLineBetweenRows(0, 1);

        Cell cell3 = table.GetCellAt(1, 1);
        cell3.border.top = true;

        cell3 = table.GetCellAt(1, 2);
        cell3.border.top = true;

        SetFontForRow(table, 0, f1);
        SetFontForRow(table, 1, f1);

        table.AutoAdjustColumnWidths();

        List<Cell> column = table.GetColumn(7);
        for ( int i = 0; i < column.Count; i++ ) {
            Cell cell = column[i];
            cell.SetTextAlignment(Align.CENTER);
        }

        column = table.GetColumn(4);
        for ( int i = 2; i < column.Count; i++ ) {
            Cell cell = column[i];
            try {
                cell.SetTextAlignment(Align.CENTER);
                if ( Int32.Parse( cell.GetText()) > 40 ) {
                    cell.SetBgColor( new double[] { 0.0, 0.85, 0.0 } );
                } else {
                    cell.SetBgColor( new double[] { 1.0, 1.0, 0.0 } );
                }
            }
            catch (Exception e) {
                Console.WriteLine(e);
            }
        }

        Cell cell2 = table.GetCellAt(0, 1);
        cell2.SetColSpan( 2 );
        cell2.SetTextAlignment(Align.CENTER);

        SetBgColorForRow(table, 0, new double[] { 0.85, 0.85, 0.85 });
        SetBgColorForRow(table, 1, new double[] { 0.85, 0.85, 0.85 });

        table.SetColumnWidth(3, 10);
        blankOutColumn(table, 3);

        table.SetColumnWidth(8, 10);
        blankOutColumn(table, 8);

        Page page = new Page(pdf, Letter.PORTRAIT);
        int numOfPages = table.GetNumberOfPages(page);
        int pageNumber = 1;
        while (true) {
            table.DrawOn(page);

            TextLine text = new TextLine(f1);
            text.SetText("Page " + pageNumber++ + " of " + numOfPages);
            text.SetPosition(300.0, 780.0);
            text.DrawOn(page);

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

        pdf.Flush();
        bos.Close();
    }