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();
    }
示例#2
0
        private void DrawLineOfText(
            Page page, List <TextLine> list, bool draw)
        {
            if (alignment == Align.JUSTIFY)
            {
                float sum_of_word_widths = 0f;
                for (int i = 0; i < list.Count; i++)
                {
                    TextLine text = list[i];
                    sum_of_word_widths += text.font.StringWidth(text.GetFallbackFont(), text.str);
                }
                float dx = (w - sum_of_word_widths) / (list.Count - 1);
                for (int i = 0; i < list.Count; i++)
                {
                    TextLine text = list[i];
                    text.SetPosition(x1, y1);

                    if (text.GetGoToAction() != null)
                    {
                        page.AddAnnotation(new Annotation(
                                               null,                 // The URI
                                               text.GetGoToAction(), // The destination name
                                               x,
                                               page.height - (y - text.font.ascent),
                                               x + text.font.StringWidth(text.GetFallbackFont(), text.GetText()),
                                               page.height - (y - text.font.descent),
                                               null,
                                               null,
                                               null));
                    }

                    if (rotate == 0)
                    {
                        text.SetTextDirection(0);
                        text.DrawOn(page, draw);
                        x1 += text.font.StringWidth(text.GetFallbackFont(), text.str) + dx;
                    }
                    else if (rotate == 90)
                    {
                        text.SetTextDirection(90);
                        text.DrawOn(page, draw);
                        y1 -= text.font.StringWidth(text.GetFallbackFont(), text.str) + dx;
                    }
                    else if (rotate == 270)
                    {
                        text.SetTextDirection(270);
                        text.DrawOn(page, draw);
                        y1 += text.font.StringWidth(text.GetFallbackFont(), text.str) + dx;
                    }
                }
            }
            else
            {
                DrawNonJustifiedLine(page, list, draw);
            }
        }
示例#3
0
 //-------------------------------------------------------------------------------------------
 private void DrawText(PDFjet.NET.PDF pdf, PDFjet.NET.Page page, string text, int x, int y)
 {
     Font f1 = new Font(pdf, "Helvetica");
        f1.SetSize(10);
        PDFjet.NET.TextLine tLine = new TextLine(f1);
        tLine.SetText(text);
        tLine.SetPosition(x, y);
        //tLine.SetURIAction("http://www.weavver.com/accounting/");
        tLine.DrawOn(page);
 }
示例#4
0
 public void AddComponent(TextLine component)
 {
     if (component.GetTextEffect() == 2)
     {
         component.GetFont().SetSize(this.fontSize * this.superscript_size_factor);
         component.SetPosition(this.current[0], this.current[1] - this.fontSize * this.superscript_position);
     }
     else
     {
         if (component.GetTextEffect() == 1)
         {
             component.GetFont().SetSize(this.fontSize * this.subscript_size_factor);
             component.SetPosition(this.current[0], this.current[1] + this.fontSize * this.subscript_position);
         }
         else
         {
             component.GetFont().SetSize(this.fontSize);
             component.SetPosition(this.current[0], this.current[1]);
         }
     }
     this.current[0] += (double)component.GetWidth();
     this.textLines.Add(component);
 }
示例#5
0
 /**
  *  Add a new text line.
  *
  *  Find the current font, current size and effects (normal, super or subscript)
  *  Set the position of the component to the starting stored as current position
  *  Set the size and offset based on effects
  *  Set the new current position
  *
  *  @param component the component.
  */
 public void AddComponent(TextLine component)
 {
     if (component.GetTextEffect() == Effect.SUPERSCRIPT)
     {
         component.GetFont().SetSize(fontSize * superscript_size_factor);
         component.SetPosition(
             current[X],
             current[Y] - fontSize * superscript_position);
     }
     else if (component.GetTextEffect() == Effect.SUBSCRIPT)
     {
         component.GetFont().SetSize(fontSize * subscript_size_factor);
         component.SetPosition(
             current[X],
             current[Y] + fontSize * subscript_position);
     }
     else
     {
         component.GetFont().SetSize(fontSize);
         component.SetPosition(current[X], current[Y]);
     }
     current[X] += component.GetWidth();
     textLines.Add(component);
 }
示例#6
0
        private void DrawNonJustifiedLine(
            Page page, List <TextLine> list, bool draw)
        {
            float run_length = 0f;

            for (int i = 0; i < list.Count; i++)
            {
                TextLine text = list[i];
                if (i < (list.Count - 1))
                {
                    text.str += " ";
                }
                run_length += text.font.StringWidth(text.GetFallbackFont(), text.str);
            }

            if (alignment == Align.CENTER)
            {
                if (rotate == 0)
                {
                    x1 = x + ((w - run_length) / 2);
                }
                else if (rotate == 90)
                {
                    y1 = y - ((w - run_length) / 2);
                }
                else if (rotate == 270)
                {
                    y1 = y + ((w - run_length) / 2);
                }
            }
            else if (alignment == Align.RIGHT)
            {
                if (rotate == 0)
                {
                    x1 = x + (w - run_length);
                }
                else if (rotate == 90)
                {
                    y1 = y - (w - run_length);
                }
                else if (rotate == 270)
                {
                    y1 = y + (w - run_length);
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                TextLine text = list[i];
                text.SetPosition(x1, y1);

                if (text.GetGoToAction() != null)
                {
                    page.AddAnnotation(new Annotation(
                                           null,                 // The URI
                                           text.GetGoToAction(), // The destination name
                                           x,
                                           page.height - (y - text.font.ascent),
                                           x + text.font.StringWidth(text.GetFallbackFont(), text.GetText()),
                                           page.height - (y - text.font.descent),
                                           null,
                                           null,
                                           null));
                }

                if (rotate == 0)
                {
                    text.SetTextDirection(0);
                    text.DrawOn(page, draw);
                    x1 += text.font.StringWidth(text.GetFallbackFont(), text.str);
                }
                else if (rotate == 90)
                {
                    text.SetTextDirection(90);
                    text.DrawOn(page, draw);
                    y1 -= text.font.StringWidth(text.GetFallbackFont(), text.str);
                }
                else if (rotate == 270)
                {
                    text.SetTextDirection(270);
                    text.DrawOn(page, draw);
                    y1 += text.font.StringWidth(text.GetFallbackFont(), text.str);
                }
            }
        }
    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();
    }
        /// <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);
        }
        /// <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);
        }
示例#10
0
 /**
  *  Add a new text line.
  *
  *  Find the current font, current size and effects (normal, super or subscript)
  *  Set the position of the component to the starting stored as current position
  *  Set the size and offset based on effects
  *  Set the new current position
  *
  *  @param component the component.
  */
 public void AddComponent(TextLine component)
 {
     if (component.GetTextEffect() == Effect.SUPERSCRIPT) {
     component.GetFont().SetSize(fontSize * superscript_size_factor);
     component.SetPosition(
             current[X],
             current[Y] - fontSize * superscript_position);
     }
     else if (component.GetTextEffect() == Effect.SUBSCRIPT) {
     component.GetFont().SetSize(fontSize * subscript_size_factor);
     component.SetPosition(
             current[X],
             current[Y] + fontSize * subscript_position);
     }
     else {
     component.GetFont().SetSize(fontSize);
     component.SetPosition(current[X], current[Y]);
     }
     current[X] += component.GetWidth();
     textLines.Add(component);
 }
示例#11
0
 public Title SetLocation(float x, float y)
 {
     prefix.SetLocation(x, y);
     textLine.SetPosition(x, y);
     return(this);
 }
示例#12
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();
    }