MoveTo() public method

public MoveTo ( float x, float y ) : void
x float
y float
return void
        // ---------------------------------------------------------------------------    
        /**
         * Draws the time table for a day at the film festival.
         * @param directcontent a canvas to which the time table has to be drawn.
         */
        protected void DrawTimeTable(PdfContentByte directcontent)
        {
            directcontent.SaveState();
            directcontent.SetLineWidth(1.2f);
            float llx, lly, urx, ury;

            llx = OFFSET_LEFT;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LEFT + WIDTH;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePath();
            directcontent.Stroke();

            llx = OFFSET_LOCATION;
            lly = OFFSET_BOTTOM;
            urx = OFFSET_LOCATION + WIDTH_LOCATION;
            ury = OFFSET_BOTTOM + HEIGHT;
            directcontent.MoveTo(llx, lly);
            directcontent.LineTo(urx, lly);
            directcontent.LineTo(urx, ury);
            directcontent.LineTo(llx, ury);
            directcontent.ClosePathStroke();

            directcontent.SetLineWidth(1);
            directcontent.MoveTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM
            );
            directcontent.LineTo(
              OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM + HEIGHT
            );
            float y;
            for (int i = 1; i < LOCATIONS; i++)
            {
                y = OFFSET_BOTTOM + (i * HEIGHT_LOCATION);
                if (i == 2 || i == 6)
                {
                    directcontent.MoveTo(OFFSET_LOCATION, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                else
                {
                    directcontent.MoveTo(OFFSET_LOCATION + WIDTH_LOCATION / 2, y);
                    directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y);
                }
                directcontent.MoveTo(OFFSET_LEFT, y);
                directcontent.LineTo(OFFSET_LEFT + WIDTH, y);
            }
            directcontent.Stroke();
            directcontent.RestoreState();
        }
Example #2
0
 private static PdfTemplate PdfFooter(PdfContentByte cb)
 {
     // Create the template and assign height
     PdfTemplate tmpFooter = cb.CreateTemplate(580, 70);
     // Move to the bottom left corner of the template
     tmpFooter.MoveTo(1, 1);
     // Place the footer content
     tmpFooter.Stroke();
     // Begin writing the footer
     tmpFooter.BeginText();
     // Set the font and size
     tmpFooter.SetFontAndSize(_baseFont, 8);
     // Write out details from the payee table
     tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "De facturen zijn contant betaalbaar te Tielt of op rekeningnummer", cb.PdfWriter.PageSize.Width / 2, 45, 0);
     tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "733-0318587-69 bij KBC of 001-6090654-03 bij BNP Paribas Fortis", cb.PdfWriter.PageSize.Width / 2, 35, 0);
     tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Alle klachten dienen binnen de 24 uren, na de uitgevoerde werken schriftelijk medegedeeld te worden.", cb.PdfWriter.PageSize.Width / 2, 25, 0);
     tmpFooter.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Bij geschillen is enkel de rechtbank van Brugge bevoegd.", cb.PdfWriter.PageSize.Width / 2, 15, 0);
     // End text
     tmpFooter.EndText();
     // Stamp a line above the page footer
     cb.SetLineWidth(0f);
     cb.MoveTo(30, 60);
     cb.LineTo(570, 60);
     cb.Stroke();
     // Return the footer template
     return tmpFooter;
 }
 public void DrawLine(
   PdfContentByte cb, float x1, float x2, float y
   )
 {
     cb.MoveTo(x1, y);
     cb.LineTo(x2, y);
     cb.Stroke();
 }
 // ---------------------------------------------------------------------------
 /**
  * Creates a path for a five pointed star.
  * This method doesn't fill or stroke the star!
  * @param canvas the canvas for which the star is constructed
  * @param x      the X coordinate of the center of the star
  * @param y      the Y coordinate of the center of the star
  */
 public static void CreateStar(PdfContentByte canvas, float x, float y)
 {
     canvas.MoveTo(x + 10, y);
       canvas.LineTo(x + 80, y + 60);
       canvas.LineTo(x, y + 60);
       canvas.LineTo(x + 70, y);
       canvas.LineTo(x + 40, y + 90);
       canvas.ClosePath();
 }
        private void DirectDrawReport(PdfContentByte canvas)
        {
            //画线
            canvas.SaveState();
            canvas.SetLineWidth(2f);
            canvas.MoveTo(100, 100);
            canvas.LineTo(200, 200);
            canvas.Stroke();
            canvas.RestoreState();

            //文本
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("JulyLuo测试", new Font(BF_Light, 10)), 100, 20, 0);
        }
Example #6
0
        private static void Render_BackBase(PdfContentByte under)
        {
            // Y relative to card top, line width, <repeat>
            float[] measures = new[] { 37, 3f, 144, 1.5f };

            under.SaveState();
            for (int i = 0; i < measures.Length / 2; i++)
            {
                under.SetLineWidth(measures[i * 2 + 1]);
                under.MoveTo(0, CARD_HEIGHT - measures[i * 2]);
                under.LineTo(CARD_WIDTH, CARD_HEIGHT - measures[i * 2]);
                under.Stroke();
            }

            under.SetFontAndSize(baseFont, 7);
            under.ShowTextAlignedKerned(Element.ALIGN_CENTER, "If found, please call KCSAR at (206) 205-8226", CARD_WIDTH / 2, 7, 0);

            under.RestoreState();
        }
Example #7
0
        /// <summary>
        /// 处理单个页面。
        /// </summary>
        /// <param name="pgs"></param>
        /// <param name="items"></param>
        private void ProcessPage(Pages pgs, IEnumerable items)
        {
            foreach (PageItem pi in items)
            {
                //if (pi.SI.BackgroundImage != null)
                //{
                //    PageImage bgImg = pi.SI.BackgroundImage;
                //    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bgImg.ImageData);
                //    document.Add(image);
                //}

                if (pi is PageTextHtml)
                {
                    PageTextHtml pth = pi as PageTextHtml;
                    pth.Build(pgs.G);
                    ProcessPage(pgs, pth);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;

                    iTextSharp.text.pdf.PdfContentByte cb = this.pdfWriter.DirectContent;

                    float y = getYvalue(pi.Y, pt.H);

                    //边线

                    if (pi.SI.BStyleLeft != BorderStyleEnum.None)
                    {
                        cb.MoveTo(pt.X, y);
                        cb.SetLineWidth(pi.SI.BWidthLeft);
                        cb.SetRGBColorStrokeF(pi.SI.BColorLeft.R, pi.SI.BColorLeft.G, pi.SI.BColorLeft.B);

                        cb.LineTo(pt.X, y + pt.H);

                        cb.Stroke();
                    }

                    if (pi.SI.BStyleRight != BorderStyleEnum.None)
                    {
                        cb.MoveTo(pt.X + pt.W, y);
                        cb.SetLineWidth(pi.SI.BWidthRight);
                        cb.SetRGBColorStrokeF(pi.SI.BColorRight.R, pi.SI.BColorRight.G, pi.SI.BColorRight.B);

                        cb.LineTo(pt.X + pt.W, y + pt.H);

                        cb.Stroke();
                    }

                    if (pi.SI.BStyleTop != BorderStyleEnum.None)
                    {
                        cb.MoveTo(pt.X, y + pt.H);
                        cb.SetLineWidth(pi.SI.BWidthTop);
                        cb.SetRGBColorStrokeF(pi.SI.BColorTop.R, pi.SI.BColorTop.G, pi.SI.BColorTop.B);

                        cb.LineTo(pt.X + pt.W, y + pt.H);

                        cb.Stroke();
                    }

                    if (pi.SI.BStyleBottom != BorderStyleEnum.None)
                    {
                        cb.MoveTo(pt.X, y);
                        cb.SetLineWidth(pi.SI.BWidthTop);
                        cb.SetRGBColorStrokeF(pi.SI.BColorTop.R, pi.SI.BColorTop.G, pi.SI.BColorTop.B);

                        cb.LineTo(pt.X + pt.W, y);

                        cb.Stroke();
                    }

                    //绝对定义文字

                    iTextSharp.text.Font font = TextUtility.GetFont(pi.SI, pt.Text);

                    float[]  widih;
                    string[] sa = MeasureString(pt, pgs.G, out widih);

                    int rows = sa.Length;

                    //x标准固定

                    float x     = pt.X + pi.SI.PaddingLeft;
                    int   align = iTextSharp.text.pdf.PdfContentByte.ALIGN_LEFT;

                    if (pi.SI.TextAlign == TextAlignEnum.Right)
                    {
                        align = iTextSharp.text.pdf.PdfContentByte.ALIGN_RIGHT;
                        x     = pt.X + pt.W - pi.SI.PaddingRight - 1;
                    }
                    else if (pi.SI.TextAlign == TextAlignEnum.Center)
                    {
                        align = iTextSharp.text.pdf.PdfContentByte.ALIGN_CENTER;
                        x     = pt.X + pt.W / 2;
                    }

                    cb.BeginText();
                    cb.SetFontAndSize(font.BaseFont, font.Size);

                    for (int i = 0; i < rows; i++)
                    {
                        float Yt = y + i * font.Size + 1;

                        if (pi.SI.VerticalAlign == VerticalAlignEnum.Top)
                        {
                            Yt = y + pt.H - font.Size * (rows - (i + 1)) - 1;
                        }
                        else if (pi.SI.VerticalAlign == VerticalAlignEnum.Middle)
                        {
                            Yt = y + (pt.H - font.Size * rows) / 2 + i * font.Size + 1;
                        }

                        cb.ShowTextAligned(align, sa[rows - i - 1], x, Yt, 0);
                        cb.EndText();
                    }

                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;

                    iTextSharp.text.pdf.PdfContentByte cb = this.pdfWriter.DirectContent;

                    float y1 = getYvalue(pl.Y, 0);
                    float y2 = getYvalue(pl.Y2, 0);

                    cb.MoveTo(pl.X, y1);
                    cb.LineTo(pl.X2, y2);

                    cb.Stroke();

                    continue;
                }

                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;

                    iTextSharp.text.pdf.PdfContentByte cb = this.pdfWriter.DirectContent;

                    float y = this.getYvalue(i.Y, i.H);

                    System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(i.X + i.SI.PaddingLeft, y - i.SI.PaddingTop, i.W - i.SI.PaddingLeft - i.SI.PaddingRight, i.H - i.SI.PaddingTop - i.SI.PaddingBottom);

                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(i.ImageData);

                    image.SetAbsolutePosition(i.X, y);
                    image.ScaleAbsoluteHeight(i.H);
                    image.ScaleAbsoluteWidth(i.W);

                    cb.AddImage(image);

                    cb.Stroke();

                    continue;
                }

                if (pi is PageRectangle)
                {
                    PageRectangle pr = pi as PageRectangle;

                    iTextSharp.text.Rectangle r2 = new iTextSharp.text.Rectangle(pr.X, pr.Y, pr.W, pr.H);
                    r2.Border = 1;
                    document.Add(r2);
                    continue;
                }
            }
        }
