public Example_35()
    {
        StreamReader reader = new StreamReader(
            new FileStream(
                "data/chinese-english.txt", FileMode.Open, FileAccess.Read));
        String text = reader.ReadLine();

        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_35.pdf", FileMode.Create)));

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

        Font mainFont     = new Font(pdf, "AdobeMingStd", CodePage.UNICODE);
        Font fallbackFont = new Font(pdf,
                                     new FileStream("fonts/Roboto/Roboto-Regular.ttf",
                                                    FileMode.Open,
                                                    FileAccess.Read));

        TextLine textLine = new TextLine(mainFont);

        textLine.SetText(text);
        textLine.SetLocation(50f, 50f);
        textLine.DrawOn(page);

        textLine = new TextLine(mainFont);
        textLine.SetFallbackFont(fallbackFont);
        textLine.SetText(text);
        textLine.SetLocation(50f, 80f);
        textLine.DrawOn(page);

        pdf.Close();
    }
Esempio n. 2
0
    public Example_70()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_70.pdf", FileMode.Create)));

        Font f1 = new Font(pdf, new BufferedStream(
                               new FileStream(
                                   "fonts/Roboto/Roboto-Light.ttf", FileMode.Open, FileAccess.Read)));

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

        f1.SetSize(18f);
        f2.SetSize(18f);

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

        TextLine text = new TextLine(f1, "BLA ☎ BLABLA ☎");

        text.SetFallbackFont(f2);
        text.SetLocation(70f, 70f);
        text.DrawOn(page);

        pdf.Complete();
    }
Esempio n. 3
0
    public Example_24()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_24.pdf", FileMode.Create)));

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

        Image image_00 = new Image(pdf, new FileStream(
                                       "images/gr-map.jpg", FileMode.Open, FileAccess.Read), ImageType.JPG);

        Image image_01 = new Image(pdf, new FileStream(
                                       "images/linux-logo.png.stream", FileMode.Open, FileAccess.Read), ImageType.PNG_STREAM);

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

        Image image_03 = new Image(pdf, new FileStream(
                                       "images/rgb24pal.bmp", FileMode.Open, FileAccess.Read), ImageType.BMP);

        Page     page        = new Page(pdf, Letter.PORTRAIT);
        TextLine textline_00 = new TextLine(font, "This is a JPEG image.");

        textline_00.SetTextDirection(0);
        textline_00.SetLocation(50f, 50f);
        float[] point = textline_00.DrawOn(page);
        image_00.SetLocation(50f, point[1]).ScaleBy(0.25f).DrawOn(page);

        page = new Page(pdf, Letter.PORTRAIT);
        TextLine textline_01 = new TextLine(font, "This is a PNG_STREAM image.");

        textline_01.SetTextDirection(0);
        textline_01.SetLocation(50f, 50f);
        point = textline_01.DrawOn(page);
        image_01.SetLocation(50f, point[1]).DrawOn(page);

        page = new Page(pdf, Letter.PORTRAIT);
        TextLine textline_02 = new TextLine(font, "This is a PNG image.");

        textline_02.SetTextDirection(0);
        textline_02.SetLocation(50f, 50f);
        point = textline_02.DrawOn(page);
        image_02.SetLocation(50f, point[1]).ScaleBy(0.75f).DrawOn(page);

        TextLine textline_03 = new TextLine(font, "This is a BMP image.");

        textline_03.SetTextDirection(0);
        textline_03.SetLocation(50f, 620f);
        point = textline_03.DrawOn(page);
        image_03.SetLocation(50f, point[1]).ScaleBy(0.75f).DrawOn(page);

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

        Image image2 = new Image(pdf, new FileStream(
                                     "images/linux-logo.png.stream", FileMode.Open, FileAccess.Read), ImageType.PNG_STREAM);

        pdf.Complete();
    }
Esempio n. 4
0
    public Example_04()
    {
        String fileName = "data/happy-new-year.txt";

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

        // Chinese (Traditional) font
        Font f1 = new Font(pdf, Font.AdobeMingStd_Light);

        // Chinese (Simplified) font
        Font f2 = new Font(pdf, Font.STHeitiSC_Light);

        // Japanese font
        Font f3 = new Font(pdf, Font.KozMinProVI_Regular);

        // Korean font
        Font f4 = new Font(pdf, Font.AdobeMyungjoStd_Medium);

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

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

        float        x_pos  = 100f;
        float        y_pos  = 100f;
        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.SetLocation(x_pos, y_pos);
            text.DrawOn(page);
            y_pos += 25f;
        }
        reader.Close();

        pdf.Complete();
    }
Esempio n. 5
0
    public Example_21()
    {
        PDF pdf = new PDF(new FileStream("Example_21.pdf", FileMode.Create));

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

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

        TextLine text = new TextLine(f1,
                                     "QR codes encoded with Low, Medium, High and Very High error correction level - C#");

        text.SetLocation(100.0f, 30.0f);
        text.DrawOn(page);

        // Please note:
        // The higher the error correction level - the shorter the string that you can encode.
        QRCode qr = new QRCode(
            "https://kazuhikoarase.github.io/qrcode-generator/js/demo",
            ErrorCorrectLevel.L);       // Low

        qr.SetModuleLength(3f);
        qr.SetLocation(100f, 100f);
        // qr.SetColor(Color.blue);
        qr.DrawOn(page);

        qr = new QRCode(
            "https://github.com/kazuhikoarase/qrcode-generator",
            ErrorCorrectLevel.M);       // Medium
        qr.SetLocation(400f, 100f);
        qr.SetModuleLength(3f);
        qr.DrawOn(page);

        qr = new QRCode(
            "https://github.com/kazuhikoarase/jaconv",
            ErrorCorrectLevel.Q);       // High
        qr.SetLocation(100f, 400f);
        qr.SetModuleLength(3f);
        qr.DrawOn(page);

        qr = new QRCode(
            "https://github.com/kazuhikoarase",
            ErrorCorrectLevel.H);       // Very High
        qr.SetLocation(400f, 400f);
        qr.SetModuleLength(3f);
        float[] xy = qr.DrawOn(page);

/*
 *      Box box = new Box();
 *      box.SetLocation(xy[0], xy[1]);
 *      box.SetSize(20f, 20f);
 *      box.DrawOn(page);
 */
        pdf.Complete();
    }
