SetTextMatrix() 공개 메소드

public SetTextMatrix ( float x, float y ) : void
x float
y float
리턴 void
예제 #1
1
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            if (_isLastPage)
            {
                var relativeWidths = ColumnsHelper.GetRelativeColumnsForProducts(PageSize.A4);

                //RODAPE
                var pdfTableFooter = new BuilderTable().Create(relativeWidths).Standard();
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("DADOS ADICIONAIS").FixedHeight(15).Bold().HorizontalLeft().VerticalBottom().Colspan(42).NoBorder().BorderBuilder(false, false, false, false).Standard());

                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("INFORMAÇÕES COMPLEMENTARES").FixedHeight(5).Bold().HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, true).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("RESERVADO AO FISCO").Bold().HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, true).Standard());

                var infAdicional = _nfe.NFe.infNFe.infAdic;
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(infAdicional.infCpl).FixedHeight(25).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, false).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, false).Standard());

                if (_isHomolog)
                {
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create("SEM VALOR FISCAL").FixedHeight(5).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, true, false).Standard());
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, true, false).Standard());
                }

                document.Add(pdfTableFooter);
            }

            const float posX = 325f;
            const float posY = 662f;

            var pageN = writer.PageNumber;
            var text = "Folha " + pageN + "/";
            var len = _baseFont.GetWidthPoint(text, 8);

            _pdfContent = writer.DirectContent;
            _pdfContent.SetRGBColorFill(100, 100, 100);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.SetTextMatrix(posX, posY);
            _pdfContent.ShowText(text);
            _pdfContent.EndText();
            _pdfContent.AddTemplate(_pageNumberTemplate, posX + len, posY);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.EndText();
        }
예제 #2
0
        protected void PrintBarcodes(PdfWriter pdfWriter, Document doc, Purchase purchase)
        {
            PdfPTable table         = new PdfPTable(1);
            var       query         = _purchaseItemRepository.Table;
            var       purchaseItems = query.Where(x => x.PurchaseId == purchase.Id).ToList();

            foreach (var purchaseItem in purchaseItems)
            {
                iTextSharp.text.pdf.PdfContentByte cb = pdfWriter.DirectContent;
                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                bc.TextAlignment = Element.ALIGN_LEFT;
                bc.Code          = purchaseItem.EAN; // CommonUtils.GenerateBarCodeEAN13(purchaseItem.Id);
                bc.StartStopText = false;
                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                bc.Extended      = true;

                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                      iTextSharp.text.BaseColor.Black, iTextSharp.text.BaseColor.Black);

                cb.SetTextMatrix(1.5f, 3.0f);
                img.ScaleToFit(60, 5);
                img.SetAbsolutePosition(1.5f, 1);
                cb.AddImage(img);
                table.AddCell(img);
            }
            doc.Add(table);
        }
예제 #3
0
        public void OnEndPage(iPdf.PdfWriter writer, iText.Document document)
        {
            iPdf.BaseFont       helv = iPdf.BaseFont.CreateFont(iPdf.BaseFont.HELVETICA, iPdf.BaseFont.WINANSI, iPdf.BaseFont.NOT_EMBEDDED);
            iPdf.PdfContentByte cb   = writer.DirectContent;
            int    pageN             = writer.PageNumber;
            string text = pageN.ToString();

            iText.Rectangle pageSize = document.PageSize;
            cb.SetRGBColorFill(100, 100, 100);
            cb.BeginText();
            cb.SetFontAndSize(helv, 12);
            cb.SetTextMatrix(document.LeftMargin, pageSize.GetBottom(document.BottomMargin));
            cb.ShowText(text);
            cb.EndText();
        }
예제 #4
0
        }     //  end setGraphTitle

        private void AddWatermarkText(string sourceFile, string outputFile, string watermarkText, float watermarkFontSize, float watermarkFontOpacity, float watermarkRotation)
        {
            iTextSharp.text.pdf.PdfReader      reader       = null;
            iTextSharp.text.pdf.PdfStamper     stamper      = null;
            iTextSharp.text.pdf.PdfGState      gstate       = null;
            iTextSharp.text.pdf.PdfContentByte underContent = null;
            iTextSharp.text.Rectangle          rect         = null;

            int pageCount = 0;

            try
            {
                reader  = new iTextSharp.text.pdf.PdfReader(sourceFile);
                rect    = reader.GetPageSizeWithRotation(1);
                stamper = new PdfStamper(reader, new System.IO.FileStream(outputFile, System.IO.FileMode.CreateNew), '\0', true);

                iTextSharp.text.pdf.BaseFont watermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.COURIER,
                                                                                                     iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
                gstate               = new iTextSharp.text.pdf.PdfGState();
                gstate.FillOpacity   = watermarkFontOpacity;
                gstate.StrokeOpacity = watermarkFontOpacity;
                pageCount            = reader.NumberOfPages;
                for (int i = 1; i <= pageCount; i++)
                {
                    underContent = stamper.GetUnderContent(i);
                    underContent.SaveState();
                    underContent.SetGState(gstate);
                    underContent.SetColorFill(iTextSharp.text.BaseColor.DARK_GRAY);
                    underContent.BeginText();
                    underContent.SetFontAndSize(watermarkFont, watermarkFontSize);
                    underContent.SetTextMatrix(30, 30);
                    underContent.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, watermarkRotation);
                    underContent.EndText();
                    underContent.RestoreState();
                }   //  end for i loop

                stamper.Close();
                reader.Close();
            }   //  end try
            catch (Exception ex)
            {
                throw ex;
            } //  end
            return;
        }     //  end AddWatermark
예제 #5
0
        private static void FooterPdfInitialize(PdfWriter writer, Document document, PdfTemplate template, PdfContentByte contentByte, BaseFont baseFont, DateTime PrintTime)
        {
            int pageNumber = writer.PageNumber;
            string footerText = string.Format("Strona {0}{1}", pageNumber, " z ");
            float lenght = baseFont.GetWidthPoint(footerText, textSize);
            Rectangle pageSize = document.PageSize;

            contentByte.SetRGBColorFill(100, 100, 100);
            contentByte.BeginText();
            contentByte.SetFontAndSize(baseFont, textSize);
            contentByte.SetTextMatrix(pageSize.GetLeft(left), pageSize.GetBottom(bottom));
            contentByte.ShowText(footerText);
            contentByte.EndText();
            contentByte.AddTemplate(template, pageSize.GetLeft(left) + lenght, pageSize.GetBottom(bottom));

            contentByte.BeginText();
            contentByte.SetFontAndSize(baseFont, textSize);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, string.Format("Utworzony: {0}", PrintTime.ToString()), pageSize.GetRight(right), pageSize.GetBottom(bottom), 0);
            contentByte.EndText();
        }