Example #8
0
 /**
 * Draws a horizontal line.
 * @param canvas the canvas to draw on
 * @param leftX      the left x coordinate
 * @param rightX the right x coordindate
 * @param y          the y coordinate
 */
 public void DrawLine(PdfContentByte canvas, float leftX, float rightX, float y)
 {
     float w;
     if (Percentage < 0)
         w = -Percentage;
     else
         w = (rightX - leftX) * Percentage / 100.0f;
     float s;
     switch (Alignment) {
         case Element.ALIGN_LEFT:
             s = 0;
             break;
         case Element.ALIGN_RIGHT:
             s = rightX - leftX - w;
             break;
         default:
             s = (rightX - leftX - w) / 2;
             break;
     }
     canvas.SetLineWidth(LineWidth);
     if (LineColor != null)
         canvas.SetColorStroke(LineColor);
     canvas.MoveTo(s + leftX, y + offset);
     canvas.LineTo(s + w + leftX, y + offset);
     canvas.Stroke();
 }
Example #9
0
 protected override void Draw(PdfContentByte cb)
 {
     cb.MoveTo(x1, y1);
     cb.LineTo(x2, y2);
 }
Example #10
0
        /// <summary>
        /// Draws the box on the cover page that contains the date
        /// </summary>
        /// <param name="cb"></param>
        /// <param name="doc"></param>
        /// <param name="project"></param>
        private void DrawBoxForCover(PdfContentByte cb, Document doc)
        {
            // set the colors
            cb.SetColorStroke(_baseColor);
            cb.SetColorFill(_baseColor);

            // calculate the top left corner of the box
            var x = doc.LeftMargin;
            var y = doc.BottomMargin + 678;

            var height = 60;

            // move the cursor to starting position
            cb.MoveTo(x, y);

            // draw the top line
            cb.LineTo(x + _pageWidth, y);

            // draw the right line
            cb.LineTo(x + _pageWidth, y - height);

            // draw the bottom line
            cb.LineTo(x, y - height);

            // draw the left line
            cb.LineTo(x, y);

            cb.ClosePathFillStroke();
            cb.Stroke();

            // add the text inside the box
            cb.BeginText();
            cb.SetFontAndSize(_dateBaseFont, 26f);
            cb.SetColorStroke(BaseColor.WHITE);
            cb.SetColorFill(BaseColor.WHITE);
            cb.SetTextMatrix(x + 10, y - 40);
            cb.ShowText(string.Format("{0:MMMM dd, yyyy}", DateTime.Now));
            cb.EndText();
        }
Example #11
0
// ---------------------------------------------------------------------------    
    /**
     * Draws the time slots for a day at the film festival.
     * @param directcontent the canvas to which the time table has to be drawn.
     */
    protected void DrawTimeSlots(PdfContentByte directcontent) {
      directcontent.SaveState();
      float x;
      for (int i = 1; i < TIMESLOTS; i++) {
        x = OFFSET_LEFT + (i * WIDTH_TIMESLOT);
        directcontent.MoveTo(x, OFFSET_BOTTOM);
        directcontent.LineTo(x, OFFSET_BOTTOM + HEIGHT);
      }
      directcontent.SetLineWidth(0.3f);
      directcontent.SetColorStroke(BaseColor.GRAY);
      directcontent.SetLineDash(3, 1);
      directcontent.Stroke();
      directcontent.RestoreState();
    }    