Esempio n. 6
0
        public static void DrawPageNumber(PDF pdf, Page page, int pageNumber)
        {
            PDFjet.NET.Font font = new PDFjet.NET.Font(pdf, CoreFont.HELVETICA_BOLD);
            font.SetSize(7f);
            TextLine textLine = new TextLine(font);
            string   text     = string.Format(LangRes.PageNo, pageNumber);

            textLine.SetText(text);
            textLine.SetLocation(pdfUtil.PDFLoctx_pageNo, pdfUtil.PDFLocty_pageNo);
            textLine.DrawOn(page);
        }
    public Example_21()
    {
        PDF pdf = new PDF(new FileStream("Example_21.pdf", FileMode.Create));

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

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

        TextLine text = new TextLine(f1, "QR codes");

        text.SetLocation(100f, 30f);
        text.DrawOn(page);

        // Please note: The higher the error correction level - the shorter the string that you can encode.
        QRCode qr = new QRCode(
            "http://d-project.googlecode.com/svn/trunk/misc/qrcode/as3/src/sample",
            ErrorCorrectLevel.L);       // Low

        qr.SetModuleLength(3f);
        qr.SetLocation(100f, 100f);
        qr.SetLocation(0.0001f, 100f);
        qr.DrawOn(page);

        qr = new QRCode(
            "http://d-project.googlecode.com/svn/trunk/misc/qrcode",
            ErrorCorrectLevel.M);       // High
        qr.SetLocation(300f, 100f);
        qr.DrawOn(page);

        qr = new QRCode(
            "http://www.d-project.com/qrcode/index.html",
            ErrorCorrectLevel.Q);       // Medium
        qr.SetLocation(100f, 300f);
        qr.DrawOn(page);

        qr = new QRCode(
            "http://www.d-project.com",
            ErrorCorrectLevel.H);       // Very High
        qr.SetLocation(300f, 300f);
        float[] xy = qr.DrawOn(page);

/*
 *      Box box = new Box();
 *      box.SetLocation(xy[0], xy[1]);
 *      box.SetSize(20f, 20f);
 *      box.DrawOn(page);
 */
        pdf.Close();
    }
    public Example_12()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_12.pdf", FileMode.Create)));

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

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

        StringBuilder 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);
        }
        reader.Close();

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

        code2D.SetModuleWidth(0.5f);
        code2D.SetLocation(100f, 60f);
        float[] xy = code2D.DrawOn(page);

/*
 *      Box box = new Box();
 *      box.SetLocation(xy[0], xy[1]);
 *      box.SetSize(20f, 20f);
 *      box.DrawOn(page);
 */
        TextLine text = new TextLine(f1,
                                     "PDF417 barcode containing the program that created it.");

        text.SetLocation(100f, 40f);
        text.DrawOn(page);

        pdf.Close();
    }
Esempio n. 9
0
    public void drawTextAndLines(
        String text, Page page, Font font, float x, float y)
    {
        TextLine textline = new TextLine(font, text);

        textline.SetLocation(x, y);
        textline.DrawOn(page);

        Line ascenderLine = new Line(x, y - font.GetAscent(), x + 100f, y - font.GetAscent());

        ascenderLine.SetWidth(2f);
        ascenderLine.DrawOn(page);

        Line line = new Line(x, y, x + 100f, y);

        line.SetWidth(2f);
        line.DrawOn(page);

        Line descenderLine = new Line(x, y + font.GetDescent(), x + 100f, y + font.GetDescent());

        descenderLine.SetWidth(2f);
        descenderLine.DrawOn(page);
    }
Esempio n. 10
0
        /// <summary>
        /// Populate a voter card with the information of a given voter.
        /// </summary>
        /// <param name="page">The page containing the card.</param>
        /// <param name="pdf">The pdf containing the page.</param>
        /// <param name="xO">The horizontal offset of the card in points.</param>
        /// <param name="yO">The vertical offset of the card in points.</param>
        /// <param name="voter">The voter whose information to be populated onto the card.</param>
        private static void PopulateCard(Page page, PDF pdf, double xO, double yO, VoterDO voter)
        {
            // ----- POPULATE: POLLING STATION -----
            PollingStationDO ps = voter.PollingStation;

            var font = new Font(pdf, CoreFont.HELVETICA);

            font.SetSize(9);

            var t = new TextLine(font, ps.Name);

            t.SetPosition(xO + 9 * U, yO + 27.5 * U);
            t.DrawOn(page);

            t = new TextLine(font, ps.Address);
            t.SetPosition(xO + 9 * U, yO + 32 * U);
            t.DrawOn(page);

            t = new TextLine(font, "valgfrit");
            t.SetPosition(xO + 29 * U, yO + 48.8 * U);
            t.DrawOn(page);

            t = new TextLine(font, "02-04861");
            t.SetPosition(xO + 29 * U, yO + 58.7 * U);
            t.DrawOn(page);

            t = new TextLine(font, "09:00 - 20:00");
            t.SetPosition(xO + 29 * U, yO + 68.2 * U);
            t.DrawOn(page);


            // ----- POPULATE: VOTER -----
            MunicipalityDO mun = voter.PollingStation.Municipality;

            font = new Font(pdf, CoreFont.COURIER);
            font.SetSize(10);

            // Add top voter number 'Vælgernr.'
            t = new TextLine(font, "02-04861");
            t.SetPosition(xO + 102 * U, yO + 12 * U);
            t.DrawOn(page);

            // Add sender 'Afsender'
            t = new TextLine(font, mun.Name);
            t.SetPosition(xO + 102 * U, yO + 32.5 * U);
            t.DrawOn(page);

            t = new TextLine(font, mun.Address);
            t.SetPosition(xO + 102 * U, yO + 36.5 * U);
            t.DrawOn(page);

            t = new TextLine(font, mun.City);
            t.SetPosition(xO + 102 * U, yO + 40.5 * U);
            t.DrawOn(page);

            // Add reciever 'Modtager'
            t = new TextLine(font, voter.Name);
            t.SetPosition(xO + 102 * U, yO + 62.5 * U);
            t.DrawOn(page);

            t = new TextLine(font, voter.Address);
            t.SetPosition(xO + 102 * U, yO + 66.5 * U);
            t.DrawOn(page);

            t = new TextLine(font, voter.City);
            t.SetPosition(xO + 102 * U, yO + 70.5 * U);
            t.DrawOn(page);

            // Add CPR barcode
            string barcode = BarCodeHashing.Hash(voter.PrimaryKey.Value).ToString();
            var    b       = new BarCode(BarCode.CODE128, barcode);

            b.SetPosition(xO + 160 * U, yO + 60 * U);
            b.DrawOn(page);

            t = new TextLine(font, barcode);
            t.SetPosition(xO + 160 * U, yO + 72 * U);
            t.DrawOn(page);
        }