예제 #6
0
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
 * barcode is always placed at coodinates (0, 0). Use the
 * translation matrix to move it elsewhere.<p>
 * The bars and text are written in the following colors:<p>
 * <P><TABLE BORDER=1>
 * <TR>
 *    <TH><P><CODE>barColor</CODE></TH>
 *    <TH><P><CODE>textColor</CODE></TH>
 *    <TH><P>Result</TH>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P>bars and text painted with current fill color</TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>barColor</CODE></TD>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P><CODE>textColor</CODE></TD>
 *    <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>barColor</CODE></TD>
 *    <TD><P><CODE>textColor</CODE></TD>
 *    <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
 *    </TR>
 * </TABLE>
 * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
 * @param barColor the color of the bars. It can be <CODE>null</CODE>
 * @param textColor the color of the text. It can be <CODE>null</CODE>
 * @return the dimensions the barcode occupies
 */
 public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
 {
     String fullCode = code;
     if (generateChecksum && checksumText)
         fullCode = CalculateChecksum(code);
     if (!startStopText)
         fullCode = fullCode.Substring(1, fullCode.Length - 2);
     float fontX = 0;
     if (font != null) {
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code);
     int wide = 0;
     for (int k = 0; k < bars.Length; ++k) {
         wide += (int)bars[k];
     }
     int narrow = bars.Length - wide;
     float fullWidth = x * (narrow + wide * n);
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = (bars[k] == 0 ? x : x * n);
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return BarcodeSize;
 }
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
 * barcode is always placed at coodinates (0, 0). Use the
 * translation matrix to move it elsewhere.<p>
 * The bars and text are written in the following colors:<p>
 * <P><TABLE BORDER=1>
 * <TR>
 *   <TH><P><CODE>barColor</CODE></TH>
 *   <TH><P><CODE>textColor</CODE></TH>
 *   <TH><P>Result</TH>
 *   </TR>
 * <TR>
 *   <TD><P><CODE>null</CODE></TD>
 *   <TD><P><CODE>null</CODE></TD>
 *   <TD><P>bars and text painted with current fill color</TD>
 *   </TR>
 * <TR>
 *   <TD><P><CODE>barColor</CODE></TD>
 *   <TD><P><CODE>null</CODE></TD>
 *   <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
 *   </TR>
 * <TR>
 *   <TD><P><CODE>null</CODE></TD>
 *   <TD><P><CODE>textColor</CODE></TD>
 *   <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
 *   </TR>
 * <TR>
 *   <TD><P><CODE>barColor</CODE></TD>
 *   <TD><P><CODE>textColor</CODE></TD>
 *   <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
 *   </TR>
 * </TABLE>
 * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
 * @param barColor the color of the bars. It can be <CODE>null</CODE>
 * @param textColor the color of the text. It can be <CODE>null</CODE>
 * @return the dimensions the barcode occupies
 */
 public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor) {
     string fullCode;
     if (codeType == CODE128_RAW) {
         int idx = code.IndexOf('\uffff');
         if (idx < 0)
             fullCode = "";
         else
             fullCode = code.Substring(idx + 1);
     }
     else if (codeType == CODE128_UCC)
         fullCode = GetHumanReadableUCCEAN(code);
     else
         fullCode = RemoveFNC1(code);
     float fontX = 0;
     if (font != null) {
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     string bCode;
     if (codeType == CODE128_RAW) {
         int idx = code.IndexOf('\uffff');
         if (idx >= 0)
             bCode = code.Substring(0, idx);
         else
             bCode = code;
     }
     else {
         bCode = GetRawText(code, codeType == CODE128_UCC);
     }
     int len = bCode.Length;
     float fullWidth = (len + 2) * 11 * x + 2 * x;
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     byte[] bars = GetBarsCode128Raw(bCode);
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = bars[k] * x;
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return this.BarcodeSize;
 }    
        private void button1_Click(object sender, EventArgs e)
        {
            conn.Open();

            string query = ("select eru.emp_ru_name,eru.emp_ru_idcard,eru.emp_ru_birthday,eru.emp_ru_age,eru.emp_ru_telwork,eru.emp_ru_telmobile,eru.emp_ru_telhome,eru.emp_ru_telparent,eru.emp_ru_nameparent,eru.em_ru_addressparent,eru.emp_ru_namedad,eru.emp_ru_namemom,eru.emp_ru_namehusband_and_wife,eru.emp_ru_address,workplace.workplace,position.pos_id,eru.emp_ru_id ,privilege.privil_status from employee_ru eru left join workplace  on workplace.workplace_id = eru.workplace_id left join position on position.pos_id = eru.pos_id left join privilege on privilege.emp_ru_id = eru.emp_ru_id where eru.emp_ru_idcard ='" + tb1.Text + "'");

            cmd = new SqlCommand(query, conn);
            sdr = cmd.ExecuteReader();
            if (sdr.Read())
            {
                string privil_status = sdr["privil_status"].ToString();
                if (privil_status != "ได้รับสิทธิการรักษา")
                {
                    string   emp_ru_name                 = sdr["emp_ru_name"].ToString();
                    string   emp_ru_idcard               = sdr["emp_ru_idcard"].ToString();
                    DateTime birthday                    = Convert.ToDateTime(sdr["emp_ru_birthday"].ToString());
                    string   date_birth                  = String.Format("{0:yyyy-MM-dd}", birthday);
                    string   emp_ru_birthday             = date_birth;
                    string   emp_ru_age                  = sdr["emp_ru_age"].ToString();
                    string   emp_ru_telwork              = sdr["emp_ru_telwork"].ToString();
                    string   emp_ru_telmobile            = sdr["emp_ru_telmobile"].ToString();
                    string   emp_ru_telhome              = sdr["emp_ru_telhome"].ToString();
                    string   emp_ru_telparent            = sdr["emp_ru_telparent"].ToString();
                    string   emp_ru_nameparent           = sdr["emp_ru_nameparent"].ToString();
                    string   em_ru_addressparent         = sdr["em_ru_addressparent"].ToString();
                    string   emp_ru_namedad              = sdr["emp_ru_namedad"].ToString();
                    string   emp_ru_namemom              = sdr["emp_ru_namemom"].ToString();
                    string   emp_ru_namehusband_and_wife = sdr["emp_ru_namehusband_and_wife"].ToString();
                    string   emp_ru_address              = sdr["emp_ru_address"].ToString();
                    string   workplace                   = sdr["workplace"].ToString();

                    int    emp_ru_id = Convert.ToInt32(sdr["emp_ru_id"].ToString());
                    string pos_id    = sdr["pos_id"].ToString();

                    /*     query = ("insert into opd (emp_ru_id,pos_id)" +
                     * "values('" + emp_ru_id + "','" + pos_id + "')");
                     *   cmd = new SqlCommand(query, conn);
                     *   sda = new SqlDataAdapter(cmd);
                     *   dt = new DataTable();
                     *   sda.Fill(dt);*/

                    query = ("insert into opd (opd_name,opd_idcard,opd_birthday,opd_age,opd_telwork,opd_telmobile ,opd_telhome,opd_workplace,opd_telparent,opd_nameparent,opd_addressparent,opd_namedad,opd_namemom,opd_namehusband_and_wife,opd_address,emp_ru_id,pos_id)" +
                             "values('" + emp_ru_name + " ','" + emp_ru_idcard + " ','" + emp_ru_birthday + "','" + emp_ru_age + " '," +
                             "'" + emp_ru_telwork + " ','" + emp_ru_telmobile + " ','" + emp_ru_telhome + " ','" + workplace + "','" + emp_ru_telparent + " '," +
                             "'" + emp_ru_nameparent + "','" + em_ru_addressparent + " ','" + emp_ru_namedad + " '" +
                             ",'" + emp_ru_namemom + "','" + emp_ru_namehusband_and_wife + " ','" + emp_ru_address + " ','" + emp_ru_id + "','" + pos_id + "')");
                    cmd = new SqlCommand(query, conn);
                    sda = new SqlDataAdapter(cmd);
                    dt  = new DataTable();
                    sda.Fill(dt);
                    query = ("select opd_id from opd where emp_ru_id ='" + emp_ru_id + "'");
                    cmd   = new SqlCommand(query, conn);
                    sdr   = cmd.ExecuteReader();
                    if (sdr.Read())
                    {
                        int id = Convert.ToInt32(sdr["opd_id"].ToString());

                        query = ("select count(*) from privilege where emp_ru_id = '" + emp_ru_id + "'");
                        cmd   = new SqlCommand(query, conn);
                        sda   = new SqlDataAdapter(cmd);
                        dt    = new DataTable();
                        sda.Fill(dt);
                        //  sdr = cmd.ExecuteReader();
                        int count_par = (int)cmd.ExecuteScalar();
                        if (count_par == 1)
                        {
                            query = ("update privilege set privil_status = 'ได้รับสิทธิการรักษา', opd_id = '" + id + "' , date = SYSDATETIME() , time = SYSDATETIME() where emp_ru_id = '" + emp_ru_id + "'");
                            cmd   = new SqlCommand(query, conn);
                            sda   = new SqlDataAdapter(cmd);
                            dt    = new DataTable();
                            sda.Fill(dt);
                            query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                            cmd   = new SqlCommand(query, conn);
                            sdr   = cmd.ExecuteReader();
                            if (sdr.Read())
                            {
                                int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                                query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                                cmd   = new SqlCommand(query, conn);
                                sda   = new SqlDataAdapter(cmd);
                                dt    = new DataTable();
                                sda.Fill(dt);



                                query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");


                                cmd = new SqlCommand(query, conn);
                                sda = new SqlDataAdapter(cmd);
                                dt  = new DataTable();
                                sda.Fill(dt);



                                string               fontpath   = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                                BaseFont             basefont   = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                                var el = new Chunk();
                                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                                                   el.Font.Style, el.Font.Color);
                                el.Font = f2;

                                Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

                                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                                doc.Open();
                                iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                                bc.TextAlignment = Element.ALIGN_LEFT;
                                bc.Code          = S1.Text;
                                bc.StartStopText = false;
                                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                                bc.Extended      = true;

                                iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                                ru.ScalePercent(15f);



                                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                                      iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                                cb.SetTextMatrix(100f, 150.5f);
                                img.ScaleToFit(150, 159);
                                img.SetAbsolutePosition(100f, 150f);
                                //     doc.Add(ru);
                                PdfPTable headerTable = new PdfPTable(2);
                                headerTable.TotalWidth          = 530f;
                                headerTable.HorizontalAlignment = 0;
                                headerTable.SpacingAfter        = 20;
                                //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

                                float[] headerTableColWidth = new float[2];
                                headerTableColWidth[0] = 220f;
                                headerTableColWidth[1] = 310f;

                                headerTable.SetWidths(headerTableColWidth);
                                headerTable.LockedWidth = true;

                                PdfPCell headerTableCell_0 = new PdfPCell(ru);
                                headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                                headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                headerTable.AddCell(headerTableCell_0);

                                PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));

                                head.HorizontalAlignment = Element.ALIGN_LEFT;
                                head.VerticalAlignment   = Element.ALIGN_BOTTOM;
                                head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                //       headerTable.AddCell(new PdfPCell(ru));
                                headerTable.AddCell(head);

                                doc.Add(headerTable);
                                //   Paragraph pa = new Paragraph(""+head+"");
                                //   doc.Add(pa);
                                PdfPTable table = new PdfPTable(1);
                                //  table.AddCell(new PdfPCell(ru));
                                table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ             " + S2.Text + "\nวันเดือนปีเกิด            " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ        " + S4.Text + "\n เบอร์โทรศัพท์บ้าน             " + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง           " + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง           " + em_ru_addressparent + "\nชื่อบิดา            " + emp_ru_namedad + "\nชื่อมารดา            " + emp_ru_namemom + "\nชื่อสามีหรือภรรยา            " + emp_ru_namehusband_and_wife + "\nที่อยู่           " + emp_ru_address + "\nสังกัด      " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้            " + S1.Text + "\nรหัสผ่าน              " + S3.Text + "", el.Font)));
                                table.AddCell(new PdfPCell(img));
                                //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                                // table.AddCell(img);
                                // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                                //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                                //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                                doc.Add(table);
                                doc.Close();
                                System.Diagnostics.Process.Start("" + S2.Text + ".pdf");

                                clinic_approve_step2 appr2 = new clinic_approve_step2();
                                appr2.Show();
                                clinic_approve approve = new clinic_approve();
                                approve.Close();
                                Visible = false;
                            }
                        }
                        else
                        {
                            query = ("insert into privilege (privil_status,emp_ru_idcard,date,time,opd_id,emp_ru_id) values('ได้รับสิทธิการรักษา','" + emp_ru_idcard + "',SYSDATETIME(), SYSDATETIME(),'" + id + "','" + emp_ru_id + "');");
                            cmd   = new SqlCommand(query, conn);
                            sda   = new SqlDataAdapter(cmd);
                            dt    = new DataTable();
                            sda.Fill(dt);
                            query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                            cmd   = new SqlCommand(query, conn);
                            sdr   = cmd.ExecuteReader();
                            if (sdr.Read())
                            {
                                int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                                query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                                cmd   = new SqlCommand(query, conn);
                                sda   = new SqlDataAdapter(cmd);
                                dt    = new DataTable();
                                sda.Fill(dt);



                                query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");


                                cmd = new SqlCommand(query, conn);
                                sda = new SqlDataAdapter(cmd);
                                dt  = new DataTable();
                                sda.Fill(dt);



                                string               fontpath   = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                                BaseFont             basefont   = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                                var el = new Chunk();
                                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                                                   el.Font.Style, el.Font.Color);
                                el.Font = f2;

                                Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

                                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                                doc.Open();
                                iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                                bc.TextAlignment = Element.ALIGN_LEFT;
                                bc.Code          = S1.Text;
                                bc.StartStopText = false;
                                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                                bc.Extended      = true;

                                iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                                ru.ScalePercent(15f);



                                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                                      iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                                cb.SetTextMatrix(100f, 150.5f);
                                img.ScaleToFit(150, 159);
                                img.SetAbsolutePosition(100f, 150f);
                                //     doc.Add(ru);
                                PdfPTable headerTable = new PdfPTable(2);
                                headerTable.TotalWidth          = 530f;
                                headerTable.HorizontalAlignment = 0;
                                headerTable.SpacingAfter        = 20;
                                //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

                                float[] headerTableColWidth = new float[2];
                                headerTableColWidth[0] = 220f;
                                headerTableColWidth[1] = 310f;

                                headerTable.SetWidths(headerTableColWidth);
                                headerTable.LockedWidth = true;

                                PdfPCell headerTableCell_0 = new PdfPCell(ru);
                                headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                                headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                headerTable.AddCell(headerTableCell_0);

                                PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));

                                head.HorizontalAlignment = Element.ALIGN_LEFT;
                                head.VerticalAlignment   = Element.ALIGN_BOTTOM;
                                head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                //       headerTable.AddCell(new PdfPCell(ru));
                                headerTable.AddCell(head);

                                doc.Add(headerTable);
                                //   Paragraph pa = new Paragraph(""+head+"");
                                //   doc.Add(pa);
                                PdfPTable table = new PdfPTable(1);
                                //  table.AddCell(new PdfPCell(ru));
                                table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                                table.AddCell(new PdfPCell(img));
                                //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                                // table.AddCell(img);
                                // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                                //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                                //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                                doc.Add(table);
                                doc.Close();
                                System.Diagnostics.Process.Start("" + S2.Text + ".pdf");



                                clinic_approve_step2 appr2 = new clinic_approve_step2();
                                appr2.Show();
                                clinic_approve approve = new clinic_approve();
                                approve.Close();
                                Visible = false;
                            }
                        }

                        /*
                         * if (count_par == 1)
                         * {
                         *
                         *  query = ("update privilege set privil_status = 'ได้รับสิทธิการรักษา', opd_id = '" + id + "' , date = SYSDATETIME() , time = SYSDATETIME() where emp_ru_id = '" + emp_ru_id + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sda = new SqlDataAdapter(cmd);
                         *  dt = new DataTable();
                         *  sda.Fill(dt);
                         *  query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sdr = cmd.ExecuteReader();
                         *  if (sdr.Read())
                         *  {
                         *      int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                         *      query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *      query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");
                         *
                         *
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *
                         *      string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                         *      BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                         *      iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                         *      var el = new Chunk();
                         *      iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                         *                                      el.Font.Style, el.Font.Color);
                         *      el.Font = f2;
                         *
                         *      Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
                         *
                         *      PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                         *      doc.Open();
                         *      iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                         *      iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
                         *      bc.TextAlignment = Element.ALIGN_LEFT;
                         *      bc.Code = S1.Text;
                         *      bc.StartStopText = false;
                         *      bc.CodeType = iTextSharp.text.pdf.Barcode128.EAN13;
                         *      bc.Extended = true;
                         *
                         *      iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                         *      ru.ScalePercent(15f);
                         *
                         *
                         *
                         *
                         *      iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                         *        iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);
                         *
                         *      cb.SetTextMatrix(100f, 150.5f);
                         *      img.ScaleToFit(150, 159);
                         *      img.SetAbsolutePosition(100f, 150f);
                         *      //     doc.Add(ru);
                         *      PdfPTable headerTable = new PdfPTable(2);
                         *      headerTable.TotalWidth = 530f;
                         *      headerTable.HorizontalAlignment = 0;
                         *      headerTable.SpacingAfter = 20;
                         *      //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
                         *
                         *      float[] headerTableColWidth = new float[2];
                         *      headerTableColWidth[0] = 220f;
                         *      headerTableColWidth[1] = 310f;
                         *
                         *      headerTable.SetWidths(headerTableColWidth);
                         *      headerTable.LockedWidth = true;
                         *
                         *      PdfPCell headerTableCell_0 = new PdfPCell(ru);
                         *      headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      headerTable.AddCell(headerTableCell_0);
                         *
                         *      PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));
                         *
                         *      head.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      head.VerticalAlignment = Element.ALIGN_BOTTOM;
                         *      head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      //       headerTable.AddCell(new PdfPCell(ru));
                         *      headerTable.AddCell(head);
                         *
                         *      doc.Add(headerTable);
                         *      //   Paragraph pa = new Paragraph(""+head+"");
                         *      //   doc.Add(pa);
                         *      PdfPTable table = new PdfPTable(1);
                         *      //  table.AddCell(new PdfPCell(ru));
                         *      table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                         *      table.AddCell(new PdfPCell(img));
                         *      //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                         *      // table.AddCell(img);
                         *      // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                         *      //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                         *      //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                         *      doc.Add(table);
                         *      doc.Close();
                         *      System.Diagnostics.Process.Start("" + S2.Text + ".pdf");
                         *
                         *      clinic_approve_step2 appr2 = new clinic_approve_step2();
                         *      appr2.Show();
                         *      clinic_approve approve = new clinic_approve();
                         *      approve.Close();
                         *      Visible = false;
                         *
                         *
                         *  }
                         *  else
                         *  {
                         */
                        /*
                         *  query = ("insert into privilege (privil_status,emp_ru_idcard,date,time,opd_id,emp_ru_id) values('ได้รับสิทธิการรักษา','" + emp_ru_idcard + "',SYSDATETIME(), SYSDATETIME(),'" + id + "','" + emp_ru_id + "');");
                         *  cmd = new SqlCommand(query, conn);
                         *  sda = new SqlDataAdapter(cmd);
                         *  dt = new DataTable();
                         *  sda.Fill(dt);
                         *  query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sdr = cmd.ExecuteReader();
                         *  if (sdr.Read())
                         *  {
                         *      int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                         *      query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *      query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");
                         *
                         *
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *
                         *      string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                         *      BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                         *      iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                         *      var el = new Chunk();
                         *      iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                         *                                      el.Font.Style, el.Font.Color);
                         *      el.Font = f2;
                         *
                         *      Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
                         *
                         *      PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                         *      doc.Open();
                         *      iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                         *      iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
                         *      bc.TextAlignment = Element.ALIGN_LEFT;
                         *      bc.Code = S1.Text;
                         *      bc.StartStopText = false;
                         *      bc.CodeType = iTextSharp.text.pdf.Barcode128.EAN13;
                         *      bc.Extended = true;
                         *
                         *      iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                         *      ru.ScalePercent(15f);
                         *
                         *
                         *
                         *
                         *      iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                         *        iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);
                         *
                         *      cb.SetTextMatrix(100f, 150.5f);
                         *      img.ScaleToFit(150, 159);
                         *      img.SetAbsolutePosition(100f, 150f);
                         *      //     doc.Add(ru);
                         *      PdfPTable headerTable = new PdfPTable(2);
                         *      headerTable.TotalWidth = 530f;
                         *      headerTable.HorizontalAlignment = 0;
                         *      headerTable.SpacingAfter = 20;
                         *      //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
                         *
                         *      float[] headerTableColWidth = new float[2];
                         *      headerTableColWidth[0] = 220f;
                         *      headerTableColWidth[1] = 310f;
                         *
                         *      headerTable.SetWidths(headerTableColWidth);
                         *      headerTable.LockedWidth = true;
                         *
                         *      PdfPCell headerTableCell_0 = new PdfPCell(ru);
                         *      headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      headerTable.AddCell(headerTableCell_0);
                         *
                         *      PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));
                         *
                         *      head.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      head.VerticalAlignment = Element.ALIGN_BOTTOM;
                         *      head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      //       headerTable.AddCell(new PdfPCell(ru));
                         *      headerTable.AddCell(head);
                         *
                         *      doc.Add(headerTable);
                         *      //   Paragraph pa = new Paragraph(""+head+"");
                         *      //   doc.Add(pa);
                         *      PdfPTable table = new PdfPTable(1);
                         *      //  table.AddCell(new PdfPCell(ru));
                         *      table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                         *      table.AddCell(new PdfPCell(img));
                         *      //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                         *      // table.AddCell(img);
                         *      // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                         *      //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                         *      //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                         *      doc.Add(table);
                         *      doc.Close();
                         *      System.Diagnostics.Process.Start("" + S2.Text + ".pdf");
                         *
                         *      clinic_approve_step2 appr2 = new clinic_approve_step2();
                         *      appr2.Show();
                         *      clinic_approve approve = new clinic_approve();
                         *      approve.Close();
                         *      Visible = false;
                         *
                         *  }
                         */
                    }


                    /*
                     * query = ("insert into opd (opd_name,opd_idcard,opd_birthday,opd_age,opd_telwork,opd_telmobile ,opd_telhome,emp_ru_telparent,emp_ru_nameparent,em_ru_addressparent,emp_ru_namedad,eru.emp_ru_namemom,emp_ru_namehusband_and_wife,emp_ru_address)"+
                     *  "values('"+emp_ru_name+" ','"+emp_ru_idcard+" ','"+emp_ru_birthday+" ','"+emp_ru_age+" ',"+
                     *  "'"+emp_ru_age+" ','"+emp_ru_telwork+" ','"+emp_ru_telmobile+" ','"+emp_ru_telhome+" ',"+
                     *  "'"+emp_ru_telparent+"','"+emp_ru_nameparent+" ','"+ em_ru_addressparent + " '"+
                     *  ",'"+ emp_ru_namedad + "','"+emp_ru_namemom+" ','"+ emp_ru_namehusband_and_wife + " ',"+
                     *  "'"+ emp_ru_address + "')");
                     * cmd = new SqlCommand(query, conn);
                     * sda = new SqlDataAdapter(cmd);
                     * dt = new DataTable();
                     * sda.Fill(dt);
                     *
                     */
                }
            }



            conn.Close();
        }