Example #12
0
        private void ButtonHome2_Click(object sender, EventArgs e)
        {
            string name = "";

            try
            {
                Panel p = (Panel)sender;
                name = f.GetNameOfButton(p);
            }
            catch { }
            try
            {
                Label l = (Label)sender;
                name = l.Text;
            }
            catch { }
            try
            {
                PictureBox pb = (PictureBox)sender;
                name = f.GetNameOfButton(panel2, pb);
            }
            catch { }
            if (name == "Удалить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies     cur     = (Agencies)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить это турагенство ({cur.dataGridView1.SelectedRows.Count}), его аккаунт и все путевки?", "Да", "Нет", "Удаление_Агентства_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel     cur     = (OneHotel)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот тип номера ({cur.dataGridView1.SelectedRows.Count})?", "Да", "Нет", "Удаление_Номера_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(OneVoucher))
                {
                    OneVoucher   cur     = (OneVoucher)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить эту составляющую путевки?", "Да", "Нет", "Удаление_Человека_Полета_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    Vouchers     cur     = (Vouchers)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить эту путевку ({cur.dataGridView1.SelectedRows.Count})?", "Да", "Нет", "Удаление_Путевки_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels       cur     = (Hotels)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот отель ({cur.dataGridView1.SelectedRows.Count}) и все его путевки?", "Да", "Нет", "Удаление_Отеля_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes       cur     = (Routes)State;
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", $"Вы хотите удалить этот рейс ({cur.dataGridView1.SelectedRows.Count}) и отменить все путевки по нем?", "Да", "Нет", "Удаление_Рейса_Да", "Выход_Нет");
                    message.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts cur = (Accounts)State;
                    int      i   = cur.dataGridView1.SelectedRows.Count;
                    i = Math.Max(i, cur.dataGridView2.SelectedRows.Count);
                    string str = $"Вы хотите удалить этот аккаунт ({i}), его тураегнтство и все путевки?";
                    if (cur.dataGridView2.SelectedRows.Count != 0)
                    {
                        str = $"Вы хотите удалить этот аккаунт ({i})?";
                    }
                    MyMessageBox message = new MyMessageBox(this, "Предупреждение", str, "Да", "Нет", "Удаление_Аккаунта_Да", "Выход_Нет");
                    message.Show();
                }
            }
            if (name == "Изменить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies      cur = (Agencies)State;
                    AddTouragency at  = new AddTouragency(this);
                    at.label4.Text          = "Edit Touragency";
                    at.Yes.Text             = "Изменить";
                    at.textBox0.Text        = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.comboBox1.Visible    = false;
                    at.textBox2.Visible     = true;
                    at.label8.Visible       = false;
                    at.textBox2.Text        = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                    at.textBox1.Text        = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    at.dateTimePicker1.Text = cur.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    at.textBox3.Text        = cur.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                    at.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    DataGridViewRow cur = ((Vouchers)State).dataGridView1.SelectedRows[0];
                    AddVoucher      at  = new AddVoucher(this);
                    at.label4.Text            = "Edit Voucher";
                    at.Yes.Text               = "Изменить";
                    at.textBox2.Text          = cur.Cells[0].Value.ToString();
                    at.comboBox5.SelectedItem = cur.Cells[5].Value.ToString();
                    at.dateTimePicker1.Value  = Convert.ToDateTime(cur.Cells[3].Value.ToString());
                    c.Open();
                    string sql = $"SELECT Agency.Name, a.Name, aa.Name, Airport.Code, Airport.Name, h.Name, hh.Name" +
                                 $", Hotel.Name, Room.TypeRoom, Voucher.NumNights " +
                                 "FROM Agency, Country a, Country h, City aa, City hh, Airport, Hotel, Room, voucher " +
                                 $"WHERE Voucher.ID = '{cur.Cells[0].Value.ToString()}' AND Voucher.idTypeRoom = Room.ID AND Voucher.CodeAirport = Airport.Code " +
                                 "AND Airport.idCity = aa.ID AND aa.idCountry = a.ID AND Room.idHotel = Hotel.ID AND Hotel.idCity = hh.ID " +
                                 "AND hh.idCountry = h.ID AND Voucher.Login = Agency.Login";
                    MySqlCommand    command1 = new MySqlCommand(sql, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    reader1.Read();
                    at.comboBox8.SelectedItem = reader1[0].ToString();
                    at.comboBox7.SelectedItem = reader1[1].ToString();
                    at.comboBox6.SelectedItem = reader1[2].ToString();
                    at.comboBox9.SelectedItem = reader1[3].ToString() + $" ({reader1[4].ToString()})";
                    at.comboBox2.SelectedItem = reader1[5].ToString();
                    at.comboBox3.SelectedItem = reader1[6].ToString();
                    at.comboBox1.SelectedItem = reader1[7].ToString();
                    at.comboBox4.SelectedItem = reader1[8].ToString();
                    at.textBox1.Text          = reader1[9].ToString();
                    c.Close();
                    at.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel cur = (OneHotel)State;
                    AddRoom  at  = new AddRoom(this);
                    at.label4.Text   = "Edit Room";
                    at.Yes.Text      = "Изменить";
                    at.textBox1.Text = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.textBox2.Text = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Split(' ')[0];
                    at.textBox3.Text = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    at.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    AddRoute at = new AddRoute(this, false);
                    at.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts cur = (Accounts)State;
                    string   p   = "";
                    if (cur.dataGridView1.SelectedRows.Count != 0)
                    {
                        p = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    }
                    else
                    {
                        p = cur.dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
                    }
                    AddAccount at = new AddAccount(new AddTouragency(this), new User(p));
                    at.label4.Text = "Edit Account";
                    at.Yes.Text    = "Изменить";
                    if (cur.dataGridView1.SelectedRows.Count != 0)
                    {
                        at.textBox0.Text     = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                        at.comboBox1.Visible = false;
                        at.textBox2.Visible  = true;
                        at.textBox1.Text     = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                        at.Show();
                    }
                    else
                    {
                        at.textBox0.Text     = cur.dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
                        at.comboBox1.Visible = false;
                        at.textBox2.Visible  = true;
                        at.textBox2.Text     = "Администратор";
                        at.textBox1.Text     = cur.dataGridView2.SelectedRows[0].Cells[1].Value.ToString();
                        at.Show();
                    }
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   cur = (Hotels)State;
                    AddHotel at  = new AddHotel(this);
                    at.label4.Text   = "Edit Hotel";
                    at.Yes.Text      = "Изменить";
                    at.textBox0.Text = cur.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    at.textBox1.Text = cur.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    string str = cur.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

                    switch (str)
                    {
                    case "RO":
                        str = "RO - Room Only";
                        break;

                    case "BB":
                        str = "BB - Bed & Breakfast";
                        break;

                    case "HB":
                        str = "HB - Half Board";
                        break;

                    case "FB":
                        str = "FB - Full Board";
                        break;

                    case "AI":
                        str = "AI - All Inclusive";
                        break;

                    case "UAI":
                        str = "UAI - Ultra All Inclusive";
                        break;
                    }
                    at.comboBox1.Text         = str;
                    at.comboBox2.SelectedItem = cur.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                    at.comboBox3.SelectedItem = cur.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    at.ID = int.Parse(cur.dataGridView1.SelectedRows[0].Cells[5].Value.ToString());
                    at.Show();
                }
            }
            if (name == "Добавить")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies      cur = (Agencies)State;
                    AddTouragency at  = new AddTouragency(this);

                    at.Show();
                }
                if (State.GetType() == typeof(OneHotel))
                {
                    OneHotel cur = (OneHotel)State;
                    AddRoom  at  = new AddRoom(this);

                    at.Show();
                }
                if (State.GetType() == typeof(Accounts))
                {
                    Accounts   acc = (Accounts)State;
                    AddAccount aa  = new AddAccount(new AddTouragency(this));
                    aa.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   acc = (Hotels)State;
                    AddHotel aa  = new AddHotel(this);
                    aa.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes   acc = (Routes)State;
                    AddRoute aa  = new AddRoute(this);
                    aa.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    AddVoucher aa = new AddVoucher(this);
                    aa.Show();
                }
            }
            if (name == "Фильтр")
            {
                if (State.GetType() == typeof(Agencies))
                {
                    string SQL1 = "SELECT Max(comission) FROM Agency";
                    string SQL2 = "SELECT Min(comission) FROM Agency";
                    string SQL3 = "SELECT Max(dateLicense) FROM Agency";
                    string SQL4 = "SELECT Min(dateLicense) FROM Agency";
                    int    maxc = 0;
                    c.Open();
                    MySqlCommand    command = new MySqlCommand(SQL1, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        maxc = Convert.ToInt32(reader[0]);
                    }
                    c.Close();
                    Agencies     cur    = (Agencies)State;
                    FilterAgency filter = new FilterAgency(this);
                    int          minc   = 0;
                    c.Open();
                    MySqlCommand    command1 = new MySqlCommand(SQL2, c);
                    MySqlDataReader reader1  = command1.ExecuteReader();
                    while (reader1.Read())
                    {
                        minc = Convert.ToInt32(reader1[0]);
                    }
                    c.Close();
                    DateTime maxd = new DateTime();
                    c.Open();
                    MySqlCommand    command2 = new MySqlCommand(SQL3, c);
                    MySqlDataReader reader2  = command2.ExecuteReader();
                    while (reader2.Read())
                    {
                        maxd = Convert.ToDateTime(reader2[0]);
                    }
                    c.Close();
                    DateTime mind = new DateTime();
                    c.Open();
                    MySqlCommand    command3 = new MySqlCommand(SQL4, c);
                    MySqlDataReader reader3  = command3.ExecuteReader();
                    while (reader3.Read())
                    {
                        mind = Convert.ToDateTime(reader3[0]);
                    }
                    c.Close();
                    filter.textBox3.Text         = minc.ToString();
                    filter.textBox4.Text         = maxc.ToString();
                    filter.dateTimePicker1.Value = mind;
                    filter.dateTimePicker2.Value = maxd;
                    filter.Show();
                }
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels   acc = (Hotels)State;
                    AddHotel aa  = new AddHotel(this);
                    aa.label4.Text     = "Filter";
                    aa.Yes.Visible     = false;
                    aa.No.Visible      = false;
                    aa.button1.Visible = true;
                    aa.label7.Visible  = false;
                    aa.label8.Visible  = false;
                    aa.Show();
                }
                if (State.GetType() == typeof(Routes))
                {
                    Routes      acc = (Routes)State;
                    FilterRoute aa  = new FilterRoute(this);
                    aa.label4.Text = "Filter";


                    aa.Show();
                }
            }
            if (name == "Выполнить")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    SQLQuery sq = (SQLQuery)State;
                    c.Open();
                    MySqlCommand    command = new MySqlCommand(sq.richTextBox1.Text, c);
                    MySqlDataReader reader  = command.ExecuteReader();
                    sq.dataGridView1.Rows.Clear();
                    sq.dataGridView1.Columns.Clear();
                    for (int i = 0; i < reader.VisibleFieldCount; i++)
                    {
                        DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                        column.Name       = "column" + i;
                        column.HeaderText = reader.GetName(i);
                        column.Width      = (sq.dataGridView1.Width - 35) / reader.VisibleFieldCount;
                        sq.dataGridView1.Columns.Add(column);
                    }
                    while (reader.Read())
                    {
                        int num = sq.dataGridView1.Rows.Add();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            sq.dataGridView1.Rows[num].Cells[i].Value = reader[i];
                            if (reader[i].GetType() == typeof(DateTime))
                            {
                                DateTime dt = Convert.ToDateTime(reader[i]);
                                if (dt.Hour == 0 && dt.Minute == 0 && dt.Second == 0)
                                {
                                    sq.dataGridView1.Rows[num].Cells[i].Value = dt.ToShortDateString();
                                }
                            }
                        }
                    }
                    c.Close();
                }
            }
            if (name == "Очистить")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    SQLQuery sq = (SQLQuery)State;
                    sq.richTextBox1.Text            = "SELECT";
                    sq.richTextBox1.SelectionStart  = 6;
                    sq.richTextBox1.SelectionLength = 0;
                }
            }
            if (name == "Справка")
            {
                if (State.GetType() == typeof(SQLQuery))
                {
                    Help h = new Help();
                    h.Show();
                }
            }
            if (name == "Просмотр")
            {
                if (State.GetType() == typeof(Hotels))
                {
                    Hotels h = (Hotels)State;
                    Controls.Remove(State);
                    OneHotel ag = new OneHotel(this, new Hotel(Convert.ToInt32(h.dataGridView1.SelectedRows[0].Cells[5].Value)));
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
                if (State.GetType() == typeof(Agencies))
                {
                    Agencies h = (Agencies)State;
                    Controls.Remove(State);
                    OneAgency ag = new OneAgency(this, new Touragency(h.dataGridView1.SelectedRows[0].Cells[2].Value.ToString()));
                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
                if (State.GetType() == typeof(Vouchers))
                {
                    Vouchers   h  = (Vouchers)State;
                    OneVoucher ag = new OneVoucher(this);
                    Controls.Remove(State);

                    State = ag;
                    this.Controls.Add(ag);
                    ag.Location = new Point(panel3.Location.X + panel3.Size.Width, panel3.Location.Y + panel3.Size.Height + PanelForm.Size.Height);
                    ag.Visible  = true;
                    ag.Show();
                }
            }
            if (name == "Обновить")
            {
                if (State.GetType() == typeof(Routes))
                {
                    UpdateRoutes u = new UpdateRoutes();
                    u.Show();
                }
                if (State.GetType() == typeof(Agencies))
                {
                    UpdateRoutes u = new UpdateRoutes(this, 1);
                    u.Show();
                }
            }
            if (name == "Отчет")
            {
                if (State.GetType() == typeof(OneAgency))
                {
                    OneAgency a        = (OneAgency)State;
                    var       document = new iTextSharp.text.Document();
                    using (var writer = PdfWriter.GetInstance(document, new FileStream("ReportTourAgency.pdf", FileMode.Create)))
                    {
                        document.Open();

                        BaseFont             baseFont = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                        iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, 20, 0);


                        document.Add(new Paragraph($"{a.label1.Text}", new iTextSharp.text.Font(baseFont, 30, 0)));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 10, 0)));
                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

                        cb.MoveTo(30, 745);
                        cb.LineTo(560, 745);
                        cb.Stroke();

                        document.Add(new Paragraph($"{a.label2.Text}", font));
                        document.Add(new Paragraph($"{a.label4.Text}", font));
                        document.Add(new Paragraph($"{a.label3.Text}", font));
                        document.Add(new Paragraph($"{a.label6.Text}", font));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 3, 0)));
                        DataGridView d    = a.dataGridView1;
                        int          sum  = 0;
                        int          suma = 0;
                        int          sumb = 0;
                        for (int i = 0; i < d.Rows.Count; i++)
                        {
                            if (d.Rows[i].Cells[4].Value.ToString() == "Выполнено" || d.Rows[i].Cells[4].Value.ToString() == "В процессе" || d.Rows[i].Cells[4].Value.ToString() == "Оплачено")
                            {
                                if (DateTime.Now <= Convert.ToDateTime(d.Rows[i].Cells[2].Value.ToString()).AddYears(1))
                                {
                                    if (DateTime.Now <= Convert.ToDateTime(d.Rows[i].Cells[2].Value.ToString()).AddMonths(1))
                                    {
                                        sumb += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                                    }
                                    suma += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                                }
                                sum += Convert.ToInt32(d.Rows[i].Cells[3].Value);
                            }
                        }
                        document.Add(new Paragraph($"Прибыль от турагентства за все время: {sum}$", font));
                        document.Add(new Paragraph($"Прибыль от турагентства за месяц: {sumb}$", font));
                        document.Add(new Paragraph($"Прибыль от турагентства за год: {suma}$", font));

                        bool t = false;
                        for (int i = 0; i < d.Rows.Count; i++)
                        {
                            if (d.Rows[i].Cells[4].Value.ToString() == "Забронировано")
                            {
                                if (!t)
                                {
                                    document.Add(new Paragraph($"К оплате:", font));
                                    t = true;
                                }
                                document.Add(new Paragraph($"    Путевка №{d.Rows[i].Cells[0].Value.ToString()} - {d.Rows[i].Cells[3].Value.ToString()}$ ", font));
                            }
                        }
                        document.Add(new Paragraph($" ", font));
                        document.Add(new Paragraph($" ", font));

                        document.Add(new Paragraph("Дата создания отчета: " + DateTime.Now.ToString(), new iTextSharp.text.Font(baseFont, 10, 0)));
                        document.Close();
                        writer.Close();
                        ReportPDF r = new ReportPDF(true);
                    }
                }
                if (State.GetType() == typeof(OneVoucher))
                {
                    OneVoucher a        = (OneVoucher)State;
                    var        document = new Document();
                    using (var writer = PdfWriter.GetInstance(document, new FileStream("ReportVoucher.pdf", FileMode.Create)))
                    {
                        document.Open();

                        BaseFont             baseFont = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                        iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, 20, 0);


                        document.Add(new Paragraph($"{a.label1.Text}", new iTextSharp.text.Font(baseFont, 30, 0)));
                        document.Add(new Paragraph($"         ", new iTextSharp.text.Font(baseFont, 10, 0)));
                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

                        cb.MoveTo(30, 745);
                        cb.LineTo(560, 745);
                        cb.Stroke();

                        document.Add(new Paragraph($"{a.label4.Text}", font));
                        document.Add(new Paragraph($"{a.label6.Text}", font));
                        document.Add(new Paragraph($"{a.label3.Text}", font));
                        document.Add(new Paragraph($"{a.label8.Text}", font));
                        document.Add(new Paragraph($"{a.label7.Text}", font));
                        document.Add(new Paragraph($"{a.label2.Text}", font));
                        document.Add(new Paragraph($"Перелеты: ", font));
                        document.Add(new Paragraph($"            ", font));
                        PdfPTable table = new PdfPTable(4);
                        for (int g = 0; g < 4; g++)
                        {
                            table.AddCell(new Paragraph($"{a.dataGridView2.Columns[g].HeaderText}", new iTextSharp.text.Font(baseFont, 10, 0)));
                        }
                        for (int g = 0; g < a.dataGridView2.Rows.Count; g++)
                        {
                            for (int s = 0; s < a.dataGridView2.Rows[g].Cells.Count - 1; s++)
                            {
                                table.AddCell(new Paragraph($"{a.dataGridView2.Rows[g].Cells[s].Value.ToString()}", new iTextSharp.text.Font(baseFont, 10, 0)));
                            }
                        }
                        document.Add(table);
                        document.Add(new Paragraph($"Люди: ", font));
                        document.Add(new Paragraph($"            ", font));
                        PdfPTable table1 = new PdfPTable(6);
                        for (int g = 0; g < 6; g++)
                        {
                            table1.AddCell(new Paragraph($"{a.dataGridView1.Columns[g].HeaderText}", new iTextSharp.text.Font(baseFont, 10, 0)));
                        }
                        for (int g = 0; g < a.dataGridView1.Rows.Count; g++)
                        {
                            for (int s = 0; s < a.dataGridView1.Rows[g].Cells.Count; s++)
                            {
                                table1.AddCell(new Paragraph($"{a.dataGridView1.Rows[g].Cells[s].Value.ToString()}", new iTextSharp.text.Font(baseFont, 10, 0)));
                            }
                        }
                        document.Add(table1);
                        document.Add(new Paragraph($" ", font));
                        document.Add(new Paragraph($" ", font));

                        document.Add(new Paragraph("Дата создания отчета: " + DateTime.Now.ToString(), new iTextSharp.text.Font(baseFont, 10, 0)));

                        document.Close();
                        writer.Close();
                        ReportPDF r = new ReportPDF(false);
                    }
                }
            }
        }