Esempio n. 11
0
        /// <summary>
        /// Generate lines, boxes, watermark and default text of a single voter card.
        /// </summary>
        /// <param name="page">The page containing the card.</param>
        /// <param name="pdf">The pdf containing the page.</param>
        /// <param name="xO">The horizontal offset of the card in points.</param>
        /// <param name="yO">The vertical offset of the card in points.</param>
        private static void GenerateCard(Page page, PDF pdf, double xO, double yO)
        {
            // Add watermark.
            var font = new Font(pdf, CoreFont.HELVETICA_BOLD);

            font.SetSize(55);
            var t         = new TextLine(font, "FAKE VALGKORT");
            var lightBlue = new[] { 0.647, 0.812, 0.957 };

            t.SetColor(lightBlue);
            t.SetPosition(xO + 20 * U, yO + 50 * U);
            t.DrawOn(page);

            // Add 'Afstemningssted' box.
            var b = new Box(xO + 6 * U, yO + 20 * U, 80 * U, 22 * U);

            b.DrawOn(page);

            // Add 'Valgbord' box.
            b = new Box(xO + 6 * U, yO + 44.5 * U, 80 * U, 7 * U);
            b.DrawOn(page);

            // Add 'Vælgernr' box.
            b = new Box(xO + 6 * U, yO + 54 * U, 80 * U, 7 * U);
            b.DrawOn(page);

            // Add 'Afstemningstid' box.
            b = new Box(xO + 6 * U, yO + 63.5 * U, 80 * U, 7 * U);
            b.DrawOn(page);

            // Add lines.
            var l = new Line(xO + 96 * U, yO + 5 * U, xO + 96 * U, yO + 85 * U);

            l.DrawOn(page);
            l = new Line(xO + 96 * U, yO + 25 * U, xO + 205 * U, yO + 25 * U);
            l.DrawOn(page);
            l = new Line(xO + 96 * U, yO + 45 * U, xO + 205 * U, yO + 45 * U);
            l.DrawOn(page);
            l = new Line(xO + 6 * U, yO + 85 * U, xO + 205 * U, yO + 85 * U);
            l.DrawOn(page);

            // Add default text.
            font = new Font(pdf, CoreFont.HELVETICA);
            font.SetSize(7);
            t = new TextLine(font, "Afstemningssted:");
            t.SetPosition(xO + 7 * U, yO + 23 * U);
            t.DrawOn(page);
            t = new TextLine(font, "Vælgernr.:");
            t.SetPosition(xO + 7 * U, yO + 58 * U);
            t.DrawOn(page);
            t = new TextLine(font, "Afstemningstid:");
            t.SetPosition(xO + 7 * U, yO + 68 * U);
            t.DrawOn(page);
            t = new TextLine(font, "Afsender:");
            t.SetPosition(xO + 98 * U, yO + 29 * U);
            t.DrawOn(page);
            t = new TextLine(font, "Modtager:");
            t.SetPosition(xO + 98 * U, yO + 49 * U);
            t.DrawOn(page);

            font = new Font(pdf, CoreFont.HELVETICA);
            font.SetSize(9);
            t = new TextLine(font, "Folketingsvalg");
            t.SetPosition(xO + 7 * U, yO + 10 * U);
            t.DrawOn(page);
            t = new TextLine(font, "20. november 2001");
            t.SetPosition(xO + 7 * U, yO + 14 * U);
            t.DrawOn(page);
            t = new TextLine(font, "Valgbord:");
            t.SetPosition(xO + 7 * U, yO + 49 * U);
            t.DrawOn(page);

            font = new Font(pdf, CoreFont.HELVETICA_OBLIQUE);
            font.SetSize(7);
            t = new TextLine(font, "Medbring kortet ved afstemningen");
            t.SetPosition(xO + 6.5 * U, yO + 18.5 * U);
            t.DrawOn(page);
        }
Esempio n. 12
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();
    }
