コード例 #1
0
    public Example_19()
    {
        try {

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

            PDF pdf = new PDF( bos );

            FileStream fis = new FileStream( "Example_03.pdf", FileMode.Open );

            // FileInputStream fis = new FileInputStream( "PDF32000_2008.pdf" );

            BufferedStream bis = new BufferedStream( fis );
            List< PDFobj > objects = pdf.read(bis);
            for ( int j = 0; j < objects.Count; j++ ) {
                PDFobj obj = ( PDFobj ) objects[j];
                for ( int i = 0; i < obj.dict.Count; i++ ) {
                    Console.WriteLine(obj.dict[i]);
                }
                Console.WriteLine();
            }
            bis.Close();

            pdf.Flush();
            bos.Close();
        }
        catch ( Exception e ) {
            Console.WriteLine(e.StackTrace);
        }
    }
コード例 #2
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();
    }
コード例 #3
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();
    }
コード例 #4
0
ファイル: Accounting_Checks.cs プロジェクト: weavver/data
        //-------------------------------------------------------------------------------------------
        /// <summary>
        /// This method generates a PDF copy of the check to be printed on standard 3 sheet check paper.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="invoice"></param>
        /// <returns>Returns the path to the PDF file on the local file system.</returns>
        public string GeneratePDF()
        {
            string filepath = System.IO.Path.GetTempFileName() + ".pdf";

               FileStream fos = new FileStream(filepath, FileMode.Create);
               BufferedStream bos = new BufferedStream(fos);
               PDF pdf = new PDF(bos);
               Page p = new PDFjet.NET.Page(pdf, Letter.PORTRAIT);

               // these two variables are lazy loaded from the db so we cache them here
               Logistics_Addresses payeeAddress = PayeeAddress;
               string payeeName = PayeeName;
               for (int i = 0; i < 3; i++)
               {
                    int yoffset = i * 251;
                    // these lines draw a seperation line between the 3 parts on a full check sheet which is useful for debugging
                    //Line l = new Line(0, yoffset, 400, yoffset);
                    //l.DrawOn(p);
                    //yoffset += 25;
                    // draw the date
                    DrawText(pdf, p, PostAt.ToString("MM/dd/yy"), 515, yoffset + 70);

                    int xnameoffset = (i == 0) ? 85 : 30;
                    DrawText(pdf, p, payeeName, xnameoffset, yoffset + 105);
                    DrawText(pdf, p, "**" + String.Format("{0:f}", Amount), 500, yoffset + 107);
                    int amountnodecimals = Convert.ToInt32(Math.Truncate(Amount));
                    int decimals = Convert.ToInt32((Amount - amountnodecimals) * 100);
                    DrawText(pdf, p, NumberConvertor.NumberToText(amountnodecimals).ToLower() + " dollar(s) " + NumberConvertor.NumberToText(decimals).ToLower() + " cents *****************", 30, yoffset + 130);

                    // draw the mailing address for windowed envelopes
                    string mailingAddress = (payeeAddress == null) ? "" : payeeAddress.ToString();
                    if (!String.IsNullOrEmpty(mailingAddress))
                    {
                         string[] addressLines = Regex.Split(mailingAddress, "\r\n");
                         for (int a = 0; a < addressLines.Length; a++)
                         {
                              DrawText(pdf, p, addressLines[a], 50, yoffset + 155 + (a * 12));
                         }
                    }

                    // draw the memo
                    DrawText(pdf, p, Memo, 30, yoffset + 215);
               }
               pdf.Flush();
               bos.Close();

               return filepath;
        }
コード例 #5
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();
    }
コード例 #6
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();
    }
コード例 #7
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();
    }
コード例 #8
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();
    }
コード例 #9
0
        /// <summary>
        /// Generate a single batch (pdf-file) containing one or more voter cards.
        /// </summary>
        /// <param name="sender">The worker which has ordered the generation.</param>
        /// <param name="e">Arguments describing the current DoWork event.</param>
        /// <param name="voters">The voter(s) to be on the voter card(s) in the file.</param>
        /// <param name="fileName">The name of the file.</param>
        private void GenerateFile(object sender, DoWorkEventArgs e, IEnumerable<VoterDO> voters, String fileName)
        {
            var worker = sender as BackgroundWorker;

            String path = destination + "\\" + fileName + ".pdf";
            var fos = new FileStream(path, FileMode.Create);
            var bos = new BufferedStream(fos);

            var pdf = new PDF(bos); // PDF in file

            var page = new Page(pdf, A4.PORTRAIT); // First page in PDF

            int pageCount = 0;
            foreach (var voter in voters)
            {
                GenerateCard(page, pdf, 0, pageCount * U);
                PopulateCard(page, pdf, 0, pageCount * U, voter);
                if (pageCount != 200) pageCount += 100;
                else
                {
                    pageCount = 0;
                    page = new Page(pdf, A4.PORTRAIT);
                }

                // Update progress percentage?
                voterDoneCount++;
                double perc = (Convert.ToDouble(voterDoneCount) / Convert.ToDouble(voterCount)) * 100;
                int iperc = (int)perc;
                if (iperc != VoterDonePerc) worker.ReportProgress(iperc);

                // Cancelled?
                // If yes, flag cancelled and break, but make sure file stream is closed properly.
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }

            pdf.Flush();
            bos.Close();
        }
コード例 #10
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();
    }