Example #13
0
// ---------------------------------------------------------------------------    
    /**
     * Draws a row of squares.
     * @param canvas the canvas to which the squares have to be drawn
     * @param x      X coordinate to position the row
     * @param y      Y coordinate to position the row
     * @param side   the side of the square
     * @param gutter the space between the squares
     */
    public void CreateSquares(PdfContentByte canvas,
      float x, float y, float side, float gutter) {
      canvas.SaveState();
      canvas.SetColorStroke(new GrayColor(0.2f));
      canvas.SetColorFill(new GrayColor(0.9f));
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Stroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.Fill();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.FillStroke();
      x = x + side + gutter;
      canvas.MoveTo(x, y);
      canvas.LineTo(x + side, y);
      canvas.LineTo(x + side, y + side);
      canvas.LineTo(x, y + side);
      canvas.ClosePathFillStroke();
      canvas.RestoreState();
    }
        private MemoryStream PrintTerms(IEnumerable<GlossaryItem> terms)
        {
            float ppi = 72.0F;
            float PageWidth = 8.5F;
            float PageHeight = 11.0F;
            float TopBottomMargin = 0.625F;
            float LeftRightMargin = 0.75F;
            float GutterWidth = 0.25F;
            float HeaderFooterHeight = 0.125F;
            float Column1Left = LeftRightMargin;
            float Column1Right = ((PageWidth - (LeftRightMargin * 2) - GutterWidth) / 2) + LeftRightMargin;
            float Column2Left = Column1Right + GutterWidth;
            float Column2Right = PageWidth - LeftRightMargin;

            bool HasMultipleDefinitions = (terms.Count() > 1);

            string version = DataAccess.GetKeyValue("glossaryversion").Value;

            Document doc = new Document(new Rectangle(0, 0, PageWidth * ppi, PageHeight * ppi));

            MemoryStream m = new MemoryStream();

            PdfWriter writer = PdfWriter.GetInstance(doc, m);
            writer.CloseStream = false;

            try {
                doc.AddTitle("The Glossary of Systematic Christian Theology");
                doc.AddSubject("A collection of technical terms and associated definitions as taught from the pulpit by Dr. Ron Killingsworth in classes at Rephidim Church.");
                doc.AddCreator("My program using iText#");
                doc.AddAuthor("Dr. Ron Killingsworth");
                doc.AddCreationDate();

                writer.SetEncryption(PdfWriter.STRENGTH128BITS, null, "xaris", PdfWriter.AllowCopy | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders | PdfWriter.AllowDegradedPrinting);

                doc.Open();

                BaseFont bfArialBlack = BaseFont.CreateFont("C:\\windows\\fonts\\ariblk.ttf", BaseFont.WINANSI, false);
                BaseFont bfGaramond = BaseFont.CreateFont("C:\\windows\\fonts\\gara.ttf", BaseFont.WINANSI, false);
                Font fntTerm = new Font(bfArialBlack, 10, Font.BOLD, new BaseColor(57, 81, 145));
                Font fntDefinition = new Font(bfGaramond, 9, Font.NORMAL, new BaseColor(0, 0, 0));

                ///////////////////////////////////////////

                if (HasMultipleDefinitions) {
                    PdfContentByte cbCover = new PdfContentByte(writer);
                    cbCover = writer.DirectContent;

                    cbCover.BeginText();

                    cbCover.SetFontAndSize(bfGaramond, 42);
                    cbCover.SetRGBColorFill(57, 81, 145);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Glossary of", (PageWidth / 2) * ppi, ((PageHeight / 2) + Convert.ToSingle(1.5)) * ppi, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Systematic Christian Theology", (PageWidth / 2) * ppi, ((PageHeight / 2) + 1) * ppi, 0);

                    cbCover.SetFontAndSize(bfGaramond, 16);
                    cbCover.SetRGBColorFill(0, 0, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "A collection of technical terms and associated definitions", (PageWidth / 2) * ppi, ((PageHeight / 2) + Convert.ToSingle(0.6)) * ppi, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "as taught by Dr. Ron Killingsworth, Rephidim Church, Wichita Falls, Texas", (PageWidth / 2) * ppi, ((PageHeight / 2) + Convert.ToSingle(0.4)) * ppi, 0);

                    cbCover.SetFontAndSize(bfGaramond, 12);
                    cbCover.SetRGBColorFill(0, 0, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Published by:", (PageWidth / 2) * ppi, ((PageHeight / 2) - Convert.ToSingle(0.6)) * ppi, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Rephidim Doctrinal Bible Studies, Inc.", (PageWidth / 2) * ppi, ((PageHeight / 2) - Convert.ToSingle(0.8)) * ppi, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "4430 Allendale Rd., Wichita Falls, Texas 76310", (PageWidth / 2) * ppi, ((PageHeight / 2) - Convert.ToSingle(1.0)) * ppi, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "(940) 691-1166     rephidim.org     [email protected]", (PageWidth / 2) * ppi, ((PageHeight / 2) - Convert.ToSingle(1.2)) * ppi, 0);

                    cbCover.SetFontAndSize(bfGaramond, 10);
                    cbCover.SetRGBColorFill(0, 0, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Version: " + version + " / " + terms.Count() + " terms", (LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                    cbCover.SetFontAndSize(bfGaramond, 10);
                    cbCover.SetRGBColorFill(0, 0, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "© 1971-" + DateTime.Today.Year.ToString() + " Dr. Ron Killingsworth, Rephidim Doctrinal Bible Studies, Inc.", (PageWidth - LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                    cbCover.EndText();

                    doc.NewPage();

                    ///////////////////////////////////////////

                    PdfContentByte cbBlank = new PdfContentByte(writer);
                    cbBlank = writer.DirectContent;

                    cbBlank.BeginText();

                    cbCover.SetFontAndSize(bfGaramond, 10);
                    cbCover.SetRGBColorFill(0, 0, 0);
                    cbCover.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " ", (LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                    cbBlank.EndText();

                    doc.NewPage();

                    ///////////////////////////////////////////

                }

                PdfContentByte cb = writer.DirectContent;
                ColumnText ct = new ColumnText(cb);

                int[] left = {
                    Convert.ToInt32(Column1Left * ppi),
                    Convert.ToInt32(Column2Left * ppi)
                };
                int[] right = {
                    Convert.ToInt32(Column1Right * ppi),
                    Convert.ToInt32(Column2Right * ppi)
                };

                foreach (var term in terms) {
                    ct.AddText(new Phrase(term.Term.Trim() + Environment.NewLine, fntTerm));
                    ct.AddText(new Phrase(Regex.Replace(term.Definition.Trim().Replace("<br/>", "\r"), @"<[^>]+>", "") + Environment.NewLine + Environment.NewLine, fntDefinition));
                }

                int status = 0;
                int column = 0;
                int PageNumber = 0;
                if (HasMultipleDefinitions) {
                    PageNumber = 3;
                } else {
                    PageNumber = 1;
                }
                while ((status & ColumnText.NO_MORE_TEXT) == 0) {
                    ///////////////////////////////////////////

                    PdfContentByte cbPage = new PdfContentByte(writer);
                    cbPage = writer.DirectContent;

                    cbPage.SetLineWidth(0.5f);
                    cbPage.SetRGBColorStroke(50, 50, 50);
                    cbPage.MoveTo(LeftRightMargin * ppi, (PageHeight - TopBottomMargin - (HeaderFooterHeight / 2)) * ppi);
                    cbPage.LineTo((PageWidth - LeftRightMargin) * ppi, (PageHeight - TopBottomMargin - (HeaderFooterHeight / 2)) * ppi);
                    cbPage.Stroke();

                    cbPage.SetLineWidth(0.5f);
                    cbPage.SetRGBColorStroke(50, 50, 50);
                    cbPage.MoveTo(LeftRightMargin * ppi, (TopBottomMargin + HeaderFooterHeight) * ppi);
                    cbPage.LineTo((PageWidth - LeftRightMargin) * ppi, (TopBottomMargin + HeaderFooterHeight) * ppi);
                    cbPage.Stroke();

                    cbPage.BeginText();

                    cbPage.SetFontAndSize(bfGaramond, 10);
                    cbPage.SetRGBColorFill(0, 0, 0);
                    cbPage.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "The Glossary of Systematic Christian Theology", (PageWidth / 2) * ppi, (PageHeight - TopBottomMargin) * ppi, 0);

                    if (PageNumber % 2 == 0) {
                        cbPage.SetFontAndSize(bfGaramond, 8);
                        cbPage.SetRGBColorFill(0, 0, 0);
                        cbPage.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "© 1971-" + DateTime.Today.Year.ToString() + " Dr. Ron Killingsworth, Rephidim Doctrinal Bible Studies, Inc.", (PageWidth - LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                        cbPage.SetFontAndSize(bfGaramond, 8);
                        cbPage.SetRGBColorFill(0, 0, 0);
                        cbPage.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Page " + PageNumber.ToString(), (LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);
                    } else {
                        cbPage.SetFontAndSize(bfGaramond, 8);
                        cbPage.SetRGBColorFill(0, 0, 0);
                        cbPage.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "© 1971-" + DateTime.Today.Year.ToString() + " Dr. Ron Killingsworth, Rephidim Doctrinal Bible Studies, Inc.", (LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                        cbPage.SetFontAndSize(bfGaramond, 8);
                        cbPage.SetRGBColorFill(0, 0, 0);
                        cbPage.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Page " + PageNumber.ToString(), (PageWidth - LeftRightMargin) * ppi, (TopBottomMargin) * ppi, 0);

                    }

                    cbPage.EndText();

                    ///////////////////////////////////////////

                    //If HasMultipleDefinitions Then
                    //    ct.setSimpleColumn(left(column), (TopBottomMargin + (HeaderFooterHeight * 3 / 2)) * ppi, right(column), (PageHeight - TopBottomMargin - HeaderFooterHeight) * ppi, 10, Element.ALIGN_LEFT)
                    //Else
                    //    ct.setSimpleColumn(LeftRightMargin * ppi, (TopBottomMargin + (HeaderFooterHeight * 3 / 2)) * ppi, (PageWidth - LeftRightMargin) * ppi, (PageHeight - TopBottomMargin - HeaderFooterHeight) * ppi, 10, Element.ALIGN_LEFT)
                    //End If
                    //status = ct.go()
                    //If (status And ColumnText.NO_MORE_COLUMN) <> 0 Then
                    //    column += 1
                    //    If column > 1 Then

                    //        doc.newPage()
                    //        PageNumber += 1
                    //        column = 0
                    //    End If
                    //End If

                    if (HasMultipleDefinitions) {
                        ct.SetSimpleColumn(left[column], (TopBottomMargin + (HeaderFooterHeight * 3 / 2)) * ppi, right[column], (PageHeight - TopBottomMargin - HeaderFooterHeight) * ppi, 10, Element.ALIGN_LEFT);

                        status = ct.Go();
                        if ((status & ColumnText.NO_MORE_COLUMN) != 0) {
                            column += 1;

                            if (column > 1) {
                                doc.NewPage();
                                PageNumber += 1;
                                column = 0;
                            }
                        }
                    } else {
                        ct.SetSimpleColumn(LeftRightMargin * ppi, (TopBottomMargin + (HeaderFooterHeight * 3 / 2)) * ppi, (PageWidth - LeftRightMargin) * ppi, (PageHeight - TopBottomMargin - HeaderFooterHeight) * ppi, 10, Element.ALIGN_LEFT);

                        status = ct.Go();
                        if ((status) != 0) {
                            doc.NewPage();
                            PageNumber += 1;
                        }
                    }

                }

                doc.Close();
                m.Flush();
                m.Position = 0;
                return m;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #15
0
 public bool Open(PdfContentByte cb, float fontSize, float xtlm, float ytlm)
 {
     if (!_isPrevEmDash)
     {
         var padding = fontSize * _emDashPaddingRatio;
         cb.EndText();
         cb.SetLineWidth(_lineWidth);
         cb.MoveTo(xtlm, ytlm - padding);
         _isPrevEmDash = true;
         return true;
     }
     else
     {
         return false;
     }
 }
Example #16
0
        public void DrawLine(PdfContentByte cb, float x1, float y1, float x2, float y2, int step) {
    	    cb.MoveTo(x1, y1);
    	    cb.LineTo(x2, y2);
    	    cb.Stroke();
        	
    	    for (int i = 0; i < 10; i++) {
        	    double[] point = GetPointOnLine(x1, y1, x2, y2, i*step);
        	    cb.Rectangle((float)point[0], (float)point[1], 2, 2);
        	    cb.Stroke();
		    }
        }
Example #17
0
        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal void WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
        {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;

            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.ToString().Length;
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            if (isJustified) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }

            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;

            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                Color color = chunk.Color;
                hScale = 1;

                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else
                        width = chunk.Width;
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((Color)bgr[0]);
                            float[] extra = (float[])bgr[1];
                            graphics.Rectangle(xMarker - extra[0],
                                yMarker + descender - extra[1] + chunk.TextRise,
                                width - subtract + extra[0] + extra[2],
                                ascender - descender + extra[1] + extra[3]);
                            graphics.Fill();
                            graphics.SetGrayFill(0);
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            Color scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (Color)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                float fsize = chunk.Font.Size;
                                graphics.SetLineWidth(ps[0] + fsize * ps[1]);
                                float shift = ps[2] + fsize * ps[3];
                                int cap2 = (int)ps[4];
                                if (cap2 != 0)
                                    graphics.SetLineCap(cap2);
                                graphics.MoveTo(xMarker, yMarker + shift);
                                graphics.LineTo(xMarker + width - subtract, yMarker + shift);
                                graphics.Stroke();
                                if (scolor != null)
                                    graphics.ResetGrayStroke();
                                if (cap2 != 0)
                                    graphics.SetLineCap(0);
                            }
                            graphics.SetLineWidth(1);
                        }
                        if (chunk.IsAttribute(Chunk.ACTION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            text.AddAnnotation(new PdfAnnotation(writer, xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size, (PdfAction)chunk.GetAttribute(Chunk.ACTION)));
                        }
                        if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
                            String filename = (String)obj[0];
                            if (obj[1] is String)
                                RemoteGoto(filename, (String)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + chunk.Font.Size, 0));
                        }
                        if (chunk.IsAttribute(Chunk.GENERICTAG)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                            IPdfPageEvent pev = writer.PageEvent;
                            if (pev != null)
                                pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
                        }
                        if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
                            annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
                            text.AddAnnotation(annot);
                        }
                        float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
                        object hs = chunk.GetAttribute(Chunk.HSCALE);
                        if (paramsx != null || hs != null) {
                            float b = 0, c = 0;
                            if (paramsx != null) {
                                b = paramsx[0];
                                c = paramsx[1];
                            }
                            if (hs != null)
                                hScale = (float)hs;
                            text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
                        }
                        if (chunk.IsImage()) {
                            Image image = chunk.Image;
                            float[] matrix = image.Matrix;
                            matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
                            matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
                            graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
                            text.MoveText(xMarker + lastBaseFactor + image.ScaledWidth - text.XTLM, 0);
                        }
                    }
                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (chunk.Font.CompareTo(currentFont) != 0) {
                    currentFont = chunk.Font;
                    text.SetFontAndSize(currentFont.Font, currentFont.Size);
                }
                float rise = 0;
                Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
                int tr = 0;
                float strokeWidth = 1;
                Color strokeColor = null;
                object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
                if (textRender != null) {
                    tr = (int)textRender[0] & 3;
                    if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                        text.SetTextRenderingMode(tr);
                    if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
                        strokeWidth = (float)textRender[1];
                        if (strokeWidth != 1)
                            text.SetLineWidth(strokeWidth);
                        strokeColor = (Color)textRender[2];
                        if (strokeColor == null)
                            strokeColor = color;
                        if (strokeColor != null)
                            text.SetColorStroke(strokeColor);
                    }
                }
                if (fr != null)
                    rise = (float)fr;
                if (color != null)
                    text.SetColorFill(color);
                if (rise != 0)
                    text.SetTextRise(rise);
                if (chunk.IsImage()) {
                    adjustMatrix = true;
                }
                // If it is a CJK chunk or Unicode TTF we will have to simulate the
                // space adjustment.
                else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
                    if (hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(chunk.ToString());
                    else {
                        float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
                        PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
                        int lastIdx = idx;
                        while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
                            textArray.Add(spaceCorrection);
                            textArray.Add(s.Substring(lastIdx, idx - lastIdx));
                            lastIdx = idx;
                        }
                        textArray.Add(spaceCorrection);
                        textArray.Add(s.Substring(lastIdx));
                        text.ShowText(textArray);
                    }
                }
                else {
                    if (isJustified && hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale);
                    }
                    text.ShowText(chunk.ToString());
                }

                if (rise != 0)
                    text.SetTextRise(0);
                if (color != null)
                    text.ResetRGBColorFill();
                if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                    text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                if (strokeColor != null)
                    text.ResetRGBColorStroke();
                if (strokeWidth != 1)
                    text.SetLineWidth(1);
                if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
                    adjustMatrix = true;
                    text.SetTextMatrix(xMarker, yMarker);
                }
            }
            if (isJustified) {
                text.SetWordSpacing(0);
                text.SetCharacterSpacing(0);
                if (line.NewlineSplit)
                    lastBaseFactor = 0;
            }
            if (adjustMatrix)
                text.MoveText(baseXMarker - text.XTLM, 0);
            currentValues[0] = currentFont;
            currentValues[1] = lastBaseFactor;
        }
        private void AddColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation) {
            Rectangle cleanUpRegion = cleanUpLocation.Region;

            canvas.SaveState();
            canvas.SetColorFill(cleanUpLocation.CleanUpColor);
            canvas.MoveTo(cleanUpRegion.Left, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Bottom);
            canvas.LineTo(cleanUpRegion.Right, cleanUpRegion.Top);
            canvas.LineTo(cleanUpRegion.Left, cleanUpRegion.Top);
            canvas.ClosePath();
            canvas.Fill();
            canvas.RestoreState();
        }
        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal float WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)  {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;
            float glueWidth = 0;
            float lastX = text.XTLM + line.OriginalWidth;
            
            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.GetLineLengthUtf32();
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            int separatorCount = line.GetSeparatorCount();
            if (separatorCount > 0) {
                glueWidth = line.WidthLeft / separatorCount;
            }
            else if (isJustified && separatorCount == 0) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }
            else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) {
                lastX -= line.WidthLeft;
            }
            
            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;
            float tabPosition = 0;
            
            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.OpenMCBlock(chunk.accessibleElement);
                }
                BaseColor color = chunk.Color;
                float fontSize = chunk.Font.Size;
                float ascender;
                float descender;
                if (chunk.IsImage())
                {
                    ascender = chunk.Height();
                    descender = 0;
                }
                else
                {
                    ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                    descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                }
                hScale = 1;
                
                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else {
                        width = chunk.Width();
                    }
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsSeparator()) {
                            width = glueWidth;
                            Object[] sep = (Object[])chunk.GetAttribute(Chunk.SEPARATOR);
                            IDrawInterface di = (IDrawInterface)sep[0];
                            bool vertical = (bool)sep[1];
                            if (vertical) {
                                di.Draw(graphics, baseXMarker, yMarker + descender, baseXMarker + line.OriginalWidth, ascender - descender, yMarker);      
                            }
                            else {
                                di.Draw(graphics, xMarker, yMarker + descender, xMarker + width, ascender - descender, yMarker);
                            }
                        }
                        if (chunk.IsTab()) {
                            if (chunk.IsAttribute(Chunk.TABSETTINGS))
                            {
                                TabStop tabStop = chunk.TabStop;
                                if (tabStop != null) {
                                    tabPosition = tabStop.Position + baseXMarker;
                                    if (tabStop.Leader != null)
                                        tabStop.Leader.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                                }
                                else {
                                    tabPosition = xMarker;
                                }
                            } else {
                                //Keep deprecated tab logic for backward compatibility...
                                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                                IDrawInterface di = (IDrawInterface)tab[0];
                                tabPosition = (float)tab[1] + (float)tab[3];
                                if (tabPosition > xMarker)
                                    di.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                            }
                            float tmp = xMarker;
                            xMarker = tabPosition;
                            tabPosition = tmp;
                        }
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((BaseColor)bgr[0]);
                            float[] extra = (float[])bgr[1];
                            graphics.Rectangle(xMarker - extra[0],
                                yMarker + descender - extra[1] + chunk.TextRise,
                                width - subtract + extra[0] + extra[2],
                                ascender - descender + extra[1] + extra[3]);
                            graphics.Fill();
                            graphics.SetGrayFill(0);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE) && !chunk.IsNewlineSplit()) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            BaseColor scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (BaseColor)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                graphics.SetLineWidth(ps[0] + fontSize * ps[1]);
                                float shift = ps[2] + fontSize * ps[3];
                                int cap2 = (int)ps[4];
                                if (cap2 != 0)
                                    graphics.SetLineCap(cap2);
                                graphics.MoveTo(xMarker, yMarker + shift);
                                graphics.LineTo(xMarker + width - subtract, yMarker + shift);
                                graphics.Stroke();
                                if (scolor != null)
                                    graphics.ResetGrayStroke();
                                if (cap2 != 0)
                                    graphics.SetLineCap(0);
                            }
                            graphics.SetLineWidth(1);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.ACTION))
                        {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = null;
                            if (chunk.IsImage()) {
                                annot = new PdfAnnotation(writer, xMarker, yMarker + chunk.ImageOffsetY, xMarker + width - subtract, yMarker + chunk.ImageHeight + chunk.ImageOffsetY, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            else {
                        	    annot = new PdfAnnotation(writer, xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            text.AddAnnotation(annot, true);
                            if (IsTagged(writer) && chunk.accessibleElement != null) {
                                int structParent = GetStructParentIndex(annot);
                                annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
                                PdfStructureElement strucElem;
                                structElements.TryGetValue(chunk.accessibleElement.ID, out strucElem);
                                if (strucElem != null) {
                                    PdfArray kArray = strucElem.GetAsArray(PdfName.K);
                                    if (kArray == null) {
                                        kArray = new PdfArray();
                                        PdfObject k = strucElem.Get(PdfName.K);
                                        if (k != null) {
                                            kArray.Add(k);
                                        }
                                        strucElem.Put(PdfName.K, kArray);
                                    }
                                    PdfDictionary dict = new PdfDictionary();
                                    dict.Put(PdfName.TYPE, PdfName.OBJR);
                                    dict.Put(PdfName.OBJ, annot.IndirectReference);
                                    kArray.Add(dict);
                                    writer.StructureTreeRoot.SetAnnotationMark(structParent, strucElem.Reference);
                                }
                            }
                        }
                        if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
                            String filename = (String)obj[0];
                            if (obj[1] is String)
                                RemoteGoto(filename, (String)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) {
                            /*float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;*/
                            LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + fontSize, 0));
                        }
                        if (chunk.IsAttribute(Chunk.GENERICTAG)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                            IPdfPageEvent pev = writer.PageEvent;
                            if (pev != null)
                                pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
                        }
                        if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
                            annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
                            text.AddAnnotation(annot, true);
                        }
                        float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
                        object hs = chunk.GetAttribute(Chunk.HSCALE);
                        if (paramsx != null || hs != null) {
                            float b = 0, c = 0;
                            if (paramsx != null) {
                                b = paramsx[0];
                                c = paramsx[1];
                            }
                            if (hs != null)
                                hScale = (float)hs;
                            text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
                        }
                        if (!isJustified)
                        {
                            if (chunk.IsAttribute(Chunk.WORD_SPACING))
                            {
                                float ws = (float)chunk.GetAttribute(Chunk.WORD_SPACING);
                                text.SetWordSpacing(ws);
                            }
                        }

                        if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
                    	    float cs = (float) chunk.GetAttribute(Chunk.CHAR_SPACING);
						    text.SetCharacterSpacing(cs);
					    }
                        if (chunk.IsImage()) {
                            Image image = chunk.Image;
                            width = chunk.ImageWidth;
                            float[] matrix = image.GetMatrix(chunk.ImageScalePercentage);
                            matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
                            matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
                            graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
                            text.MoveText(xMarker + lastBaseFactor + chunk.ImageWidth - text.XTLM, 0);
                        }
                    }

                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (!chunk.IsImage() && chunk.Font.CompareTo(currentFont) != 0) {
                    currentFont = chunk.Font;
                    text.SetFontAndSize(currentFont.Font, currentFont.Size);
                }
                float rise = 0;
                Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
                int tr = 0;
                float strokeWidth = 1;
                BaseColor strokeColor = null;
                object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
                if (textRender != null) {
                    tr = (int)textRender[0] & 3;
                    if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                        text.SetTextRenderingMode(tr);
                    if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
                        strokeWidth = (float)textRender[1];
                        if (strokeWidth != 1)
                            text.SetLineWidth(strokeWidth);
                        strokeColor = (BaseColor)textRender[2];
                        if (strokeColor == null)
                            strokeColor = color;
                        if (strokeColor != null)
                            text.SetColorStroke(strokeColor);
                    }
                }
                if (fr != null)
                    rise = (float)fr;
                if (color != null)
                    text.SetColorFill(color);
                if (rise != 0)
                    text.SetTextRise(rise);
                if (chunk.IsImage()) {
                    adjustMatrix = true;
                }
                else if (chunk.IsHorizontalSeparator()) {
                    PdfTextArray array = new PdfTextArray();
                    array.Add(-glueWidth * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                else if (chunk.IsTab() && tabPosition != xMarker)
                {
                    PdfTextArray array = new PdfTextArray();
                    array.Add((tabPosition - xMarker) * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                
                // If it is a CJK chunk or Unicode TTF we will have to simulate the
                // space adjustment.
                else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
                    if (hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(s);
                    else {
                        float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
                        PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
                        int lastIdx = idx;
                        while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
                            textArray.Add(spaceCorrection);
                            textArray.Add(s.Substring(lastIdx, idx - lastIdx));
                            lastIdx = idx;
                        }
                        textArray.Add(spaceCorrection);
                        textArray.Add(s.Substring(lastIdx));
                        text.ShowText(textArray);
                    }
                }
                else {
                    if (isJustified && hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    text.ShowText(chunk.ToString());
                }
                
                if (rise != 0)
                    text.SetTextRise(0);
                if (color != null)
                    text.ResetRGBColorFill();
                if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                    text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                if (strokeColor != null)
                    text.ResetRGBColorStroke();
                if (strokeWidth != 1)
                    text.SetLineWidth(1);            
                if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
                    adjustMatrix = true;
                    text.SetTextMatrix(xMarker, yMarker);
                }
                if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
				    text.SetCharacterSpacing(baseCharacterSpacing);
                }
                if (chunk.IsAttribute(Chunk.WORD_SPACING)) {
                    text.SetWordSpacing(baseWordSpacing);
                }
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.CloseMCBlock(chunk.accessibleElement);
                }
            }
            if (isJustified) {
                text.SetWordSpacing(0);
                text.SetCharacterSpacing(0);
                if (line.NewlineSplit)
                    lastBaseFactor = 0;
            }
            if (adjustMatrix)
                text.MoveText(baseXMarker - text.XTLM, 0);
            currentValues[0] = currentFont;
            currentValues[1] = lastBaseFactor;
            return lastX;
        }