Esempio n. 13
0
    public Example_27()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_27.pdf", FileMode.Create)));

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

        // Thai font
        Font f1 = new Font(pdf,
                           new FileStream(
                               "fonts/Noto/NotoSansThai-Regular.ttf",
                               FileMode.Open,
                               FileAccess.Read));

        f1.SetSize(14f);

        // Latin font
        Font f2 = new Font(pdf,
                           new FileStream(
                               "fonts/Droid/DroidSans.ttf",
                               FileMode.Open,
                               FileAccess.Read));

        f2.SetSize(12f);

        // Hebrew font
        Font f3 = new Font(pdf,
                           new FileStream(
                               "fonts/Noto/NotoSansHebrew-Regular.ttf",
                               FileMode.Open,
                               FileAccess.Read));

        f3.SetSize(12f);

        // Arabic font
        Font f4 = new Font(pdf,
                           new FileStream(
                               "fonts/Noto/NotoNaskhArabic-Regular.ttf",
                               FileMode.Open,
                               FileAccess.Read));

        f4.SetSize(12f);

        float x = 50f;
        float y = 50f;

        TextLine text = new TextLine(f1);

        text.SetFallbackFont(f2);
        text.SetLocation(x, y);

        StringBuilder buf = new StringBuilder();

        for (int i = 0x0E01; i < 0x0E5B; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x, y += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            if (i > 0x0E30 && i < 0x0E3B)
            {
                buf.Append("\u0E01");
            }
            if (i > 0x0E46 && i < 0x0E4F)
            {
                buf.Append("\u0E2D");
            }
            buf.Append((char)i);
        }

        text.SetText(buf.ToString());
        text.SetLocation(x, y += 20f);
        text.DrawOn(page);

        y += 20f;

        String str = "\u0E1C\u0E1C\u0E36\u0E49\u0E07 abc 123";

        text.SetText(str);
        text.SetLocation(x, y);
        text.DrawOn(page);

        y += 20f;

        str = "כך נראית תחתית הטבלה עם סיום הפלייאוף התחתון:";
        str = Bidi.ReorderVisually(str);
        TextLine textLine = new TextLine(f3, str);

        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f3.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str      = "10. הפועל כפר סבא 38 נקודות (הפרש שערים 14-)";
        str      = Bidi.ReorderVisually(str);
        textLine = new TextLine(f3, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f3.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str      = "11. הפועל קריית שמונה 36 נקודות (הפרש שערים 7-)";
        str      = Bidi.ReorderVisually(str);
        textLine = new TextLine(f3, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f3.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str      = "12. הפועל חיפה 34 נקודות (הפרש שערים 10-)";
        str      = Bidi.ReorderVisually(str);
        textLine = new TextLine(f3, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f3.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str      = "13. הפועל עכו 34 נקודות (הפרש שערים 21-)";
        str      = Bidi.ReorderVisually(str);
        textLine = new TextLine(f3, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f3.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        y += 40f;

        str = Bidi.ReorderVisually(
            "قالت شركة PSA بيجو ستروين الفرنسية وشريكتها الصينية شركة دونغفينغ موترز الاربعاء إنهما اتفقتا");
        textLine = new TextLine(f4, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f4.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str = Bidi.ReorderVisually(
            "على التعاون في تطوير السيارات التي تعمل بالطاقة الكهربائية اعتبارا من عام 2019.");
        textLine = new TextLine(f4, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f4.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str = Bidi.ReorderVisually(
            "وجاء في تصريح اصدرته في باريس الشركة الفرنسية ان الشركتين ستنتجان نموذجا كهربائيا مشتركا تستخدمه كل");
        textLine = new TextLine(f4, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f4.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str = Bidi.ReorderVisually(
            "من بيجو وسيتروين ودونغفينغ.");
        textLine = new TextLine(f4, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f4.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        str = Bidi.ReorderVisually(
            "وقالت إن الخطة تهدف الى تحقيق عائد يزيد على 100 مليار يوان (15,4 مليار دولار) بحلول عام 2020.");
        textLine = new TextLine(f4, str);
        textLine.SetFallbackFont(f2);
        textLine.SetLocation(600f - f4.StringWidth(f2, str), y += 20f);
        textLine.DrawOn(page);

        pdf.Close();
    }
Esempio n. 14
0
    public Example_03()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_03.pdf", FileMode.Create)));

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

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

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

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

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

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

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

        image2.SetLocation(260f, 560f);
        image2.SetRotate(ClockWise._90_degrees);
        // image2.SetRotate(ClockWise._180_degrees);
        // image2.SetRotate(ClockWise._270_degrees);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        image2.SetLocation(350f, 560f);
        image2.SetRotate(ClockWise.degrees_0);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

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

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

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

        float[] xy = image1.DrawOn(page2);

        Box box = new Box();

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

        pdf.Close();
    }
Esempio n. 15
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();
    }
Esempio n. 16
0
    public Example_03()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_03.pdf", FileMode.Create)));

        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 image1 = new Image(
 *              pdf,
 *              new BufferedStream(new FileStream(
 *                      "images/ee-map.png.stream", FileMode.Open, FileAccess.Read)),
 *              ImageType.PNG_STREAM);
 */
        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);

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

        float[] xy = page.AddHeader(new TextLine(f1, "This is a header!"));

        Box box = new Box();

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

        page.AddFooter(new TextLine(f1, "And this is a footer."));

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

        text.SetLocation(90f, 30f);
        text.SetURIAction("https://en.wikipedia.org/wiki/European_Union");
        xy = text.DrawOn(page);

        image1.SetLocation(90f, xy[1] + f1.GetDescent());
        image1.ScaleBy(2f / 3f);
        image1.DrawOn(page);

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

        image2.SetLocation(90f, xy[1] + f1.GetDescent());
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        image2.SetLocation(260f, xy[1] + f1.GetDescent());
        image2.SetRotate(ClockWise._90_degrees);
        // image2.SetRotate(ClockWise._180_degrees);
        // image2.SetRotate(ClockWise._270_degrees);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        image2.SetLocation(350f, xy[1] + f1.GetDescent());
        image2.SetRotate(ClockWise.degrees_0);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

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

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

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

        xy = image1.DrawOn(page2);

        box = new Box();
        box.SetLocation(xy[0], xy[1]);
        box.SetSize(20f, 20f);
        box.DrawOn(page2);

        pdf.Complete();
    }
    public Example_07()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_07.pdf", FileMode.Create)));
        // pdf.SetPageLayout(PageLayout.SINGLE_PAGE);
        // pdf.SetPageMode(PageMode.FULL_SCREEN);

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

        f1.SetSize(15f);

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

        f2.SetSize(15f);

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

        f1.SetSize(72f);
        page.AddWatermark(f1, "This is a Draft");
        f1.SetSize(15f);

        float    x_pos = 70f;
        float    y_pos = 70f;
        TextLine text  = new TextLine(f1);

        text.SetLocation(x_pos, y_pos);
        StringBuilder buf = new StringBuilder();

        for (int i = 0x20; i < 0x7F; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            buf.Append((char)i);
        }

        y_pos += 24f;
        buf    = new StringBuilder();
        for (int i = 0x390; i < 0x3EF; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            if (i == 0x3A2 ||
                i == 0x3CF ||
                i == 0x3D0 ||
                i == 0x3D3 ||
                i == 0x3D4 ||
                i == 0x3D5 ||
                i == 0x3D7 ||
                i == 0x3D8 ||
                i == 0x3D9 ||
                i == 0x3DA ||
                i == 0x3DB ||
                i == 0x3DC ||
                i == 0x3DD ||
                i == 0x3DE ||
                i == 0x3DF ||
                i == 0x3E0 ||
                i == 0x3EA ||
                i == 0x3EB ||
                i == 0x3EC ||
                i == 0x3ED ||
                i == 0x3EF)
            {
                // Replace .notdef with space to generate PDF/A compliant PDF
                buf.Append((char)0x0020);
            }
            else
            {
                buf.Append((char)i);
            }
        }

        y_pos += 24f;
        buf    = new StringBuilder();
        for (int i = 0x410; i < 0x46F; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            buf.Append((char)i);
        }

        x_pos = 370f;
        y_pos = 70f;
        text  = new TextLine(f2);
        text.SetLocation(x_pos, y_pos);
        buf = new StringBuilder();
        for (int i = 0x20; i < 0x7F; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            buf.Append((char)i);
        }

        y_pos += 24f;
        buf    = new StringBuilder();
        for (int i = 0x390; i < 0x3EF; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            if (i == 0x3A2 ||
                i == 0x3CF ||
                i == 0x3D0 ||
                i == 0x3D3 ||
                i == 0x3D4 ||
                i == 0x3D5 ||
                i == 0x3D7 ||
                i == 0x3D8 ||
                i == 0x3D9 ||
                i == 0x3DA ||
                i == 0x3DB ||
                i == 0x3DC ||
                i == 0x3DD ||
                i == 0x3DE ||
                i == 0x3DF ||
                i == 0x3E0 ||
                i == 0x3EA ||
                i == 0x3EB ||
                i == 0x3EC ||
                i == 0x3ED ||
                i == 0x3EF)
            {
                // Replace .notdef with space to generate PDF/A compliant PDF
                buf.Append((char)0x0020);
            }
            else
            {
                buf.Append((char)i);
            }
        }

        y_pos += 24f;
        buf    = new StringBuilder();
        for (int i = 0x410; i < 0x46F; i++)
        {
            if (i % 16 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x_pos, y_pos += 24f);
                text.DrawOn(page);
                buf = new StringBuilder();
            }
            buf.Append((char)i);
        }

        pdf.Close();
    }
Esempio n. 18
0
    public Example_05()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_05.pdf", FileMode.Create)));

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

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

        TextLine text = new TextLine(f1);

        text.SetLocation(300f, 300f);
        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.SetLocation(70f, 50f);
        text.DrawOn(page);

        f1.SetKernPairs(true);
        text.SetLocation(70f, 70f);
        text.DrawOn(page);

        f1.SetKernPairs(false);
        text.SetLocation(70f, 90f);
        text.DrawOn(page);

        f1.SetSize(8.0f);
        text = new TextLine(f1, "-- font.SetKernPairs(false);");
        text.SetLocation(150f, 50f);
        text.DrawOn(page);
        text.SetLocation(150f, 90f);
        text.DrawOn(page);
        text = new TextLine(f1, "-- font.SetKernPairs(true);");
        text.SetLocation(150f, 70f);
        text.DrawOn(page);

        Point point = new Point(300f, 300f);

        point.SetShape(Point.CIRCLE);
        point.SetFillShape(true);
        point.SetColor(Color.blue);
        point.SetRadius(37f);
        point.DrawOn(page);
        point.SetRadius(25f);
        point.SetColor(Color.white);
        point.DrawOn(page);

        page.SetPenWidth(1.0f);
        page.DrawEllipse(300f, 600f, 100f, 50f);

        f1.SetSize(14f);
        String unicode = "\u20AC\u0020\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160";

        text = new TextLine(f1, unicode);
        text.SetLocation(100f, 700f);
        text.DrawOn(page);

        pdf.Complete();
    }