예제 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            Document doc = new Document(new iTextSharp.text.Rectangle(24, 12), 5, 5, 1, 1);

            try
            {
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(
                                                             Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes5555555.pdf", FileMode.Create));
                doc.Open();

                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Price");
                for (int i = 0; i < 20; i++)
                {
                    DataRow row = dt.NewRow();
                    row["ID"]    = "ZS00000000000000" + i.ToString();
                    row["Price"] = "100," + i.ToString();
                    dt.Rows.Add(row);
                }
                //       System.Drawing.Image img1 = null;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i != 0)
                    {
                        doc.NewPage();
                    }
                    PdfContentByte cb1 = writer.DirectContent;
                    BaseFont       bf  = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                    cb1.SetFontAndSize(bf, 2.0f);
                    cb1.BeginText();
                    cb1.SetTextMatrix(1.2f, 9.5f);
                    cb1.ShowText("Safi Garments");
                    cb1.EndText();

                    PdfContentByte cb2 = writer.DirectContent;
                    BaseFont       bf1 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    cb2.SetFontAndSize(bf1, 1.3f);
                    cb2.BeginText();
                    cb2.SetTextMatrix(17.5f, 1.0f);
                    cb2.ShowText(dt.Rows[i]["Price"].ToString());
                    cb2.EndText();

                    iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
                    iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                    bc.TextAlignment = Element.ALIGN_LEFT;
                    bc.Code          = dt.Rows[i]["ID"].ToString();
                    bc.StartStopText = false;
                    bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                    bc.Extended      = true;

                    //System.Drawing.Image bimg =
                    //  bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
                    //img1 = bimg;

                    iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                          iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                    cb.SetTextMatrix(1.5f, 3.0f);
                    img.ScaleToFit(60, 5);
                    img.SetAbsolutePosition(1.5f, 1);
                    cb.AddImage(img);
                }

                ////////////////////***********************************//////////////////////

                doc.Close();
                System.Diagnostics.Process.Start(Environment.GetFolderPath(
                                                     Environment.SpecialFolder.Desktop) + "/codes.pdf");
                //MessageBox.Show("Bar codes generated on desktop fileName=codes.pdf");
            }
            catch
            {
            }
            finally
            {
                doc.Close();
            }
        }