Example #20
0
        protected override void Draw(PdfContentByte cb)
        {
            //TODO check the line width with this rectangles SVG takes 5 pixel out and 5 pixels in when asking line-width=10
            //TODO check the values for rx and ry what if they get to big

            if (rx == 0 || ry == 0)
            {
                cb.Rectangle(x, y, width, height);
            }
            else
            { //corners
                /*
			
                if(rx > x / 2){
                    rx = x/2;
                }
                if(ry > y / 2){
                    ry = y/2;
                }*/

                cb.MoveTo(x + rx, y);
                cb.LineTo(x + width - rx, y);
                Arc(x + width - 2 * rx, y, x + width, y + 2 * ry, -90, 90, cb);
                cb.LineTo(x + width, y + height - ry);
                Arc(x + width, y + height - 2 * ry, x + width - 2 * rx, y + height, 0, 90, cb);
                cb.LineTo(x + rx, y + height);
                Arc(x + 2 * rx, y + height, x, y + height - 2 * ry, 90, 90, cb);
                cb.LineTo(x, y + ry);
                Arc(x, y + 2 * ry, x + 2 * rx, y, 180, 90, cb);
                cb.ClosePath();
            }

        }
Example #21
0
        private void LineTimeAndLead(PdfContentByte cb)
        {
            YPos -= 1;

            //Top Border Line
            cb.MoveTo(XBeginningPos, YPos);
            cb.LineTo(XEndPos, YPos);
            cb.Stroke();

            //Time: & Lead: Text
            TimeLeadText(cb);

            //Bottom Border Line
            YPos -= 46;
            cb.MoveTo(XBeginningPos, YPos);
            cb.LineTo(XEndPos, YPos);
            cb.Stroke();

            YPos -= 106;
        }