Esempio n. 19
0
    public Example_74()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_74.pdf", FileMode.Create)));

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

        f1.SetSize(72f);

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

        f2.SetSize(24f);


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

        StringBuilder buf = new StringBuilder();

        buf.Append("Heya, World! This is a test to show the functionality of a TextBox.");

        float x1 = 90f;
        float y1 = 150f;

        Point p1 = new Point(x1, y1);

        p1.SetRadius(5f);
        p1.SetFillShape(true);
        p1.DrawOn(page);

        TextLine textline = new TextLine(f2, "(x1, y1)");

        textline.SetLocation(x1, y1 - 15f);
        textline.DrawOn(page);

        float   width   = 500f;
        float   height  = 450f;
        TextBox textBox = new TextBox(f1, buf.ToString());

        textBox.SetLocation(x1, y1);
        textBox.SetWidth(width);
        textBox.SetHeight(height);
        textBox.SetMargin(0f);
        textBox.SetSpacing(0f);
        float[] xy = textBox.DrawOn(page);

        float x2 = x1 + width;
        float y2 = y1 + textBox.GetHeight();

        f2.SetSize(18f);

        // Text on the left
        TextLine ascent_text = new TextLine(f2, "Ascent");

        ascent_text.SetLocation(x1 - 85f, y1 + 40f); //(y1 + f1.getAscent()) / 2);
        ascent_text.DrawOn(page);

        TextLine descent_text = new TextLine(f2, "Descent");

        descent_text.SetLocation(x1 - 85f, y1 + f1.GetAscent() + 15f);
        descent_text.DrawOn(page);

        // Lines beside the text
        Line arrow_line1 = new Line(x1 - 10f, y1, x1 - 10f, y1 + f1.GetAscent());

        arrow_line1.SetColor(Color.blue);
        arrow_line1.SetWidth(3f);
        arrow_line1.DrawOn(page);

        Line arrow_line2 = new Line(x1 - 10f, y1 + f1.GetAscent(),
                                    x1 - 10f, y1 + f1.GetAscent() + f1.GetDescent());

        arrow_line2.SetColor(Color.red);
        arrow_line2.SetWidth(3f);
        arrow_line2.DrawOn(page);


        // Lines for first line of text
        Line text_line1 = new Line(x1, y1 + f1.GetAscent(), x2, y1 + f1.GetAscent());

        text_line1.DrawOn(page);

        Line descent_line1 = new Line(x1, y1 + (f1.GetAscent() + f1.GetDescent()),
                                      x2, y1 + (f1.GetAscent() + f1.GetDescent()));

        descent_line1.DrawOn(page);


        // Lines for second line of text
        float curr_y = y1 + f1.GetBodyHeight();

        Line text_line2 = new Line(x1, curr_y + f1.GetAscent(), x2, curr_y + f1.GetAscent());

        text_line2.DrawOn(page);

        Line descent_line2 = new Line(x1, curr_y + f1.GetAscent() + f1.GetDescent(),
                                      x2, curr_y + f1.GetAscent() + f1.GetDescent());

        descent_line2.DrawOn(page);


        Point p2 = new Point(x2, y2);

        p2.SetRadius(5f);
        p2.SetFillShape(true);
        p2.DrawOn(page);

        f2.SetSize(24f);
        TextLine textline2 = new TextLine(f2, "(x2, y2)");

        textline2.SetLocation(x2 - 80f, y2 + 30f);
        textline2.DrawOn(page);

        Box box = new Box();

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

        pdf.Complete();
    }
Esempio n. 20
0
    public Example_16()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_16.pdf", FileMode.Create)));

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

        f1.SetSize(14f);

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

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

        colors["Lorem"]       = Color.blue;
        colors["ipsum"]       = Color.red;
        colors["dolor"]       = Color.green;
        colors["ullamcorper"] = Color.gray;

        f1.SetSize(72f);

        GraphicsState gs = new GraphicsState();

        gs.SetAlphaStroking(0.5f);      // Set alpha for stroking operations
        gs.SetAlphaNonStroking(0.5f);   // Set alpha for nonstroking operations
        page.SetGraphicsState(gs);

        TextLine text = new TextLine(f1, "Hello, World");

        text.SetLocation(50f, 300f);
        text.DrawOn(page);

        String latinText = File.ReadAllText("data/latin.txt");

        f1.SetSize(14f);
        TextBox textBox = new TextBox(f1, latinText);

        textBox.SetLocation(50f, 50f);
        textBox.SetWidth(400f);
        // If no height is specified the height will be calculated based on the text.
        // textBox.SetHeight(400f);

        // textBox.SetVerticalAlignment(Align.TOP);
        // textBox.SetVerticalAlignment(Align.BOTTOM);
        // textBox.SetVerticalAlignment(Align.CENTER);
        textBox.SetBgColor(Color.whitesmoke);
        textBox.SetTextColors(colors);

        // Find x and y without actually drawing the text box.
        // float[] xy = textBox.DrawOn(page, false);
        float[] xy = textBox.DrawOn(page);

        page.SetGraphicsState(new GraphicsState()); // Reset GS

        Box box = new Box();

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

        pdf.Complete();
    }
Esempio n. 21
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();
    }
Esempio n. 22
0
    public Example_31()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_31.pdf", FileMode.Create)));

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

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

        f1.SetSize(15f);

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

        f2.SetSize(15f);

        StringBuilder buf    = new StringBuilder();
        StreamReader  reader = new StreamReader(
            new FileStream("data/marathi.txt", FileMode.Open, FileAccess.Read));
        String line = null;

        while ((line = reader.ReadLine()) != null)
        {
            buf.Append(line + "\n");
        }
        reader.Close();

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

        textBox.SetFallbackFont(f2);
        textBox.SetLocation(50f, 50f);
        textBox.SetNoBorders();
        textBox.DrawOn(page);

        String   str      = "असम के बाद UP में भी CM कैंडिडेट का ऐलान करेगी BJP?";
        TextLine textLine = new TextLine(f1, str);

        textLine.SetFallbackFont(f2);
        textLine.SetLocation(50f, 175f);
        textLine.DrawOn(page);


        page.SetPenColor(Color.blue);
        page.SetBrushColor(Color.blue);
        page.FillRect(50f, 200f, 200f, 200f);

        GraphicsState gs = new GraphicsState();

        gs.SetAlphaStroking(0.5f);      // The stroking alpha constant
        gs.SetAlphaNonStroking(0.5f);   // The nonstroking alpha constant
        page.SetGraphicsState(gs);

        page.SetPenColor(Color.green);
        page.SetBrushColor(Color.green);
        page.FillRect(100f, 250f, 200f, 200f);

        page.SetPenColor(Color.red);
        page.SetBrushColor(Color.red);
        page.FillRect(150, 300, 200f, 200f);

        // Reset the parameters to the default values
        page.SetGraphicsState(new GraphicsState());

        page.SetPenColor(Color.orange);
        page.SetBrushColor(Color.orange);
        page.FillRect(200, 350, 200f, 200f);

        page.SetBrushColor(0x00003865);
        page.FillRect(50, 550, 200f, 200f);

        pdf.Complete();
    }