예제 #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();
        }
예제 #11
0
        //QR Code Generator
        private void GenerateQRCode(PdfWriter writer, Document doc, DataTable dt)
        {
            //Document doc = new Document(new iTextSharp.text.Rectangle(4.5f, 5.5f), 0.5f, 0.5f, 0, 0);

            try
            {
                //PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(
                //  Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf", FileMode.Create));
                //doc.Open();

                //DataTable dt = new DataTable();
                //dt.Columns.Add("ID");
                //dt.Columns.Add("Price");
                //for (int i = 0; i < 8; i++)
                //{
                //    DataRow row = dt.NewRow();
                //    row["ID"] = "ZS00000000000000" + i.ToString();
                //    row["Price"] = "100," + i.ToString();
                //    dt.Rows.Add(row);
                //}

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i != 0)
                    {
                        doc.NewPage();
                    }

                    iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
                    string strID    = "103";                 // dt.Rows[i]["EmployeeID"].ToString();
                    string strName  = dt.Rows[i]["FullName"].ToString();
                    string strPhone = "1234567";             // dt.Rows[i]["PhoneOne"].ToString();
                    string strEmail = "*****@*****.**"; // dt.Rows[i]["Email"].ToString();
                    string strData  = string.Format("Id-{0} * Name-{1} * Phone-{2} * Email-{3}", strID, strName, strPhone, strEmail);
                    iTextSharp.text.pdf.BarcodeQRCode Qr  = new BarcodeQRCode(strData, 60, 6, null);
                    iTextSharp.text.Image             img = Qr.GetImage();
                    cb.SetTextMatrix(-2.0f, 0.0f);
                    //img.ScaleToFit(60, 5);
                    img.ScaleToFit(1200, 100);
                    //img.SetAbsolutePosition(-2.8f, 0.5f);
                    img.SetAbsolutePosition(420f, 400f);
                    //img.Border= Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;

                    //img.BorderWidth = 1f;
                    cb.AddImage(img);

                    //PdfContentByte cb1 = writer.DirectContent;
                    //BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    //cb1.SetFontAndSize(bf, 0.5f);
                    //cb1.BeginText();
                    //cb1.SetTextMatrix(0.2f, 5.1f);
                    //cb1.ShowText("Neurotherapy Academy");
                    //cb1.EndText();

                    //PdfContentByte id = writer.DirectContent;
                    //BaseFont bf1 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    //id.SetFontAndSize(bf1, 0.4f);
                    //id.BeginText();
                    //id.SetTextMatrix(0.2f, 0.6f);
                    //id.ShowText(dt.Rows[i]["FullName"].ToString());
                    //id.EndText();
                }
                // if you want to print it un comment the following two line

                //PdfAction act = new PdfAction(PdfAction.PRINTDIALOG);
                //writer.SetOpenAction(act);

                //doc.Close();

                //System.Diagnostics.Process.Start(Environment.GetFolderPath(
                //          Environment.SpecialFolder.Desktop) + "/codes.pdf");
            }
            catch
            {
            }
            finally
            {
                doc.Close();
            }
        }
