EndText() public méthode

public EndText ( ) : void
Résultat void
Exemple #1
1
// ---------------------------------------------------------------------------    
    /**
     * Draws a character representing an arrow at the current position.
     * @see com.itextpdf.text.pdf.draw.VerticalPositionMark#draw(
     *      com.itextpdf.text.pdf.PdfContentByte, float, float, float, float, float)
     */
    // i'm so stupid; originally forgot to override parent method and wondered
    // why the arrows weren't being drawn...
    public override void Draw(
      PdfContentByte canvas, float llx, float lly, float urx, float ury, float y
    ) {
      canvas.BeginText();
      canvas.SetFontAndSize(zapfdingbats, 12);
      if (left) {
        canvas.ShowTextAligned(Element.ALIGN_CENTER,
          ((char) 220).ToString(), llx - 10, y, 0
        );
      }
      else {
        canvas.ShowTextAligned(Element.ALIGN_CENTER,
          ((char) 220).ToString(), urx + 10, y + 8, 180
        );
      }
      canvas.EndText();
    }
Exemple #2
1
// ---------------------------------------------------------------------------           
    /**
     * Draws some text on every calendar sheet.
     * 
     */
    protected void DrawInfo(PdfContentByte directcontent) {
      directcontent.BeginText();
      directcontent.SetFontAndSize(bf, 18);
      float x, y;
      x = (OFFSET_LEFT + WIDTH + OFFSET_LOCATION) / 2;
      y = OFFSET_BOTTOM + HEIGHT + 24;
      directcontent.ShowTextAligned(
        Element.ALIGN_CENTER,
        "FOOBAR FILM FESTIVAL", x, y, 0
      );
      x = OFFSET_LOCATION + WIDTH_LOCATION / 2f - 6;
      y = OFFSET_BOTTOM + HEIGHT_LOCATION;
      directcontent.ShowTextAligned(
        Element.ALIGN_CENTER,
        "The Majestic", x, y, 90
      );
      y = OFFSET_BOTTOM + HEIGHT_LOCATION * 4f;
      directcontent.ShowTextAligned(
        Element.ALIGN_CENTER,
        "Googolplex", x, y, 90
      );
      y = OFFSET_BOTTOM + HEIGHT_LOCATION * 7.5f;
      directcontent.ShowTextAligned(
        Element.ALIGN_CENTER,
        "Cinema Paradiso", x, y, 90
      );
      directcontent.SetFontAndSize(bf, 12);
      x = OFFSET_LOCATION + WIDTH_LOCATION - 6;
      for (int i = 0; i < LOCATIONS; i++) {
        y = OFFSET_BOTTOM + ((8.5f - i) * HEIGHT_LOCATION);
        directcontent.ShowTextAligned(
          Element.ALIGN_CENTER,
          locations[i], x, y, 90
        );
      }
      directcontent.SetFontAndSize(bf, 6);
      y = OFFSET_BOTTOM + HEIGHT + 1;
      for (int i = 0; i < TIMESLOTS; i++) {
        x = OFFSET_LEFT + (i * WIDTH_TIMESLOT);
        directcontent.ShowTextAligned(
          Element.ALIGN_LEFT,
          TIME[i], x, y, 45
        );
      }
      directcontent.EndText();
    }
        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();
        }
Exemple #4
1
        private static void AddWaterMarkText(PdfContentByte directContent, string textWatermark, BaseFont font, float fontSize, float angle, BaseColor color, Rectangle realPageSize)
        {
            var gstate = new PdfGState { FillOpacity = 0.2f, StrokeOpacity = 0.2f };

            directContent.SaveState();
            directContent.SetGState(gstate);
            directContent.SetColorFill(color);
            directContent.BeginText();
            directContent.SetFontAndSize(font, fontSize);

            var x = (realPageSize.Right + realPageSize.Left) / 2;
            var y = (realPageSize.Bottom + realPageSize.Top) / 2;

            directContent.ShowTextAligned(Element.ALIGN_CENTER, textWatermark, x, y, angle);
            directContent.EndText();
            directContent.RestoreState();
        }