Esempio n. 23
0
    public Example_20()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_20.pdf", FileMode.Create)));

        BufferedStream bis = new BufferedStream(
            new FileStream("data/testPDFs/PDFjetLogo.pdf", FileMode.Open));
        SortedDictionary <Int32, PDFobj> objects = pdf.Read(bis);

        bis.Close();

        pdf.AddResourceObjects(objects);

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

        f1.SetSize(18f);

        List <PDFobj> pages    = pdf.GetPageObjects(objects);
        PDFobj        contents = pages[0].GetContentsObject(objects);

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

        float height = 105f;    // The logo height in points.
        float x      = 50f;
        float y      = 50f;
        float xScale = 0.5f;
        float yScale = 0.5f;

        page.DrawContents(
            contents.GetData(),
            height,
            x,
            y,
            xScale,
            yScale);

        page.SetPenColor(Color.darkblue);
        page.SetPenWidth(0f);
        page.DrawRect(0f, 0f, 50f, 50f);

        PDFjet.NET.Path path = new PDFjet.NET.Path();

        path.Add(new Point(13.0f, 0.0f));
        path.Add(new Point(15.5f, 4.5f));

        path.Add(new Point(18.0f, 3.5f));
        path.Add(new Point(15.5f, 13.5f, Point.CONTROL_POINT));
        path.Add(new Point(15.5f, 13.5f, Point.CONTROL_POINT));
        path.Add(new Point(20.5f, 7.5f));

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

        path.Add(new Point(5.5f, 7.5f));
        path.Add(new Point(10.5f, 13.5f, Point.CONTROL_POINT));
        path.Add(new Point(10.5f, 13.5f, Point.CONTROL_POINT));
        path.Add(new Point(8.0f, 3.5f));

        path.Add(new Point(10.5f, 4.5f));
        path.SetClosePath(true);
        path.SetColor(Color.red);
        // path.SetFillShape(true);
        path.SetLocation(100f, 100f);
        path.ScaleBy(10f);

        path.DrawOn(page);

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

        TextLine line = new TextLine(f1, "Hello, World!");

        line.SetLocation(50f, 50f);
        line.DrawOn(page);

        QRCode qr = new QRCode(
            "http://d-project.googlecode.com/svn/trunk/misc/qrcode/as3/src/sample",
            ErrorCorrectLevel.L);       // Low

        qr.SetModuleLength(3f);
        qr.SetLocation(50f, 200f);
        qr.DrawOn(page);

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

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

        f1.SetSize(14f);

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

        Box bg_flag = new Box();

        bg_flag.SetLocation(50f, 50f);
        bg_flag.SetSize(200f, 120f);
        bg_flag.SetColor(Color.black);
        bg_flag.SetLineWidth(1.5f);
        bg_flag.DrawOn(page);

        float stripe_width = 120f / 3;

        Line white_stripe = new Line(0.0f, 0.0f, 200.0f, 0.0f);

        white_stripe.SetWidth(stripe_width);
        white_stripe.SetColor(Color.white);
        white_stripe.PlaceIn(bg_flag, 0.0f, stripe_width / 2);
        white_stripe.DrawOn(page);

        Line green_stripe = new Line(0.0f, 0.0f, 200.0f, 0.0f);

        green_stripe.SetWidth(stripe_width);
        green_stripe.SetColor(0x00966e);
        green_stripe.PlaceIn(bg_flag, 0.0f, (3 * stripe_width) / 2);
        green_stripe.DrawOn(page);

        Line red_stripe = new Line(0.0f, 0.0f, 200.0f, 0.0f);

        red_stripe.SetWidth(stripe_width);
        red_stripe.SetColor(0xd62512);
        red_stripe.PlaceIn(bg_flag, 0.0f, (5 * stripe_width) / 2);
        red_stripe.DrawOn(page);

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

        colors["Lorem"]       = Color.blue;
        colors["ipsum"]       = Color.red;
        colors["dolor"]       = Color.green;
        colors["ullamcorper"] = Color.gray;

        f1.SetSize(72f);

        GraphicsState gs = new GraphicsState();

        gs.Set_CA(0.5f);                            // Stroking alpha
        gs.Set_ca(0.5f);                            // Nonstroking alpha
        page.SetGraphicsState(gs);

        TextLine text = new TextLine(f1, "Hello, World");

        text.SetLocation(50f, 300f);
        text.DrawOn(page);

        f1.SetSize(14f);

        StringBuilder buf = new StringBuilder();

        buf.Append("    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");

        buf.Append("    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, vitae 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.");

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

        textBox.SetLocation(50f, 200f);
        textBox.SetWidth(400f);
        textBox.SetHeight(400f);

        // If no height is specified the height will be calculated based on the text.
        // textBox.SetHeight(363f);
        // textBox.SetHeight(362f);
        // textBox.SetVerticalAlignment(Align.TOP);
        // textBox.SetVerticalAlignment(Align.BOTTOM);
        // textBox.SetVerticalAlignment(Align.CENTER);

        textBox.SetBgColor(Color.whitesmoke);
        textBox.SetTextColors(colors);

        // Find x and y without actually drawing the text box.
        // float[] xy = textBox.DrawOn(page, false);
        float[] xy = textBox.DrawOn(page);

        page.SetGraphicsState(new GraphicsState()); // Reset GS

        Box box = new Box();

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

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

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

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

        Image image = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/map407.png", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);

        image.SetLocation(10f, 100f);

        TextLine textLine = new TextLine(font);

        textLine.SetText("© OpenStreetMap contributors");
        textLine.SetLocation(430f, 655f);
        textLine.DrawOn(page);

        textLine = new TextLine(font);
        textLine.SetText("http://www.openstreetmap.org/copyright");
        textLine.SetURIAction("http://www.openstreetmap.org/copyright");
        textLine.SetLocation(380f, 665f);
        textLine.DrawOn(page);

        OptionalContentGroup group = new OptionalContentGroup("Map");

        group.Add(image);
        group.SetVisible(true);
        // group.SetPrintable(true);
        group.DrawOn(page);

        TextBox tb = new TextBox(font);

        tb.SetText("Hello Text");
        tb.SetLocation(300f, 100f);

        tb = new TextBox(font);
        tb.SetText("Hello Blue Layer Text");
        tb.SetLocation(300f, 200f);

        Line line = new Line();

        line.SetPointA(300f, 250f);
        line.SetPointB(500f, 250f);
        line.SetWidth(2f);
        line.SetColor(Color.blue);

        group = new OptionalContentGroup("Blue");
        group.Add(tb);
        group.Add(line);
        // group.SetVisible(true);
        group.DrawOn(page);

        line = new Line();
        line.SetPointA(300f, 260f);
        line.SetPointB(500f, 260f);
        line.SetWidth(2f);
        line.SetColor(Color.red);

        image = new Image(
            pdf,
            new BufferedStream(new FileStream(
                                   "images/BARCODE.PNG", FileMode.Open, FileAccess.Read)),
            ImageType.PNG);
        image.SetLocation(10f, 100f);

        group = new OptionalContentGroup("Barcode");
        group.Add(image);
        group.Add(line);
        group.SetVisible(true);
        group.SetPrintable(true);
        group.DrawOn(page);

        pdf.Close();
    }