Example #22
0
        private void DocumentHeader(PdfContentByte cb)
        {
            YPos = 678;

            //Vertical Line
            cb.MoveTo(296, YPos);
            cb.LineTo(296, YEndPost);
            cb.Stroke();

            //Horizontal Line
            cb.MoveTo(XBeginningPos, YPos);
            cb.LineTo(XEndPos, YPos);
            cb.Stroke();
            var text = "Date:" + DateTime.Now.Date.ToString("MM/dd/yyyy");
            var textAlignedPdf = new TextAlignedPdfConfig
                                            {
                                                Alignment = 0,
                                                Text = text,
                                                X = 50,
                                                Y = YPos += 18,
                                                Rotation = 0
                                            };

            PdfText(cb, textAlignedPdf);

            YPos -= 123;
        }
Example #23
0
        /// <summary>
        /// Draws the diamont.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public static void DrawDiamont(PdfContentByte content, float x, float y)
        {
            content.SaveState();
            var state = new PdfGState();
            content.SetGState(state);
            content.SetColorFill(BaseColor.BLACK);
            content.MoveTo(x, y);
            var sPoint = new Point(x, y);
            var uMPoint = new Point(x + WPosMarkerMid, y + HPosMarkerMid);
            var rPoint = new Point(uMPoint.X + WPosMarkerMid, uMPoint.Y - HPosMarkerMid);
            var mPoint = new Point(rPoint.X - WPosMarkerMid, rPoint.Y - HPosMarkerMid);

            DrawLines(content, uMPoint, rPoint, mPoint, sPoint);

            content.ClosePathFillStroke();
            content.RestoreState();
        }