예제 #12
0
        private static void WriteTextToDocument(BaseFont bf,Rectangle tamPagina,
            PdfContentByte over,PdfGState gs,string texto)
        {
            over.SetGState(gs);

            over.SetRGBColorFill(220, 220, 220);

            over.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);

            over.SetFontAndSize(bf, 46);

            Single anchoDiag =

                (Single)Math.Sqrt(Math.Pow((tamPagina.Height - 120), 2)

                + Math.Pow((tamPagina.Width - 60), 2));

            Single porc = (Single)100

                * (anchoDiag / bf.GetWidthPoint(texto, 46));

            over.SetHorizontalScaling(porc);

            double angPage = (-1)

            * Math.Atan((tamPagina.Height - 60) / (tamPagina.Width - 60));

            over.SetTextMatrix((float)Math.Cos(angPage),

                       (float)Math.Sin(angPage),

                       (float)((-1F) * Math.Sin(angPage)),

                       (float)Math.Cos(angPage),

                       30F,

                       (float)tamPagina.Height - 60);

            over.ShowText(texto);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                conn.Open();
                string query = ("insert into employee_doctor(emp_doc_name, emp_doc_idcard, emp_doc_birth, emp_doc_address, emp_doc_tel, emp_doc_email, emp_doc_occupation_id, emp_doc_specialist)values('" + txtname.Text + "', '" + txtidcard.Text + "', '" + dateTimePicker1.Text + "', '" + txtaddress.Text + "', '" + txttel.Text + "', '" + txtemail.Text + "', '" + txtooid.Text + "', '" + txtss.Text + "'); ");
                cmd = new SqlCommand(query, conn);
                sda = new SqlDataAdapter(cmd);
                dt  = new DataTable();
                sda.Fill(dt);

                query = ("select emp_doc_id from employee_doctor where emp_doc_idcard = '" + txtidcard.Text + "'");
                cmd   = new SqlCommand(query, conn);
                sda   = new SqlDataAdapter(cmd);
                dt    = new DataTable();
                sda.Fill(dt);
                sdr = cmd.ExecuteReader();
                if (sdr.Read())
                {
                    int doc_id = Convert.ToInt32(sdr["emp_doc_id"].ToString());
                    query = ("Insert into user_control(uct_user, uct_password, emp_doc_id) values('" + txtidcard.Text + "', '" + dateTimePicker1.Text + "', '" + doc_id + "');  ");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();
                    sda.Fill(dt);
                }


                string   fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);

                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL);


                var el = new Chunk();
                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                                   el.Font.Style, el.Font.Color);
                el.Font = f2;

                Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + txtname.Text + ".pdf", FileMode.Create));
                doc.Open();
                //    Paragraph pa = new Paragraph();



                /*
                 *
                 *   List list = new List(List.UNORDERED);
                 *   list.Add(new ListItem(new Phrase(10, "" + txtname.Text + "", el.Font)));
                 *   list.Add(""+txtidcard.Text+"");
                 */

                Zen.Barcode.Code128BarcodeDraw barcode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
                Picbox.Image = barcode.Draw(txtidcard.Text, 100);


                doc.NewPage();



                iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                bc.TextAlignment = Element.ALIGN_LEFT;
                bc.Code          = txtidcard.Text;
                bc.StartStopText = false;
                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                bc.Extended      = true;

                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                      iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                cb.SetTextMatrix(5.5f, 3.0f);
                img.ScaleToFit(150, 200);
                img.SetAbsolutePosition(1.5f, 1);
                //   cb.AddImage(img);
                PdfPTable table = new PdfPTable(3);
                table.AddCell(new Phrase(70, "บัตรเข้าออกงานของแพทย์", el.Font));
                table.AddCell(new Phrase(10, "" + txtname.Text + "", el.Font));
                table.AddCell(img);

                table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + txtidcard.Text + "", el.Font));
                table.AddCell(new Phrase(10, "รหัสผ่าน" + dateTimePicker1.Text + "", el.Font));


                doc.Add(table);
                //    doc.Add(pa);
                //  doc.Add(list);
                doc.Close();
                System.Diagnostics.Process.Start("" + txtname.Text + ".pdf");

                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OKCancel);
            }
        }