Esempio n. 26
0
    public Example_28()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_28.pdf", FileMode.Create)));

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

        f1.SetSize(11f);

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

        f2.SetSize(11f);

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

        StreamReader reader = new StreamReader(
            new FileStream("data/report.csv", FileMode.Open));

        float  y   = 40f;
        String str = null;

        while ((str = reader.ReadLine()) != null)
        {
            new TextLine(f1, str)
            .SetFallbackFont(f2)
            .SetLocation(50f, y += 20f)
            .DrawOn(page);
        }
        reader.Close();

        float x = 50f;

        y = 210f;
        float dy = 22f;

        TextLine      text  = new TextLine(f1);
        StringBuilder buf   = new StringBuilder();
        int           count = 0;

        for (int i = 0x2200; i <= 0x22FF; i++)
        {
            // Draw the Math Symbols
            if (count % 80 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x, y += dy);
                text.DrawOn(page);
                buf.Length = 0;
            }
            buf.Append((char)i);
            count++;
        }
        text.SetText(buf.ToString());
        text.SetLocation(x, y += dy);
        text.DrawOn(page);
        buf.Length = 0;

        count = 0;
        for (int i = 0x25A0; i <= 0x25FF; i++)
        {
            // Draw the Geometric Shapes
            if (count % 80 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x, y += dy);
                text.DrawOn(page);
                buf.Length = 0;
            }
            buf.Append((char)i);
            count++;
        }
        text.SetText(buf.ToString());
        text.SetLocation(x, y += dy);
        text.DrawOn(page);
        buf.Length = 0;

        count = 0;
        for (int i = 0x2701; i <= 0x27ff; i++)
        {
            // Draw the Dingbats
            if (count % 80 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x, y += dy);
                text.DrawOn(page);
                buf.Length = 0;
            }
            buf.Append((char)i);
            count++;
        }
        text.SetText(buf.ToString());
        text.SetLocation(x, y += dy);
        text.DrawOn(page);
        buf.Length = 0;

        count = 0;
        for (int i = 0x2800; i <= 0x28FF; i++)
        {
            // Draw the Braille Patterns
            if (count % 80 == 0)
            {
                text.SetText(buf.ToString());
                text.SetLocation(x, y += dy);
                text.DrawOn(page);
                buf.Length = 0;
            }
            buf.Append((char)i);
            count++;
        }
        text.SetText(buf.ToString());
        text.SetLocation(x, y);
        text.DrawOn(page);

        pdf.Complete();
    }
Esempio n. 27
0
    public Example_45()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_45.pdf", FileMode.Create)),
                          Compliance.PDF_UA);

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

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

        f1.SetSize(14f);
        f2.SetSize(14f);
        // f2.SetItalic(true);

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

        TextLine text = new TextLine(f1);

        text.SetLocation(70f, 70f);
        text.SetText("Hasta la vista!");
        text.SetLanguage("es-MX");
        text.SetStrikeout(true);
        text.SetUnderline(true);
        text.SetURIAction("http://pdfjet.com");
        text.DrawOn(page);

        text = new TextLine(f1);
        text.SetLocation(70f, 90f);
        text.SetText("416-335-7718");
        text.SetURIAction("http://pdfjet.com");
        text.DrawOn(page);

        text = new TextLine(f1);
        text.SetLocation(70f, 120f);
        text.SetText("2014-11-25");
        text.DrawOn(page);

        List <Paragraph> paragraphs = new List <Paragraph>();

        Paragraph paragraph = new Paragraph()
                              .Add(new TextLine(f1,
                                                "The centres also offer free one-on-one consultations with business advisors who can review your business plan and make recommendations to improve it. The small business centres offer practical resources, from step-by-step info on setting up your business to sample business plans to a range of business-related articles and books in our resource libraries."))
                              .Add(new TextLine(f2,
                                                "This text is blue color and is written using italic font.")
                                   .SetColor(Color.blue));

        paragraphs.Add(paragraph);

        Text textArea = new Text(paragraphs);

        textArea.SetLocation(70f, 150f);
        textArea.SetWidth(500f);
        textArea.DrawOn(page);

        float[] xy = (new PlainText(f2, new String[] {
            "The Fibonacci sequence is named after Fibonacci.",
            "His 1202 book Liber Abaci introduced the sequence to Western European mathematics,",
            "although the sequence had been described earlier in Indian mathematics.",
            "By modern convention, the sequence begins either with F0 = 0 or with F1 = 1.",
            "The Liber Abaci began the sequence with F1 = 1, without an initial 0.",
            "",
            "Fibonacci numbers are closely related to Lucas numbers in that they are a complementary pair",
            "of Lucas sequences. They are intimately connected with the golden ratio;",
            "for example, the closest rational approximations to the ratio are 2/1, 3/2, 5/3, 8/5, ... .",
            "Applications include computer algorithms such as the Fibonacci search technique and the",
            "Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting",
            "parallel and distributed systems. They also appear in biological settings, such as branching",
            "in trees, phyllotaxis (the arrangement of leaves on a stem), the fruit sprouts of a pineapple,",
            "the flowering of an artichoke, an uncurling fern and the arrangement of a pine cone.",
        })
                      .SetLocation(70f, 370f)
                      .SetFontSize(10f)
                      .DrawOn(page));

        Box box = new Box();

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

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

        text = new TextLine(f1);
        text.SetLocation(70f, 120f);
        text.SetText("416-877-1395");
        text.DrawOn(page);

        Line line = new Line(70f, 150f, 300f, 150f);

        line.SetWidth(1f);
        line.SetColor(Color.oldgloryred);
        line.SetAltDescription("This is a red line.");
        line.SetActualText("This is a red line.");
        line.DrawOn(page);

        box = new Box();
        box.SetLineWidth(1f);
        box.SetLocation(70f, 200f);
        box.SetSize(100f, 100f);
        box.SetColor(Color.oldgloryblue);
        box.SetAltDescription("This is a blue box.");
        box.SetActualText("This is a blue box.");
        box.DrawOn(page);

        page.AddBMC("Span", "This is a test", "This is a test");
        page.DrawString(f1, "This is a test", 75f, 230f);
        page.AddEMC();

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

        image.SetLocation(70f, 310f);
        image.ScaleBy(0.5f);
        image.SetAltDescription("This is an image of a strawberry.");
        image.SetActualText("This is an image of a strawberry.");
        image.DrawOn(page);

        float w = 530f;
        float h = 13f;

        List <Field> fields = new List <Field>();

        fields.Add(new Field(0f, new String[] { "Company", "Smart Widget Designs" }));
        fields.Add(new Field(0f, new String[] { "Street Number", "120" }));
        fields.Add(new Field(w / 8, new String[] { "Street Name", "Oak" }));
        fields.Add(new Field(5 * w / 8, new String[] { "Street Type", "Street" }));
        fields.Add(new Field(6 * w / 8, new String[] { "Direction", "West" }));
        fields.Add(new Field(7 * w / 8, new String[] { "Suite/Floor/Apt.", "8W" })
                   .SetAltDescription("Suite/Floor/Apartment")
                   .SetActualText("Suite/Floor/Apartment"));
        fields.Add(new Field(0f, new String[] { "City/Town", "Toronto" }));
        fields.Add(new Field(w / 2, new String[] { "Province", "Ontario" }));
        fields.Add(new Field(7 * w / 8, new String[] { "Postal Code", "M5M 2N2" }));
        fields.Add(new Field(0f, new String[] { "Telephone Number", "(416) 331-2245" }));
        fields.Add(new Field(w / 4, new String[] { "Fax (if applicable)", "(416) 124-9879" }));
        fields.Add(new Field(w / 2, new String[] { "Email", "*****@*****.**" }));
        fields.Add(new Field(0f, new String[] { "Other Information",
                                                "We don't work on weekends.", "Please send us an Email." }));