Example #24
-8
        void DrawElement(PdfContentByte cb)
        {
            try
            {
                IList<PathItem> translatedItems = Translate(path.PathItems);

                //loop over the items in the path
                foreach (PathItem item in translatedItems)
                {
                    IList<float> numbers = item.Coordinates;

                    if (item.IsMoveTo())
                    {
                        cb.MoveTo(numbers[0], numbers[1]);
                    }
                    else if (item.IsLineTo())
                    {
                        cb.LineTo(numbers[0], numbers[1]);
                    }
                    else if (item.IsCubicBezier())
                    {
                        cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
                    }
                    else if (item.IsQuadraticBezier())
                    {
                        cb.CurveTo(numbers[0], numbers[1], numbers[2], numbers[3]);
                    }
                    else if (item.IsArcTo())
                    {
                        DrawArc(cb, numbers);
                    }
                    else if (item.IsClosePath())
                    {
                        cb.ClosePath();
                    }
                    else
                    {
                        //System.out.Println(item);
                    }
                }
            } catch {
                //TODO
            }
        }
Example #25
-8
// ---------------------------------------------------------------------------    
    /**
     * Draws a series of Bezier curves
     * @param cb the canvas to which the curves have to be drawn
     * @param x0 X coordinate of the start point
     * @param y0 Y coordinate of the start point
     * @param x1 X coordinate of the first control point
     * @param y1 Y coordinate of the first control point
     * @param x2 X coordinate of the second control point
     * @param y2 Y coordinate of the second control point
     * @param x3 X coordinate of the end point
     * @param y3 Y coordinate of the end point
     * @param distance the distance between the curves
     */
    public void createBezierCurves(PdfContentByte cb, float x0, float y0,
        float x1, float y1, float x2, float y2, float x3, 
        float y3, float distance) 
    {
      cb.MoveTo(x0, y0);
      cb.LineTo(x1, y1);
      cb.MoveTo(x2, y2);
      cb.LineTo(x3, y3);
      cb.MoveTo(x0, y0);
      cb.CurveTo(x1, y1, x2, y2, x3, y3);
      x0 += distance;
      x1 += distance;
      x2 += distance;
      x3 += distance;
      cb.MoveTo(x2, y2);
      cb.LineTo(x3, y3);
      cb.MoveTo(x0, y0);
      cb.CurveTo(x2, y2, x3, y3);
      x0 += distance;
      x1 += distance;
      x2 += distance;
      x3 += distance;
      cb.MoveTo(x0, y0);
      cb.LineTo(x1, y1);
      cb.MoveTo(x0, y0);
      cb.CurveTo(x1, y1, x3, y3);
      cb.Stroke();
    }
   // ---------------------------------------------------------------------------
   /**
    * Creates a path for circle using Bezier curvers.
    * The path can be constructed clockwise or counter-clockwise.
    * This method doesn't Fill or stroke the circle!
    * @param canvas    the canvas for which the path is constructed
    * @param x         the X coordinate of the center of the circle
    * @param y         the Y coordinate of the center of the circle
    * @param r         the radius
    * @param clockwise true if the circle has to be constructed clockwise
    */
   public static void CreateCircle(PdfContentByte canvas, float x, float y,
 float r, bool clockwise)
   {
       float b = 0.5523f;
         if (clockwise) {
       canvas.MoveTo(x + r, y);
       canvas.CurveTo(x + r, y - r * b, x + r * b, y - r, x, y - r);
       canvas.CurveTo(x - r * b, y - r, x - r, y - r * b, x - r, y);
       canvas.CurveTo(x - r, y + r * b, x - r * b, y + r, x, y + r);
       canvas.CurveTo(x + r * b, y + r, x + r, y + r * b, x + r, y);
         } else {
       canvas.MoveTo(x + r, y);
       canvas.CurveTo(x + r, y + r * b, x + r * b, y + r, x, y + r);
       canvas.CurveTo(x - r * b, y + r, x - r, y + r * b, x - r, y);
       canvas.CurveTo(x - r, y - r * b, x - r * b, y - r, x, y - r);
       canvas.CurveTo(x + r * b, y - r, x + r, y - r * b, x + r, y);
         }
   }