Exemple #5
0
        /// <summary>
        /// This method is used to search for the location words in pdf and update it with the words given from replacingText variable
        /// </summary>
        /// <param name="pSearch">Searchable String</param>
        /// <param name="replacingText">Replacing String</param>
        /// <param name="SC">Case Ignorance</param>
        /// <param name="SourceFile">Path of the source file</param>
        /// <param name="DestinationFile">Path of the destination file</param>
        public static void PDFTextGetter(string pSearch, string replacingText, StringComparison SC, string SourceFile, string DestinationFile)
        {
            try
            {
                iTextSharp.text.pdf.PdfContentByte cb     = null;
                iTextSharp.text.pdf.PdfContentByte cb2    = null;
                iTextSharp.text.pdf.PdfWriter      writer = null;
                iTextSharp.text.pdf.BaseFont       bf     = null;

                if (System.IO.File.Exists(SourceFile))
                {
                    PdfReader pReader = new PdfReader(SourceFile);


                    for (int page = 1; page <= pReader.NumberOfPages; page++)
                    {
                        myLocationTextExtractionStrategy strategy = new myLocationTextExtractionStrategy();
                        cb  = stamper.GetOverContent(page);
                        cb2 = stamper.GetOverContent(page);

                        //Send some data contained in PdfContentByte, looks like the first is always cero for me and the second 100,
                        //but i'm not sure if this could change in some cases
                        strategy.UndercontentCharacterSpacing  = (int)cb.CharacterSpacing;
                        strategy.UndercontentHorizontalScaling = (int)cb.HorizontalScaling;

                        //It's not really needed to get the text back, but we have to call this line ALWAYS,
                        //because it triggers the process that will get all chunks from PDF into our strategy Object
                        string currentText = PdfTextExtractor.GetTextFromPage(pReader, page, strategy);

                        //The real getter process starts in the following line
                        List <iTextSharp.text.Rectangle> MatchesFound = strategy.GetTextLocations(pSearch, SC);

                        //Set the fill color of the shapes, I don't use a border because it would make the rect bigger
                        //but maybe using a thin border could be a solution if you see the currect rect is not big enough to cover all the text it should cover
                        cb.SetColorFill(BaseColor.WHITE);

                        //MatchesFound contains all text with locations, so do whatever you want with it, this highlights them using PINK color:

                        foreach (iTextSharp.text.Rectangle rect in MatchesFound)
                        {
                            //width
                            cb.Rectangle(rect.Left, rect.Bottom, 60, rect.Height);
                            cb.Fill();
                            cb2.SetColorFill(BaseColor.BLACK);
                            bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                            cb2.SetFontAndSize(bf, 9);

                            cb2.BeginText();
                            cb2.ShowTextAligned(0, replacingText, rect.Left, rect.Bottom, 0);
                            cb2.EndText();
                            cb2.Fill();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #6
0
 public void OnStartPage(iPdf.PdfWriter writer, iText.Document document)
 {
     iPdf.PdfContentByte under = writer.DirectContentUnder;
     under.BeginText();
     iText.Image imagem = waterMark;
     imagem.SetAbsolutePosition((float)((document.PageSize.Width - imagem.Width) / 2), ((float)(document.PageSize.Height - imagem.Height) / 2));
     under.AddImage(imagem);
     under.EndText();
 }
Exemple #7
0
// ---------------------------------------------------------------------------    
    /**
     * Draws three stars to separate two paragraphs.
     * @see com.itextpdf.text.pdf.draw.DrawInterface#draw(
     * com.itextpdf.text.pdf.PdfContentByte, float, float, float, float, float)
     */
    public void Draw(
      PdfContentByte canvas, float llx, float lly, float urx, float ury, float y
    ) {
      float middle = (llx + urx) / 2;
      canvas.BeginText();
      canvas.SetFontAndSize(bf, 10);
      canvas.ShowTextAligned(Element.ALIGN_CENTER, "*", middle, y, 0);
      canvas.ShowTextAligned(Element.ALIGN_CENTER, "*  *", middle, y -10, 0);
      canvas.EndText();
    }
        private static void PdfText(PdfContentByte cb, TextAlignedPdfConfig parms)
        {
            var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb.SetColorFill(BaseColor.BLACK);
            cb.SetFontAndSize(bf, 18);

            cb.BeginText();
            cb.ShowTextAligned(parms.Alignment, parms.Text, parms.X, parms.Y, parms.Rotation);
            cb.EndText();
        }
Exemple #9
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();
        }
Exemple #10
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();
        }
Exemple #11
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
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            int pageN = writer.PageNumber;

            string text = "From SG Telecom        SIGN..........................   Exe. Name  "+ BusinessAccessLeyer.BAL.StaticVariables.selectuser+"     Given To........................... ";
               // 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, 12);
               // pdfContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, pageSize.GetRight(40), pageSize.GetBottom(30), 0);
            pdfContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, pageSize.GetLeft(40) , pageSize.GetBottom(30), 0);
            pdfContent.EndText();

            BusinessAccessLeyer.BAL.StaticVariables.selectuser = "";

              //  string path = @"D:\Dropboxdata\Dropbox\mayankmvc\Web_Complete_Inv\PresantationAccessLeyer\Images\Address Img.jpg";

              ////  iTextSharp.text.Image instanceImg = iTextSharp.text.Image.GetInstance(path);

              //  //Image logo = Image.GetInstance(path);
              //  // logo.ScaleAbsolute(500, 300);

              //   string imageURL =   path ;  // Server.MapPath(".") + "/image2.jpg";
              //   iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
              //   //Resize image depend upon your need
              //   jpg.ScaleToFit(240f, 120f);
              //   //Give space before image
              //   jpg.SpacingBefore = 10f;
              //   //Give some space after the image
              //   jpg.SpacingAfter = 1f;
              //   //jpg.Alignment = Element.ALIGN_LEFT;
              //   jpg.Alignment =  Element.ALIGN_CENTER;
              //   document.Add(jpg);

            ////////////////////////////////////
        }
 /** 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 MemoryStream PrintTerms(IEnumerable<GlossaryItem> terms)
        {
            float ppi = 72.0F;
            float PageWidth = 8.5F;
            float PageHeight = 11.0F;
            float TopBottomMargin = 0.625F;
            float LeftRightMargin = 0.75F;
            float GutterWidth = 0.25F;
            float HeaderFooterHeight = 0.125F;
            float Column1Left = LeftRightMargin;
            float Column1Right = ((PageWidth - (LeftRightMargin * 2) - GutterWidth) / 2) + LeftRightMargin;
            float Column2Left = Column1Right + GutterWidth;
            float Column2Right = PageWidth - LeftRightMargin;

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

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

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

            MemoryStream m = new MemoryStream();

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

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

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

                doc.Open();

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

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

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

                    cbCover.BeginText();

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

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

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

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

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

                    cbCover.EndText();

                    doc.NewPage();

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

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

                    cbBlank.BeginText();

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

                    cbBlank.EndText();

                    doc.NewPage();

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

                }

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

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

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

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

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

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

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

                    cbPage.BeginText();

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

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

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

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

                    }

                    cbPage.EndText();

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

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

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

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

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

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

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

                }

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

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #15
0
        public void RenderCanvasSheet(Stream stream, IEnumerable<CanvasItemModel> items, UserModel currentUser,UserModel requestedBy, PurchaseRequest Pr, string[] Vendors)
        {
            Document document = new Document(PageSize.LETTER);

            try {
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                document.Open();

                // Create a page in the document and add it to the bottom layer
                document.NewPage();
                //Pass Document to this
                CurrentDoc = document;

                page = writer.DirectContentUnder;
                page.BeginText();
                int top = (int)document.GetTop(0);
                SetFontSizeTo(16);
                PrintText("CANVASS SHEET", 20, 10);
                SetFontSizeTo(10);

                //Header
                PrintText("Company Name: " + requestedBy.CompanyName, 20, 30); // Company Name
                PrintText("Department: " + requestedBy.DepartmentName, 20, 45); // Company Address
                PrintText("Purpose: " + Pr.Purpose, 20, 60); // Purpose
                PrintTextRight("Date: {0}".WithTokens(DateTime.Now.ToShortDateString()), 70, 30); // Date Created
                PrintTextRight("PR No: {0}".WithTokens(Pr.PRNo), 70, 45); // PR Number

                SetFontSizeTo(8);

                // START HERE ----------------------------
                Paragraph Grid = new Paragraph("\n");
                Grid.Alignment = 1;
                Grid.SpacingAfter = 10f;
                document.Add(Grid);

                Paragraph Grid2 = new Paragraph();
                Grid2.Alignment = 1;
                Grid2.SpacingBefore = 35f;
                //Start Table -----------------------------------
                PdfPTable rightTable = new PdfPTable(7);
                int[] widths = { 1, 7, 2, 2, 2, 2, 2 };
                rightTable.SetWidths(widths);
                rightTable.TotalWidth = 570f;
                rightTable.LockedWidth = true;
                Font tableFont = new Font(Font.FontFamily.HELVETICA, 8);

                PdfPCell rightAlignedCell = new PdfPCell();
                rightAlignedCell.HorizontalAlignment = Element.ALIGN_CENTER;

                //Headers
                rightAlignedCell.Phrase = new Phrase("Item No.", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("Item Description", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("Quantity", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("UOM", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[0], tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[1], tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[2], tableFont); rightTable.AddCell(rightAlignedCell);

                rightAlignedCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                foreach (var item in items) {
                    string priceVendor1 = item.PriceVendor1 == 0 ? "NONE" : item.PriceVendor1.ToString();
                    string priceVendor2 = item.PriceVendor2 == 0 ? "NONE" : item.PriceVendor2.ToString();
                    string priceVendor3 = item.PriceVendor3 == 0 ? "NONE" : item.PriceVendor3.ToString();
                    rightTable.AddCell(new Phrase(item.ItemNumber.ToString(), tableFont));
                    rightTable.AddCell(new Phrase(item.ItemDescription, tableFont));
                    rightAlignedCell.Phrase = new Phrase(item.Quantity.ToString(), tableFont); rightTable.AddCell(rightAlignedCell);
                    rightTable.AddCell(new Phrase(item.UOM, tableFont));
                    rightAlignedCell.Phrase = new Phrase(priceVendor1, tableFont); rightTable.AddCell(rightAlignedCell);
                    rightAlignedCell.Phrase = new Phrase(priceVendor2, tableFont); rightTable.AddCell(rightAlignedCell);
                    rightAlignedCell.Phrase = new Phrase(priceVendor3, tableFont); rightTable.AddCell(rightAlignedCell);
                }
                Grid2.Add(rightTable);
                document.Add(Grid2);

                // Footer
                SetFontSizeTo(10);
                PrintTextBottom("Requested By:", 20, 105);
                PrintTextBottom("{0} {1}".WithTokens(requestedBy.FirstName, requestedBy.LastName), 20, 35);

                PrintTextBottom("Prepared By:", 265, 105);
                PrintTextBottom("{0} {1}".WithTokens(currentUser.FirstName, currentUser.LastName), 265, 35);

                PrintTextBottom("Approved By:", 450, 105);
                PrintTextBottom("{0}".WithTokens("______________________"), 450, 35);

                page.EndText();

                writer.Flush();
            }
            finally {
                document.Close();
            }
        }
Exemple #16
0
 public bool Open(PdfContentByte cb, float fontSize, float xtlm, float ytlm)
 {
     if (!_isPrevEmDash)
     {
         var padding = fontSize * _emDashPaddingRatio;
         cb.EndText();
         cb.SetLineWidth(_lineWidth);
         cb.MoveTo(xtlm, ytlm - padding);
         _isPrevEmDash = true;
         return true;
     }
     else
     {
         return false;
     }
 }
Exemple #17
0
  private bool CreateLayerInLegend(PdfContentByte content, Configuration.MapTabRow mapTab, List<CommonLayer> layerList, LegendProperties properties, CommonLayer layer, float indent)
  {
    if (!layerList.Contains(layer))
    {
      return false;
    }

    float layerHeight = GetLayerHeightInLegend(layerList, properties, layer);

    if (properties.CurrentY < properties.Height && properties.CurrentY - layerHeight < 0)
    {
      if (properties.CurrentColumn == properties.NumColumns)
      {
        return true;
      }

      properties.CurrentX += properties.ColumnWidth + properties.ColumnSpacing;
      properties.CurrentY = properties.Height;
      properties.CurrentColumn += 1;
    }

    int numClasses = GetNumClasses(layer);

    Configuration.LayerRow configLayer = mapTab.GetMapTabLayerRows().Where(o => String.Compare(o.LayerRow.LayerName, layer.Name, true) == 0).Select(o => o.LayerRow).FirstOrDefault();
    string layerName = configLayer != null && !configLayer.IsDisplayNameNull() ? configLayer.DisplayName : layer.Name;

    // write the layer name

    if (layer.Type == CommonLayerType.Group || numClasses > 1)
    {
      properties.CurrentY -= properties.FontSize;
      string name = layerName;

      try
      {
        while (content.GetEffectiveStringWidth(name, false) > properties.ColumnWidth - indent)
        {
          name = name.Substring(0, name.Length - 1);
        }
      }
      catch { }

      content.BeginText();
      content.SetFontAndSize(properties.BaseFont, properties.FontSize);
      content.SetRGBColorFill(0, 0, 0);
      content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, name, properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
      content.EndText();
    }

    if (layer.Type == CommonLayerType.Group)
    {
      properties.CurrentY -= properties.LayerSpacing;

      foreach (CommonLayer childLayer in layer.Children)
      {
        CreateLayerInLegend(content, mapTab, layerList, properties, childLayer, indent + 1.5f * properties.FontSize);
      }
    }
    else
    {
      properties.CurrentY -= properties.ClassSpacing;

      foreach (CommonLegendGroup legendGroup in layer.Legend.Groups)
      {
        foreach (CommonLegendClass legendClass in legendGroup.Classes)
        {
          if (!legendClass.ImageIsTransparent)
          {
            properties.CurrentY -= properties.SwatchHeight;

            MemoryStream stream = new MemoryStream(legendClass.Image);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
            float w = properties.SwatchHeight * bitmap.Width / bitmap.Height;

            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(legendClass.Image);
            image.SetAbsolutePosition(properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY - properties.SwatchHeight * 0.1f);
            image.ScaleAbsolute(w, properties.SwatchHeight);
            content.AddImage(image);

            string label = numClasses > 1 ? legendClass.Label : layerName;

            try
            {
              while (content.GetEffectiveStringWidth(label, false) > properties.ColumnWidth - properties.SwatchWidth - properties.ClassSpacing)
              {
                label = label.Substring(0, label.Length - 1);
              }
            }
            catch { }

            content.BeginText();
            content.SetFontAndSize(properties.BaseFont, properties.FontSize);
            content.SetRGBColorFill(0, 0, 0);
            content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, label, properties.OriginX + properties.CurrentX + indent + properties.SwatchWidth + properties.ClassSpacing, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
            content.EndText();

            properties.CurrentY -= properties.ClassSpacing;
          }
        }
      }

      properties.CurrentY -= properties.LayerSpacing - properties.ClassSpacing;
    }

    return false;
  }
Exemple #18
0
        public void RenderRfq(Stream stream, VendorModel vendor, IEnumerable<ItemModel> items, UserModel user, int RfqNumber, PurchaseRequest Pr, DateTime DateRequested)
        {
            Document document = new Document(PageSize.LETTER);

            try {
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                document.Open();

                // Create a page in the document and add it to the bottom layer
                document.NewPage();
                //Pass Document to this
                CurrentDoc = document;

                page = writer.DirectContentUnder;
                page.BeginText();
                int top = (int)document.GetTop(0);
                SetFontSizeTo(16);
                PrintText("REQUEST FOR QUOTATION (THIS IS NOT AN ORDER)", 20, 10);
                SetFontSizeTo(10);

                //Header
                PrintText("Company Name: {0}".WithTokens(Pr.User.Company.Name), 20, 30); // Company Name
                PrintText("Address: 8th Floor Gedisco Tower, 534 Asuncion St., Binondo, Manila", 20, 45); // Company Address
                PrintText("Purchasing Department", 20, 60);
                PrintText("Issued By: {0} {1}".WithTokens(user.FirstName, user.LastName), 20, 75); // Requested By
                PrintTextRight("RFQ NO: {0}".WithTokens(RfqNumber), 70, 30); // RFQ Number
                PrintTextRight("Date: {0}".WithTokens(DateTime.Now.ToShortDateString()), 70, 45); // Date Created
                PrintTextRight("PR No: {0}".WithTokens(Pr.PRNo), 70, 60); // PR Number

                //Body
                SetFontSizeTo(14);
                PrintText("BID/OFFER/QUOTE MUST BE RECEIVED BY:", 20, 105); // Requested By
                PrintTextRight("Date: {0}".WithTokens(DateRequested.ToShortDateString()), 95, 105); // Date Required
                SetFontSizeTo(10);
                PrintText("Attention: {0} {1}".WithTokens(user.FirstName, user.LastName), 40, 125); // Vendor Contact Person
                PrintText("Tel No: {0}".WithTokens("+63 2 244 9296"), 40, 140); // Vendor Tel No
                PrintText("Email Address: {0}".WithTokens(user.Email), 40, 155); // Vendor Email
                PrintText("Fax No: {0}".WithTokens("+63 2 241 7826"), 240, 125); // Vendor Fax No
                SetFontSizeTo(8);
                PrintText("Unless otherwise requested, quote on each item separately. Unit Prices shall be shown. If unable to furnish", 20, 175); // Vendor Email
                PrintText("items as specified, submit sample and/or descriptive specifications of substitute offered.", 20, 185); // Vendor Email

                //Items
                SetFontSizeTo(8);
                PrintText("_______________________________________________________________________________________________________________________", 20, 210);
                PrintText("Item No.", 20, 205);
                PrintText("Item Description", 70, 205);
                PrintText("Quantity", 370, 205);
                PrintText("Unit Price", 420, 205);
                PrintText("Discount", 470, 205);
                PrintText("Total", 520, 205);

                //// Items..
                //int staryY = 225;
                //int itemCount = 1;
                //foreach (var item in items) {
                //    PrintItem(itemCount.ToString(), item.Description, item.Quantity.ToString(), ref staryY);
                //    itemCount++;
                //}
                //PrintText("********** NOTHING FOLLOWS **********", 75, staryY + 15);

                // START HERE ----------------------------
                Paragraph Grid = new Paragraph("\n\n\n\n\n\n\n\n\n");
                Grid.Alignment = 1;
                Grid.SpacingAfter = 35f;
                document.Add(Grid);

                Paragraph Grid2 = new Paragraph();
                Grid2.Alignment = 1;
                Grid2.SpacingBefore = 35f;
                //Start Table -----------------------------------
                PdfPTable rightTable = new PdfPTable(7);
                int[] widths = { 1, 1, 1, 7, 2, 2, 2 };
                rightTable.SetWidths(widths);
                rightTable.TotalWidth = 570f;
                rightTable.LockedWidth = true;
                Font tableFont = new Font(Font.FontFamily.HELVETICA, 8);

                rightTable.HorizontalAlignment = Element.ALIGN_CENTER;

                rightTable.AddCell(new Phrase("Item No.", tableFont));
                rightTable.AddCell(new Phrase("Item Description", tableFont));
                rightTable.AddCell(new Phrase("Quantity", tableFont));
                rightTable.AddCell(new Phrase("Unit Price", tableFont));
                rightTable.AddCell(new Phrase("Discount", tableFont));
                rightTable.AddCell(new Phrase("Total Amount", tableFont));

                rightTable.HorizontalAlignment = Element.ALIGN_LEFT;

                int itemCount = 1;
                foreach (var item in items) {
                    rightTable.AddCell(new Phrase(item.ItemNumber.ToString(), tableFont));
                    rightTable.AddCell(new Phrase(item.Description, tableFont));
                    rightTable.AddCell(new Phrase(item.Quantity.ToString(), tableFont));
                    rightTable.AddCell(new Phrase("", tableFont));
                    rightTable.AddCell(new Phrase("", tableFont));
                    rightTable.AddCell(new Phrase("", tableFont));
                    itemCount++;
                }
                //Nothing Follows
                rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("******** NOTHING FOLLOWS ********", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase(""));

                Grid2.Add(rightTable);
                document.Add(Grid2);
                // End of table -----------------------------------

                // Footer
                SetFontSizeTo(10);
                PrintTextBottom("If accepted within _____ days, the undersigned offers and agrees to honor this quotation.", 20, 85);
                PrintTextBottom("Print Name of Person:", 20, 65);
                PrintTextBottom("Company Name:", 20, 50);
                PrintTextBottom("Address:", 20, 35);
                PrintTextBottom("Email Address:", 20, 20);

                PrintTextBottom("No. of Days to Deliver:", 200, 65);
                PrintTextBottom("Telephone No.:", 200, 50);
                PrintTextBottom("Fax No.:", 200, 35);

                page.EndText();

                writer.Flush();
            }
            finally {
                document.Close();
            }
        }
Exemple #19
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();
        }
Exemple #20
0
        /// <summary>
        /// 处理单个页面。
        /// </summary>
        /// <param name="pgs"></param>
        /// <param name="items"></param>
        private void ProcessPage(Pages pgs, IEnumerable items)
        {
            foreach (PageItem pi in items)
            {
                //if (pi.SI.BackgroundImage != null)
                //{
                //    PageImage bgImg = pi.SI.BackgroundImage;
                //    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bgImg.ImageData);
                //    document.Add(image);
                //}

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

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

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

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

                    //边线

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

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

                        cb.Stroke();
                    }

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

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

                        cb.Stroke();
                    }

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

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

                        cb.Stroke();
                    }

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

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

                        cb.Stroke();
                    }

                    //绝对定义文字

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

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

                    int rows = sa.Length;

                    //x标准固定

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

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

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

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

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

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

                    continue;
                }

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

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

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

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

                    cb.Stroke();

                    continue;
                }

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

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

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

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

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

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

                    cb.AddImage(image);

                    cb.Stroke();

                    continue;
                }

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

                    iTextSharp.text.Rectangle r2 = new iTextSharp.text.Rectangle(pr.X, pr.Y, pr.W, pr.H);
                    r2.Border = 1;
                    document.Add(r2);
                    continue;
                }
            }
        }
Exemple #21
0
// ---------------------------------------------------------------------------            
    /**
     * Draws some text on every calendar sheet.
     * 
     */
    protected void DrawDateInfo(string day, int d, PdfContentByte directcontent) {
      directcontent.BeginText();
      directcontent.SetFontAndSize(bf, 18);
      float x, y;
      x = OFFSET_LOCATION;
      y = OFFSET_BOTTOM + HEIGHT + 24;
      directcontent.ShowTextAligned(
        Element.ALIGN_LEFT,
        "Day " + d, x, y, 0
      );
      x = OFFSET_LEFT + WIDTH;
      directcontent.ShowTextAligned(
        Element.ALIGN_RIGHT,
        day, x, y, 0
      );
      directcontent.EndText();
    }
 private void RenderTextElement(TextElement el, PdfContentByte dc)
 {
     var color = new BaseColor(el.FontColor);
     var font = el.FontBold ? fontBold : this.font;
     dc.SetColorFill(color);
     dc.SetFontAndSize(font, el.FontSize);
     dc.BeginText();
     dc.ShowTextAligned(PdfContentByte.ALIGN_LEFT, el.Text, TranslateLeft(el), TranslateTop(el), 0);
     dc.EndText();
     //var ct = new ColumnText(dc);
     //var p = new Phrase(new Chunk(el.Text, new iTextSharp.text.Font(font, el.FontSize)));
     //ct.SetSimpleColumn(p,
     //    TranslateLeft(el),
     //    TranslateTop(el) - el.Height,
     //    TranslateLeft(el) + el.Width,
     //    TranslateTop(el),
     //    0,
     //    iTextSharp.text.Element.ALIGN_LEFT | iTextSharp.text.Element.ALIGN_TOP);
     //ct.Go();
 }
Exemple #23
0
        static void setText(PdfContentByte cb,EditText[] edTxt)
        {
            cb.BeginText ();
            cb.ShowTextAligned (0,edTxt[0].Text, 42, 477, 0);
            cb.ShowTextAligned (0, edTxt[1].Text, 42, 463, 0);
            cb.ShowTextAligned (0, edTxt[2].Text, 42, 448, 0);
            cb.ShowTextAligned (0, edTxt[3].Text, 42, 434, 0);
            cb.ShowTextAligned (0, edTxt[4].Text, 42, 419, 0);
            cb.ShowTextAligned (0, edTxt[5].Text, 42, 405, 0);
            cb.ShowTextAligned (0, edTxt[6].Text, 42, 390, 0);
            cb.ShowTextAligned (0, edTxt[7].Text, 42, 376, 0);
            cb.ShowTextAligned (0, edTxt[8].Text, 42, 323, 0);
            cb.ShowTextAligned (0, edTxt[9].Text, 42, 309, 0);
            cb.ShowTextAligned (0, edTxt[10].Text, 42, 295, 0);
            cb.ShowTextAligned (0, edTxt[11].Text, 115, 323, 0);
            cb.ShowTextAligned (0, edTxt[12].Text, 115, 309, 0);
            cb.ShowTextAligned (0, edTxt[13].Text, 115, 295, 0);
            cb.ShowTextAligned (0, edTxt[14].Text, 217, 323, 0);
            cb.ShowTextAligned (0, edTxt[15].Text, 217, 309, 0);
            cb.ShowTextAligned (0, edTxt[16].Text, 217, 295, 0);
            cb.ShowTextAligned (0, edTxt[17].Text, 242, 323, 0);
            cb.ShowTextAligned (0, edTxt[18].Text, 242, 309, 0);
            cb.ShowTextAligned (0, edTxt[19].Text, 242, 295, 0);
            cb.ShowTextAligned (0, edTxt[20].Text, 265, 323, 0);
            cb.ShowTextAligned (0, edTxt[21].Text, 265, 309, 0);
            cb.ShowTextAligned (0, edTxt[22].Text, 265, 295, 0);
            cb.ShowTextAligned (0, edTxt[23].Text, 137, 267, 0);
            cb.ShowTextAligned (0, edTxt[24].Text, 137, 253, 0);
            cb.ShowTextAligned (0, edTxt[25].Text, 137, 238, 0);
            cb.ShowTextAligned (0, edTxt[26].Text, 137, 223, 0);
            cb.ShowTextAligned (0, edTxt[27].Text, 137, 209, 0);
            cb.ShowTextAligned (0, edTxt[28].Text, 137, 195, 0);
            cb.ShowTextAligned (0, edTxt[29].Text, 262, 267, 0);
            cb.ShowTextAligned (0, edTxt[30].Text, 262, 253, 0);
            cb.ShowTextAligned (0, edTxt[31].Text, 262, 238, 0);
            cb.ShowTextAligned (0, edTxt[32].Text, 262, 223, 0);
            cb.ShowTextAligned (0, edTxt[33].Text, 262, 209, 0);
            cb.ShowTextAligned (0, edTxt[34].Text, 262, 195, 0);
            cb.ShowTextAligned (0, edTxt[35].Text, 293, 323, 0);
            cb.ShowTextAligned (0, edTxt[36].Text, 293, 309, 0);
            cb.ShowTextAligned (0, edTxt[37].Text, 293, 295, 0);
            cb.ShowTextAligned (0, edTxt[38].Text, 293, 281, 0);
            cb.ShowTextAligned (0, edTxt[39].Text, 293, 267, 0);
            cb.ShowTextAligned (0, edTxt[40].Text, 293, 253, 0);
            cb.ShowTextAligned (0, edTxt[41].Text, 293, 238, 0);
            cb.ShowTextAligned (0, edTxt[42].Text, 293, 223, 0);
            cb.ShowTextAligned (0, edTxt[43].Text, 293, 209, 0);
            cb.ShowTextAligned (0, edTxt[44].Text, 293, 195, 0);
            cb.ShowTextAligned (0, edTxt[45].Text, 499, 323, 0);
            cb.ShowTextAligned (0, edTxt[46].Text, 499, 309, 0);
            cb.ShowTextAligned (0, edTxt[47].Text, 499, 295, 0);
            cb.ShowTextAligned (0, edTxt[48].Text, 499, 281, 0);
            cb.ShowTextAligned (0, edTxt[49].Text, 499, 267, 0);
            cb.ShowTextAligned (0, edTxt[50].Text, 499, 253, 0);
            cb.ShowTextAligned (0, edTxt[51].Text, 499, 238, 0);
            cb.ShowTextAligned (0, edTxt[52].Text, 499, 223, 0);
            cb.ShowTextAligned (0, edTxt[53].Text, 499, 209, 0);
            cb.ShowTextAligned (0, edTxt[54].Text, 499, 195, 0);
            cb.ShowTextAligned (0, edTxt[55].Text, 550, 323, 0);
            cb.ShowTextAligned (0, edTxt[56].Text, 550, 309, 0);
            cb.ShowTextAligned (0, edTxt[57].Text, 550, 295, 0);
            cb.ShowTextAligned (0, edTxt[58].Text, 550, 281, 0);
            cb.ShowTextAligned (0, edTxt[59].Text, 550, 267, 0);
            cb.ShowTextAligned (0, edTxt[60].Text, 550, 253, 0);
            cb.ShowTextAligned (0, edTxt[61].Text, 550, 238, 0);
            cb.ShowTextAligned (0, edTxt[62].Text, 550, 223, 0);
            cb.ShowTextAligned (0, edTxt[63].Text, 550, 209, 0);
            cb.ShowTextAligned (0, edTxt[64].Text, 550, 195, 0);

            cb.EndText ();
        }
Exemple #24
0
        protected internal override void Render(PdfContentByte cb, Vector2D offset)
        {
            offset.Y += Size.Y + Offset.Y - Baseline;

            cb.BeginText();
            cb.SetColorFill(new iTextSharp.text.Color(color));
            cb.SetFontAndSize(font.iTextSharpFont.BaseFont, font.Size);
            foreach (var s in text.Split('\n'))
            {
                cb.ShowTextAligned(textAlignment(alignment), s, (float)offset.X.Value(UnitsOfMeasure.Points), (float)offset.Y.Value(UnitsOfMeasure.Points), 0);
                offset.Y -= font.Height;
            }
            cb.EndText();
        }
Exemple #25
0
 static void setCheckBoxes(PdfContentByte cb, CheckBox[] chBoxes)
 {
     cb.BeginText ();
     if (chBoxes [0].Checked)
     {
         cb.ShowTextAligned (0, "x", 156, 494, 0);
     };
     if (chBoxes [1].Checked)
     {
         cb.ShowTextAligned (0, "x", 262, 494, 0);
     };
     if (chBoxes [2].Checked)
     {
         cb.ShowTextAligned (0, "x", 368, 494, 0);
     };
     if (chBoxes [3].Checked)
     {
         cb.ShowTextAligned (0, "x", 474, 494, 0);
     };
     if (chBoxes [4].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 478, 0);
     };
     if (chBoxes [5].Checked)
     {
         cb.ShowTextAligned (0, "x", 517, 478, 0);
     };
     if (chBoxes [6].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 464, 0);
     };
     if (chBoxes [7].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 450, 0);
     };
     if (chBoxes [8].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 435, 0);
     };
     if (chBoxes [9].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 421, 0);
     };
     if (chBoxes [10].Checked)
     {
         cb.ShowTextAligned (0, "x", 456, 406, 0);
     };
     if (chBoxes [11].Checked)
     {
         cb.ShowTextAligned (0, "x", 467, 392, 0);
     };
     if (chBoxes [12].Checked)
     {
         cb.ShowTextAligned (0, "x", 467, 377, 0);
     };
     if (chBoxes [13].Checked)
     {
         cb.ShowTextAligned (0, "x", 142, 363, 0);
     };
     if (chBoxes [14].Checked)
     {
         cb.ShowTextAligned (0, "x", 207, 363, 0);
     };
     if (chBoxes [15].Checked)
     {
         cb.ShowTextAligned (0, "x", 286, 363, 0);
     };
     if (chBoxes [16].Checked)
     {
         cb.ShowTextAligned (0, "x", 365, 363, 0);
     };
     if (chBoxes [17].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 267, 0);
     };
     if (chBoxes [18].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 253, 0);
     };
     if (chBoxes [19].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 239, 0);
     };
     if (chBoxes [20].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 224, 0);
     };
     if (chBoxes [21].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 209, 0);
     };
     if (chBoxes [22].Checked)
     {
         cb.ShowTextAligned (0, "x", 42, 196, 0);
     };
     if (chBoxes [23].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 267, 0);
     };
     if (chBoxes [24].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 253, 0);
     };
     if (chBoxes [25].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 239, 0);
     };
     if (chBoxes [26].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 223, 0);
     };
     if (chBoxes [27].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 209, 0);
     };
     if (chBoxes [28].Checked)
     {
         cb.ShowTextAligned (0, "x", 168, 196, 0);
     };
     cb.EndText();
 }
 /** 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;
 }
Exemple #27
0
        public void RenderPurchaseOrder(Stream stream, int PoNumber, IEnumerable<PoItemModel> PoItems, int RequestNumber, string VendorName, string VendorCode, string VendorAddress, DateTime DateCreated, DateTime DeliveryDate, UserModel RequestUser, UserModel CurrentUser)
        {
            Document document = new Document(PageSize.LETTER);

            try {
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                document.Open();

                // Create a page in the document and add it to the bottom layer
                document.NewPage();
                //Pass Document to this
                CurrentDoc = document;

                string logoLocation = sonicLogo;
                float logoPosition = 50;

                string CurrentCompany = RequestUser.CompanyName;
                //Image
                if (RequestUser.CompanyId == (int)CompanyIds.SonicSteel) {
                    logoLocation = sonicLogo;
                    logoPosition = 70;
                }
                else if (RequestUser.CompanyId == (int)CompanyIds.SteelTech) {
                    logoLocation = steeltechLogo;
                }
                else if (RequestUser.CompanyId == (int)CompanyIds.Somico) {
                    logoLocation = somicoLogo;
                }
                Image logo = Image.GetInstance(Directory.GetCurrentDirectory() + logoLocation);
                logo.SetAbsolutePosition(20, (int)CurrentDoc.GetTop(logoPosition));

                // START HERE ----------------------------
                Paragraph Grid = new Paragraph("\n\n\n\n\n\n\n\n\n");
                Grid.Alignment = 1;
                Grid.SpacingAfter = 35f;
                document.Add(Grid);

                Paragraph Grid2 = new Paragraph();
                Grid2.Alignment = 1;
                Grid2.SpacingBefore = 35f;
                //Start Table -----------------------------------
                PdfPTable rightTable = new PdfPTable(7);
                int[] widths = { 1, 1, 1, 7, 2, 2, 2 };
                rightTable.SetWidths(widths);
                rightTable.TotalWidth = 570f;
                rightTable.LockedWidth = true;
                Font tableFont = new Font(Font.FontFamily.HELVETICA, 8);

                rightTable.HorizontalAlignment = Element.ALIGN_CENTER;

                rightTable.AddCell(new Phrase("Item No.", tableFont));
                rightTable.AddCell(new Phrase("Quantity", tableFont));
                rightTable.AddCell(new Phrase("UOM", tableFont));
                rightTable.AddCell(new Phrase("Item Description", tableFont));
                rightTable.AddCell(new Phrase("Unit Price", tableFont));
                rightTable.AddCell(new Phrase("Discount", tableFont));
                rightTable.AddCell(new Phrase("Total Amount", tableFont));

                rightTable.HorizontalAlignment = Element.ALIGN_LEFT;

                int itemCount = 1;
                foreach (var poItem in PoItems) {
                    rightTable.AddCell(new Phrase(itemCount.ToString(), tableFont)); rightTable.AddCell(new Phrase(poItem.Quantity.ToString(), tableFont)); rightTable.AddCell(new Phrase(poItem.UOM, tableFont)); rightTable.AddCell(new Phrase(poItem.Description, tableFont)); rightTable.AddCell(new Phrase(poItem.Price.ToString(), tableFont)); rightTable.AddCell(new Phrase(poItem.Discount.ToString(), tableFont)); rightTable.AddCell(new Phrase(poItem.TotalPrice.ToString(), tableFont));
                    itemCount++;
                }
                //Nothing Follows
                rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("******** NOTHING FOLLOWS ********", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase(""));

                //Grand Total
                rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("", tableFont)); rightTable.AddCell(new Phrase("")); rightTable.AddCell(new Phrase("Grand Total:", new Font(Font.FontFamily.HELVETICA, 12))); rightTable.AddCell(new Phrase(PoItems.Sum(x => x.TotalPrice).ToString(), new Font(Font.FontFamily.HELVETICA, 12)));

                Grid2.Add(rightTable);
                document.Add(Grid2);
                // End of table -----------------------------------
                page = writer.DirectContentUnder;

                page.AddImage(logo);
                page.Stroke();

                // For "Purchase Order" Text
                PrintRectangle(20, 120, 570, 50);
                //For two tables
                PrintRectangle(20, 230, 350, 100);
                PrintRectangle(370, 230, 220, 100);
                //For Footer
                PrintRectangleBottom(20, 20, 570, 50);

                page.BeginText();

                SetFontSizeTo(24);

                PrintText("PURCHASE ORDER", 180, 105);

                SetPOCompanyHeader(RequestUser);

                SetFontSizeTo(10);
                // Header
                PrintText("To:", 25, 140); // Vendor Name

                SetFontSizeTo(8);
                PrintText(VendorName, 40, 140); // Vendor Name
                SetFontSizeTo(7);
                PrintText(VendorAddress, 25, 155); // Vendor Address
                SetFontSizeTo(10);

                PrintText("Vendor Code: " + VendorCode, 25, 220); // Venodr Id

                PrintText("PO Number: " + PoNumber, 375, 140); // Vendor Name
                PrintText("PO Date: " + DateTime.Now.ToShortDateString(), 375, 160); // Date Now
                PrintText("PR Number: " + RequestNumber, 375, 180); // Request Number
                PrintText("Delivery Date: " + DeliveryDate.ToShortDateString(), 375, 220); // Delivery Date

                //Footer
                SetFontSizeTo(8);
                PrintTextBottom("Purchase Orders are not valid unless signed by the Authorized Signatories. " + CurrentCompany + " will not recognize claims ", 20, 130);
                PrintTextBottom("based on verbal orders. If delivery is not made by the date indicated in this Purchase Order, United Steel Technology International Corporation may cancel this ", 20, 115);
                PrintTextBottom("Purchase Order, without any liability whatsoever. Seller expressly warrants that all goods or services furnished under this agreement shall conform to all ", 20, 100);
                PrintTextBottom("specifications and appropriate standards, will be new and will be free from defects in material or workmanship.", 20, 85);

                PrintTextBottom("Prepared By:", 25, 55);
                PrintTextBottom(CurrentUser.FirstName + " " + CurrentUser.LastName, 25, 30);
                PrintTextBottom("Noted By:", 255, 55);
                PrintTextBottom("Approved By:", 450, 55);

                //PrintTextBottom("No. of Days to Deliver:", 200, 65);
                //PrintTextBottom("Telephone No.:", 200, 50);
                //PrintTextBottom("Fax No.:", 200, 35);
                page.EndText();

                writer.Flush();
            }
            finally {
                document.Close();
            }
        }
Exemple #28
0
        private static void AddItemData(Factuur factuur, Document document,
										int lastwriteposition, PdfContentByte content, ref int topMargin)
        {
            // Loop thru the rows in the rows table
            // Start by writing out the line headers
            // Line headers
            const int aantalMargin = 360, ehprijsMargin = 450, totaalMargin = 540;

            WriteText(content, "Omschrijving", 40, topMargin, 12, true);
            WriteText(content, "Aantal", aantalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);
            WriteText(content, "Prijs/EH", ehprijsMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);
            WriteText(content, "Bedrag", totaalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);

            topMargin -= 20;
            foreach (var item in factuur.Items)
            {
                var opmerkingBottom = topMargin;
                foreach (var s in item.Omschrijving.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                {
                    WriteText(content, s, 40, opmerkingBottom, 10);
                    opmerkingBottom -= 16;
                }

                WriteText(content, item.Aantal.ToString(), aantalMargin, topMargin, 10, false, PdfContentByte.ALIGN_RIGHT);
                WriteText(content, string.Format("{0:C}", Math.Round(item.EenheidsPrijs, 2)), ehprijsMargin, topMargin, 10, false,
                          PdfContentByte.ALIGN_RIGHT);
                WriteText(content, string.Format("{0:C}", item.TotaalPrijs), totaalMargin, topMargin, 10, false,
                          PdfContentByte.ALIGN_RIGHT);

                // This is the line spacing, if you change the font size, you might want to change this as well.
                topMargin = opmerkingBottom;

                // Implement a page break function, checking if the write position has reached the lastwriteposition
                if (topMargin > lastwriteposition) continue;
                // We need to end the writing before we change the page
                content.EndText();
                // Make the page break
                document.NewPage();
                // Start the writing again
                content.BeginText();
                topMargin = 780;
                WriteText(content, "Omschrijving", 40, topMargin, 12, true);
                WriteText(content, "Aantal", aantalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);
                WriteText(content, "Prijs/EH", ehprijsMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);
                WriteText(content, "Bedrag", totaalMargin, topMargin, 12, true, PdfContentByte.ALIGN_RIGHT);
                // Assign the new write location on page two!
                // Here you might want to implement a new header function for the new page
                topMargin -= 20;
            }
        }
Exemple #29
0
	private void CreatePdfText(PdfContentByte content, Configuration.PrintTemplateContentRow row, string text)
	{
		CreatePdfBox(content, row);

		float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
		float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
		float width = Convert.ToSingle(row.Width) * PointsPerInch;
		float height = Convert.ToSingle(row.Height) * PointsPerInch;

		string fontFamily = "Helvetica";
		int textAlign = PdfContentByte.ALIGN_CENTER;
		float fontSize = 12;
		int textStyle = iTextSharp.text.Font.NORMAL;
		bool textWrap = false;

		int columnAlign = Element.ALIGN_CENTER;

		if (!row.IsTextWrapNull())
		{
			textWrap = row.TextWrap == 1;
		}

		if (!row.IsFontFamilyNull())
		{
			fontFamily = row.FontFamily;
		}

		if (!row.IsFontBoldNull())
		{
			if (row.FontBold == 1)
			{
				if (textWrap)
				{
					textStyle = Font.BOLD;
				}
				else
				{
					fontFamily += "-Bold";
				}
			}
		}

		if (!row.IsFontSizeNull())
		{
			fontSize = Convert.ToSingle(row.FontSize);
		}

		BaseFont baseFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

		if (textWrap)
		{
			if (!row.IsTextAlignNull())
			{
				switch (row.TextAlign)
				{
					case "left":
						columnAlign = Element.ALIGN_LEFT;
						break;
					case "right":
						columnAlign = Element.ALIGN_RIGHT;
						break;
				}
			}

			Font font = new Font(baseFont, fontSize, textStyle);
			content.SetRGBColorFill(0, 0, 0);

			float leading = fontSize * 1.2f;

			ColumnText column = new ColumnText(content);
			column.SetSimpleColumn(originX, originY, originX + width, originY + height, leading, columnAlign);
			column.AddText(new Phrase(leading, text, font));
			column.Go();
		}
		else
		{
			originX += width / 2;

			if (!row.IsTextAlignNull())
			{
				switch (row.TextAlign)
				{
					case "left":
						textAlign = PdfContentByte.ALIGN_LEFT;
						originX -= width / 2;
						break;
					case "right":
						textAlign = PdfContentByte.ALIGN_RIGHT;
						originX += width / 2;
						break;
				}
			}

			content.BeginText();
			content.SetFontAndSize(baseFont, fontSize);
			content.SetRGBColorFill(0, 0, 0);
			content.ShowTextAligned(textAlign, text, originX, originY, 0);
			content.EndText();
		}
	}
        /**
        * 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;
        }
        void DrawBox(
            Document doc,
            PdfContentByte cb,
            Certificate c,
            CertificateArea box,
            string text,
            bool wrap)
        {
            if (null == box || !box.Enabled || String.IsNullOrEmpty(text))
            {
                return;
            }

            var origin = (float)box.Left;
            var alignment = PdfContentByte.ALIGN_LEFT;
            switch (box.Alignment)
            {
                case "center":
                    alignment = PdfContentByte.ALIGN_CENTER;
                    origin = (box.Left + box.Width/2);
                    break;
                case "right":
                    alignment = PdfContentByte.ALIGN_RIGHT;
                    origin = box.Left + box.Width;
                    break;
            }

            var size = 0 == box.FontSize ? 12f : box.FontSize;
            cb.SetFontAndSize(
                BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false),
                size);
            cb.BeginText();
            if (wrap)
            {
                var y = 0;
                var line = 0;
                for (var x = 0; x < text.Length; x++)
                {
                    var sub = text.Substring(y, x - y);
                    var width = cb.GetEffectiveStringWidth(sub, false);
                    if (width >= 10f * Dpi * box.Width / c.BackgroundSize.Width)
                    {
                        // backup to the last whitespace char
                        while (x > y && Char.IsLetterOrDigit(text[x]))
                        {
                            x--;
                        }
                        sub = text.Substring(y, x - y);
                        cb.ShowTextAligned(
                            alignment,
                            sub,
                            (0.5f*Dpi) + (10f*Dpi*origin/c.BackgroundSize.Width),
                            (0.5f*Dpi) + (7.5f*Dpi) - (7.5f*Dpi*box.Top/c.BackgroundSize.Height) - size - (line * size),
                            0f
                        );
                        y = x;
                        line++;
                    }
                }
            }
            else
            {
                cb.ShowTextAligned(
                    alignment,
                    text,
                    (0.5f * Dpi) + (10f * Dpi * origin / c.BackgroundSize.Width),
                    (0.5f * Dpi) + (7.5f * Dpi) - (7.5f * Dpi * box.Top / c.BackgroundSize.Height) - size,
                    0f
                );
            }
            cb.EndText();
        }
Exemple #32
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;
 }   
Exemple #33
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;
 }
        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();
        }