// TODO:
        new Form(fields)
        .SetLabelFont(f1)
        .SetLabelFontSize(7f)
        .SetValueFont(f2)
        .SetValueFontSize(9f)
        .SetLocation(70f, 490f)
        .SetRowLength(w)
        .SetRowHeight(h)
        .DrawOn(page);

        pdf.Complete();
    }
Esempio n. 28
0
    public Example_37()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_37.pdf", FileMode.Create)));

        FileStream fis = new FileStream("data/testPDFs/wirth.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Smalltalk-and-OO.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk1.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/InsideSmalltalk2.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Greenbook.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Bluebook.pdf", FileMode.Open);
        // FileStream fis = new FileStream("data/testPDFs/Orangebook.pdf", FileMode.Open);

        List <PDFobj> objects = pdf.Read(fis);

        fis.Close();

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

        f1.SetSize(72f);

        TextLine line = new TextLine(f1, "This is a test!");

        line.SetLocation(50f, 350f);
        line.SetColor(Color.peru);

        List <PDFobj> pages = pdf.GetPageObjects(objects);

        foreach (PDFobj pageObj in pages)
        {
            GraphicsState gs = new GraphicsState();
            gs.SetAlphaStroking(0.75f);         // Set alpha for stroking operations
            gs.SetAlphaNonStroking(0.75f);      // Set alpha for nonstroking operations
            pageObj.SetGraphicsState(gs, objects);

            Page page = new Page(pdf, pageObj);
            page.AddResource(f1, objects);
            page.SetBrushColor(Color.blue);
            page.DrawString(f1, "Hello, World!", 50f, 200f);

            line.DrawOn(page);

            page.Complete(objects); // The graphics stack is unwinded automatically
        }
        pdf.AddObjects(objects);

/*
 *      List<Image> images = new List<Image>();
 *      foreach (PDFobj obj in objects.Values) {
 *          if (obj.GetValue("/Subtype").Equals("/Image")) {
 *              float w = float.Parse(obj.GetValue("/Width"));
 *              float h = float.Parse(obj.GetValue("/Height"));
 *              if (w > 500f && h > 500f) {
 *                  images.Add(new Image(pdf, obj));
 *              }
 *          }
 *      }
 *
 *      Font f1 = new Font(pdf, CoreFont.HELVETICA);
 *      f1.SetSize(72f);
 *
 *      Page page = null;
 *      foreach (Image image in images) {
 *          page = new Page(pdf, A4.PORTRAIT);
 *
 *          GraphicsState gs = new GraphicsState();
 *          gs.Set_CA(0.7f);    // Stroking alpha
 *          gs.Set_ca(0.7f);    // Nonstroking alpha
 *          page.SetGraphicsState(gs);
 *
 *          image.ResizeToFit(page, true);
 *
 *          // image.FlipUpsideDown(true);
 *          // image.SetLocation(0f, -image.GetHeight());
 *
 *          // image.SetRotate(ClockWise._180_degrees);
 *          // image.SetLocation(0f, 0f);
 *
 *          image.DrawOn(page);
 *
 *          TextLine text = new TextLine(f1, "Hello, World!");
 *          text.SetColor(Color.blue);
 *          text.SetLocation(150f, 150f);
 *          text.DrawOn(page);
 *
 *          page.SetGraphicsState(new GraphicsState());
 *      }
 */
        pdf.Complete();
    }
Esempio n. 29
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();
    }
Esempio n. 30
0
    public Example_01()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_01.pdf", FileMode.Create)));

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

        font1.SetSize(12f);

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

        font2.SetSize(12f);

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

        TextLine textLine = new TextLine(font1, "Happy New Year!");

        textLine.SetLocation(70f, 70f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "С Новым Годом!");
        textLine.SetLocation(70f, 100f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "Ευτυχισμένο το Νέο Έτος!");
        textLine.SetLocation(70f, 130f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "新年快樂!");
        textLine.SetFallbackFont(font2);
        textLine.SetLocation(300f, 70f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "新年快乐!");
        textLine.SetFallbackFont(font2);
        textLine.SetLocation(300f, 100f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "明けましておめでとうございます!");
        textLine.SetFallbackFont(font2);
        textLine.SetLocation(300f, 130f);
        textLine.DrawOn(page);

        textLine = new TextLine(font1, "새해 복 많이 받으세요!");
        textLine.SetFallbackFont(font2);
        textLine.SetLocation(300f, 160f);
        textLine.DrawOn(page);

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

        List <Paragraph> paragraphs = new List <Paragraph>();
        Paragraph        paragraph  = null;

        StreamReader reader = new StreamReader(
            new FileStream("data/LCG.txt", FileMode.Open));
        int    i = 0;
        String line;

        while ((line = reader.ReadLine()) != null)
        {
            if (line.Equals(""))
            {
                continue;
            }
            paragraph = new Paragraph();
            textLine  = new TextLine(font1, line);
            textLine.SetFallbackFont(font2);
            paragraph.Add(textLine);
            paragraphs.Add(paragraph);
            if (i == 0)
            {
                textLine = new TextLine(font1,
                                        "Hello, World! This is a test to check if this line will be wrapped around properly.");
                textLine.SetColor(Color.blue);
                textLine.SetUnderline(true);
                paragraph.Add(textLine);

                textLine = new TextLine(font1, "This is a test!");
                textLine.SetColor(Color.oldgloryred);
                textLine.SetUnderline(true);
                paragraph.Add(textLine);
            }
            i++;
        }

        Text text = new Text(paragraphs);

        text.SetLocation(50f, 50f);
        text.SetWidth(500f);
        float[] xy = text.DrawOn(page);

        List <float[]> points = text.GetBeginParagraphPoints();
        int            n      = 0;

        foreach (float[] point in points)
        {
            textLine = new TextLine(font1, (n + 1).ToString() + ".");
            textLine.SetLocation(point[0] - 20.0, point[1]);
            textLine.DrawOn(page);
            n++;
        }

        Box box = new Box();

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

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

        paragraphs = new List <Paragraph>();

        reader = new StreamReader(
            new FileStream("data/CJK.txt", FileMode.Open));

        while ((line = reader.ReadLine()) != null)
        {
            if (line.Equals(""))
            {
                continue;
            }
            paragraph = new Paragraph();
            textLine  = new TextLine(font2, line);
            textLine.SetFallbackFont(font1);
            paragraph.Add(textLine);
            paragraphs.Add(paragraph);
        }
        text = new Text(paragraphs);
        text.SetLocation(50f, 50f);
        text.SetWidth(500f);
        text.DrawOn(page);

        pdf.Complete();
    }