예제 #14
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;
        }
예제 #15
0
        private void pr_pro_Click(object sender, EventArgs e)
        {
            connection_check();
            try
            {
                Document doc = new Document(new iTextSharp.text.Rectangle(110, 80));

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf", FileMode.Create));

                doc.Open();

                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Price");
                dt.Columns.Add("INV");
                dt.Columns.Add("Expire");
                string       so1 = "", so2 = "", so3 = "", so4 = "", so5 = "";
                MySqlCommand cmsel = new MySqlCommand("select bar_name,bar_price,invoice_no,expdate from barcod", conngsm1);
                // SqlCommand cmsel = new SqlCommand("select bar_name,bar_price,invoice_no from barcod", cnn);
                cmsel.ExecuteNonQuery();
                MySqlDataReader cmread = cmsel.ExecuteReader();
                //cmsel.ExecuteNonQuery();
                // SqlDataReader cmread = cmsel.ExecuteReader();
                while (cmread.Read())
                {
                    so1 = cmread[0].ToString();
                    so2 = cmread[1].ToString();
                    so3 = cmread[2].ToString();
                    so4 = cmread[3].ToString();
                    //DateTime dts = Convert.ToDateTime(so4);
                    so5 = so4;
                    //int conts = Convert.ToInt32(textBox3.Text);

                    // for (int i = 0; i < conts; i++)
                    {
                        DataRow row = dt.NewRow();
                        row["ID"]     = so1;
                        row["Price"]  = so2;
                        row["INV"]    = so3;
                        row["Expire"] = so5;
                        dt.Rows.Add(row);
                    }
                }
                cmread.Dispose();
                System.Drawing.Image img1 = null;


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    {
                        if (i != 0)
                        {
                            doc.NewPage();
                        }



                        PdfContentByte cb1 = writer.DirectContent;
                        BaseFont       bf  = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                        cb1.SetFontAndSize(bf, 9.0f);
                        cb1.BeginText();
                        cb1.SetTextMatrix(10.0f, 68.5f);
                        cb1.ShowText("F r e s c o s w e e t s");

                        cb1.EndText();



                        PdfContentByte cb21  = writer.DirectContent;
                        BaseFont       bf111 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        cb21.SetFontAndSize(bf111, 8.0f);
                        cb21.BeginText();
                        cb21.SetTextMatrix(5.0f, 60.0f);
                        cb21.ShowText(dt.Rows[i]["INV"].ToString());
                        cb21.EndText();



                        PdfContentByte cb21c  = writer.DirectContent;
                        BaseFont       bf111c = BaseFont.CreateFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        cb21c.SetFontAndSize(bf111c, 5.3f);
                        cb21c.BeginText();
                        cb21c.SetTextMatrix(5.0f, 50.0f);
                        cb21c.ShowText(dt.Rows[i]["Expire"].ToString());
                        cb21c.EndText();



                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
                        iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                        bc.TextAlignment = Element.ALIGN_LEFT;
                        bc.Size          = 5;

                        //BaseFont bf1m = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        //bc.SetFontAndSize(bf1m, 24.3f);
                        bc.Code          = dt.Rows[i]["ID"].ToString();
                        bc.StartStopText = true;
                        bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                        bc.Extended      = false;


                        iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK);
                        BaseFont bf11             = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);


                        cb.SetTextMatrix(3.5f, 6.0f);
                        img.ScaleToFit(100, 30);
                        img.SetAbsolutePosition(5.0f, 5);
                        img.Alignment = Element.ALIGN_LEFT;
                        cb.AddImage(img);
                    }
                }

                ////////////////////***********************************//////////////////////
                doc.Open();
                doc.Close();
                System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf");

                checkBox1.CheckState = CheckState.Unchecked;
                checkBox2.CheckState = CheckState.Unchecked;
                checkBox3.CheckState = CheckState.Unchecked;
                checkBox4.CheckState = CheckState.Unchecked;
                textBox5.Text        = "";
            }
            catch (OleDbException ex)
            { }
        }
        /**
        * 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;
        }
예제 #17
0
 private void SetAppropriateTextMatrix(UChar letter, float voffset, PdfContentByte cb)
 {
     var ytlm = MyYTLM;
     if (_isPsuedoVertical)
     {
         if (CC.Cl06(letter) ||
             CC.Cl07(letter))
         {
             //句読点を平行移動。
             cb.SetTextMatrix(_xtlm + _fontSize * (1F / 2 + 1F / 8), ytlm + _fontSize * (1F / 2 + 1F / 8) + voffset);
         }
         else if (CC.Cl11(letter))
         {
             //小書きの仮名を平行移動。
             cb.SetTextMatrix(_xtlm + _fontSize / 8, ytlm + _fontSize / 8 + voffset);
         }
         else if (CC.Cl01(letter))
         {
             //始め括弧を回転、平行移動
             cb.SetTextMatrix(0F, -1F, 1F, 0F, _xtlm + _fontSize / 2, ytlm);
         }
         else if (letter.CodePoint == char.ConvertToUtf32("ー", 0))
         {
             //音引きを回転、かつ左右反転
             cb.SetTextMatrix(0F, -1F, -1F, 0F, _xtlm - _fontSize / 2, ytlm - _fontSize / 2);
         }
         else if (letter.CodePoint == char.ConvertToUtf32("—", 0)) //part of Cl08)
         {
             //エムダッシュを回転
             cb.SetTextMatrix(0F, -1F, 1F, 0F, _xtlm + _fontSize * (1F / 2F + 1 / 8F), ytlm - _fontSize / 2);
         }
         //TODO: 毎回 UString 作らない UChar[] で持つ。
         else if (
             CC.Cl02(letter) ||
             (new UString("―…‥").Contains(letter)) || //part of Cl08
             CC.Cl10(letter) ||
             (new UString("~+±=-÷≠:;‘’“”<>≦≧_|→↓←↑⇒⇔").Contains(letter))) //その他転置すべき記号。よく使いそうなものだけ
         {
             //それ以外の記号を回転
             cb.SetTextMatrix(0F, -1F, 1F, 0F, _xtlm + _fontSize / 2, ytlm - _fontSize / 2);
         }
         else
         {
             cb.SetTextMatrix(_xtlm, ytlm + voffset);
         }
     }
     else
     {
         cb.SetTextMatrix(_xtlm, ytlm + voffset);
     }
 }
예제 #18
0
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
  * barcode is always placed at coodinates (0, 0). Use the
  * translation matrix to move it elsewhere.<p>
  * The bars and text are written in the following colors:<p>
  * <P><TABLE BORDER=1>
  * <TR>
  *    <TH><P><CODE>barColor</CODE></TH>
  *    <TH><P><CODE>textColor</CODE></TH>
  *    <TH><P>Result</TH>
  *    </TR>
  * <TR>
  *    <TD><P><CODE>null</CODE></TD>
  *    <TD><P><CODE>null</CODE></TD>
  *    <TD><P>bars and text painted with current fill color</TD>
  *    </TR>
  * <TR>
  *    <TD><P><CODE>barColor</CODE></TD>
  *    <TD><P><CODE>null</CODE></TD>
  *    <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
  *    </TR>
  * <TR>
  *    <TD><P><CODE>null</CODE></TD>
  *    <TD><P><CODE>textColor</CODE></TD>
  *    <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
  *    </TR>
  * <TR>
  *    <TD><P><CODE>barColor</CODE></TD>
  *    <TD><P><CODE>textColor</CODE></TD>
  *    <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
  *    </TR>
  * </TABLE>
  * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
  * @param barColor the color of the bars. It can be <CODE>null</CODE>
  * @param textColor the color of the text. It can be <CODE>null</CODE>
  * @return the dimensions the barcode occupies
  */    
 public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor) {
     string fullCode = code;
     float fontX = 0;
     if (font != null) {
         if (generateChecksum && checksumText)
             fullCode += GetChecksum(fullCode);
         fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size);
     }
     string bCode = KeepNumbers(code);
     if (generateChecksum)
         bCode += GetChecksum(bCode);
     int len = bCode.Length;
     float fullWidth = len * (3 * x + 2 * x * n) + (6 + n ) * x;
     float barStartX = 0;
     float textStartX = 0;
     switch (textAlignment) {
         case Element.ALIGN_LEFT:
             break;
         case Element.ALIGN_RIGHT:
             if (fontX > fullWidth)
                 barStartX = fontX - fullWidth;
             else
                 textStartX = fullWidth - fontX;
             break;
         default:
             if (fontX > fullWidth)
                 barStartX = (fontX - fullWidth) / 2;
             else
                 textStartX = (fullWidth - fontX) / 2;
             break;
     }
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     byte[] bars = GetBarsInter25(bCode);
     bool print = true;
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = (bars[k] == 0 ? x : x * n);
         if (print)
             cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         cb.SetTextMatrix(textStartX, textStartY);
         cb.ShowText(fullCode);
         cb.EndText();
     }
     return this.BarcodeSize;
 }   
예제 #19
0
 /** Places the barcode in a <CODE>PdfContentByte</CODE>. The
 * barcode is always placed at coodinates (0, 0). Use the
 * translation matrix to move it elsewhere.<p>
 * The bars and text are written in the following colors:<p>
 * <P><TABLE BORDER=1>
 * <TR>
 *    <TH><P><CODE>barColor</CODE></TH>
 *    <TH><P><CODE>textColor</CODE></TH>
 *    <TH><P>Result</TH>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P>bars and text painted with current fill color</TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>barColor</CODE></TD>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P>bars and text painted with <CODE>barColor</CODE></TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>null</CODE></TD>
 *    <TD><P><CODE>textColor</CODE></TD>
 *    <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD>
 *    </TR>
 * <TR>
 *    <TD><P><CODE>barColor</CODE></TD>
 *    <TD><P><CODE>textColor</CODE></TD>
 *    <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD>
 *    </TR>
 * </TABLE>
 * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed
 * @param barColor the color of the bars. It can be <CODE>null</CODE>
 * @param textColor the color of the text. It can be <CODE>null</CODE>
 * @return the dimensions the barcode occupies
 */    
 public override Rectangle PlaceBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor) {
     Rectangle rect = this.BarcodeSize;
     float barStartX = 0;
     float barStartY = 0;
     float textStartY = 0;
     if (font != null) {
         if (baseline <= 0)
             textStartY = barHeight - baseline;
         else {
             textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size);
             barStartY = textStartY + baseline;
         }
     }
     switch (codeType) {
         case EAN13:
         case UPCA:
         case UPCE:
             if (font != null)
                 barStartX += font.GetWidthPoint(code[0], size);
             break;
     }
     byte[] bars = null;
     int[] guard = GUARD_EMPTY;
     switch (codeType) {
         case EAN13:
             bars = GetBarsEAN13(code);
             guard = GUARD_EAN13;
             break;
         case EAN8:
             bars = GetBarsEAN8(code);
             guard = GUARD_EAN8;
             break;
         case UPCA:
             bars = GetBarsEAN13("0" + code);
             guard = GUARD_UPCA;
             break;
         case UPCE:
             bars = GetBarsUPCE(code);
             guard = GUARD_UPCE;
             break;
         case SUPP2:
             bars = GetBarsSupplemental2(code);
             break;
         case SUPP5:
             bars = GetBarsSupplemental5(code);
             break;
     }
     float keepBarX = barStartX;
     bool print = true;
     float gd = 0;
     if (font != null && baseline > 0 && guardBars) {
         gd = baseline / 2;
     }
     if (barColor != null)
         cb.SetColorFill(barColor);
     for (int k = 0; k < bars.Length; ++k) {
         float w = bars[k] * x;
         if (print) {
             if (Array.BinarySearch(guard, k) >= 0)
                 cb.Rectangle(barStartX, barStartY - gd, w - inkSpreading, barHeight + gd);
             else
                 cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight);
         }
         print = !print;
         barStartX += w;
     }
     cb.Fill();
     if (font != null) {
         if (textColor != null)
             cb.SetColorFill(textColor);
         cb.BeginText();
         cb.SetFontAndSize(font, size);
         switch (codeType) {
             case EAN13:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 13; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
             case EAN8:
                 for (int k = 0; k < 8; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = TEXTPOS_EAN8[k] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
             case UPCA:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 11; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 cb.SetTextMatrix(keepBarX + x * (11 + 12 * 7), textStartY);
                 cb.ShowText(code.Substring(11, 1));
                 break;
             case UPCE:
                 cb.SetTextMatrix(0, textStartY);
                 cb.ShowText(code.Substring(0, 1));
                 for (int k = 1; k < 7; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 cb.SetTextMatrix(keepBarX + x * (9 + 6 * 7), textStartY);
                 cb.ShowText(code.Substring(7, 1));
                 break;
             case SUPP2:
             case SUPP5:
                 for (int k = 0; k < code.Length; ++k) {
                     string c = code.Substring(k, 1);
                     float len = font.GetWidthPoint(c, size);
                     float pX = (7.5f + (9 * k)) * x - len / 2;
                     cb.SetTextMatrix(pX, textStartY);
                     cb.ShowText(c);
                 }
                 break;
         }
         cb.EndText();
     }
     return rect;
 }
예제 #20
-1
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            int pageN = writer.PageNumber;
            string text = pageN + " - ";
            float len = baseFont.GetWidthPoint(text, 8);

            Rectangle pageSize = document.PageSize;
            pdfContent = writer.DirectContent;
            pdfContent.SetRGBColorFill(100, 100, 100);

            pdfContent.BeginText();
            pdfContent.SetFontAndSize(baseFont, 8);
            pdfContent.SetTextMatrix(pageSize.Width / 2, pageSize.GetBottom(30));
            pdfContent.ShowText(text);
            pdfContent.EndText();

            pdfContent.AddTemplate(pageNumberTemplate, (pageSize.Width / 2) + len, pageSize.GetBottom(30));

            pdfContent.BeginText();
            pdfContent.SetFontAndSize(baseFont, 8);
            pdfContent.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, printTime.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0);
            pdfContent.EndText();
        }