예제 #1
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            float  ury        = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float  lly        = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);
            string column_val = SummarizedValue.ToString();

            ResetSummary();
            Phrase     phrase = GetFormattedPhrase(this.Font, Rep.Font, column_val);
            ColumnText ct     = new ColumnText(Rep.Canvas);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
예제 #2
0
        internal void TextRightWithBorder(string total, string forRoom, string daily, string rooms)
        {
            var font = BaseFont.HELVETICA_BOLD;

            var columnText = new ColumnText(_contentByte)
            {
                Alignment           = Element.ALIGN_RIGHT,
                AdjustFirstLine     = false,
                SpaceCharRatio      = 1,
                Leading             = 9,
                ExtraParagraphSpace = 0
            };

            var llx = _doc.PageSize.Width * 0.75f;
            var lly = Position;
            var urx = _doc.PageSize.Width - (_doc.Left * 2);
            var ury = Position + 60;

            columnText.SetIndent(0, true);

            columnText.AddText(new Phrase(total + "\n", new Font(GetFont(font), 10)));
            columnText.AddText(new Phrase(forRoom + "\n", new Font(GetFont(font), 8)));
            columnText.AddText(new Phrase(daily + "\n", new Font(GetFont(font), 8)));
            columnText.AddText(new Phrase(rooms + "\n", new Font(GetFont(font), 8)));

            var adjustX = 20f;
            var adjustY = 10f;

            columnText.SetSimpleColumn(llx - adjustX, lly - adjustY, urx - adjustX, ury - adjustY);
            columnText.Go();
            Rectangle(llx, lly, urx - llx, ury - lly, 0.3f, 0, BaseColor.GRAY);
            SetAtualPosition(lly);
        }
예제 #3
0
 /** Constructs a <CODE>PdfPCell</CODE> with a <CODE>Phrase</CODE>.
  * The default padding is 2.
  * @param phrase the text
  */
 public PdfPCell(Phrase phrase) : base(0, 0, 0, 0)
 {
     borderWidth = 0.5f;
     border      = BOX;
     column.AddText(this.phrase = phrase);
     column.SetLeading(0, 1);
 }
예제 #4
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            ColumnText ct         = new ColumnText(Rep.Canvas);
            string     column_val = Rep.GetDataFieldValue(ColumnName, slno, TableIndex);

            if (Prefix != "" || Suffix != "")
            {
                column_val = Prefix + " " + column_val + " " + Suffix;
            }

            Phrase phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            float ury = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float lly = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);

            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
예제 #5
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            float  ury        = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float  lly        = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);
            string column_val = SummarizedValue.ToString();

            ResetSummary();

            if (SuppressIfZero && !(Convert.ToDecimal(column_val) > 0))
            {
                column_val = string.Empty;
            }
            else
            {
                column_val = FormatDecimals(column_val, AmountInWords, DecimalPlaces, Rep.CultureInfo?.NumberFormat, FormatUsingCulture);
            }

            if (Rep.SummaryValInRow.ContainsKey(Title))
            {
                Rep.SummaryValInRow[Title] = new PdfNTV {
                    Name = Title.Replace(".", "_"), Type = PdfEbDbTypes.Int32, Value = column_val
                }
            }
            ;
            else
            {
                Rep.SummaryValInRow.Add(Title, new PdfNTV {
                    Name = Title.Replace(".", "_"), Type = PdfEbDbTypes.Int32, Value = column_val
                });
            }
            Phrase     phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);
            ColumnText ct     = new ColumnText(Rep.Canvas);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
예제 #6
0
        public void CreateTaggedPdf21()
        {
            try {
                InitializeDocument("21");

                PdfTemplate template = writer.DirectContent.CreateTemplate(PageSize.A4.Width, PageSize.A4.Height);

                writer.DirectContent.AddTemplate(template, 0, 0, true);

                ColumnText columnText = new ColumnText(template);
                columnText.SetSimpleColumn(36, 36, 250, 750);
                columnText.AddText(new Phrase("Hello word \n\n"));
                columnText.Go();

                document.NewPage();
                writer.DirectContent.AddTemplate(template, 0, 0);

                document.Close();
            }
            catch (Exception conformExc) {
                Assert.AreEqual("Template with tagged content could not be used more than once.", conformExc.Message);
                return;
            }
            finally {
                document.Close();
            }
            Assert.Fail("Expected error: 'Template with tagged content could not be used more than once.");
        }
예제 #7
0
        private void Column(List <string> list, float llx)
        {
            var columnText = new ColumnText(_contentByte)
            {
                Alignment           = Element.ALIGN_LEFT,
                AdjustFirstLine     = false,
                SpaceCharRatio      = 1,
                Leading             = 9,
                ExtraParagraphSpace = 0
            };

            var lly = Position - (list.Count * 8);
            var urx = llx + (_doc.PageSize.Width / 4);
            var ury = Position;

            columnText.SetIndent(0, true);

            list.ForEach(x =>
            {
                columnText.AddText(new Phrase(x + "\n", new Font(GetFont(BaseFont.HELVETICA), 8)));
            });

            columnText.SetSimpleColumn(llx, lly, urx, ury + 10);

            columnText.Go();
        }
예제 #8
0
        // ===========================================================================
        public virtual void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                ColumnText          ct     = new ColumnText(writer.DirectContent);
                foreach (Movie movie in movies)
                {
                    ct.AddText(CreateMovieInformation(movie));
                    ct.AddText(Chunk.NEWLINE);
                }
                ct.Alignment           = Element.ALIGN_JUSTIFIED;
                ct.ExtraParagraphSpace = 6;
                ct.SetLeading(0, 1.2f);
                ct.FollowingIndent = 27;
                int linesWritten = 0;
                int column       = 0;
                // iText-ONLY, 'Initial value of the status' => 0
                // iTextSharp **DOES NOT** include this member variable
                // int status = ColumnText.START_COLUMN;
                int status = 0;
                while (ColumnText.HasMoreText(status))
                {
                    ct.SetSimpleColumn(
                        COLUMNS[column][0], COLUMNS[column][1],
                        COLUMNS[column][2], COLUMNS[column][3]
                        );
                    ct.YLine      = COLUMNS[column][3];
                    status        = ct.Go();
                    linesWritten += ct.LinesWritten;
                    column        = Math.Abs(column - 1);
                    if (column == 0)
                    {
                        document.NewPage();
                    }
                }

                ct.AddText(new Phrase("Lines written: " + linesWritten));
                ct.Go();
            }
        }
예제 #9
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            iTextSharp.text.Font font = null;

            if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point)
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           this.StyleDecorator.Font.Size,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
            else
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }

            base.Decorate();

            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator, font);

            ColumnText columnText = new ColumnText(contentByte);

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Top - r.Height, pdfFormat.Leading, pdfFormat.Alignment);

            string formatedText = this.text;

            if (!String.IsNullOrEmpty(StyleDecorator.FormatString))
            {
                formatedText = StandardFormatter.FormatOutput(this.text, this.StyleDecorator.FormatString,
                                                              this.StyleDecorator.DataType, String.Empty);
            }

            Chunk chunk = new Chunk(formatedText, font);

            columnText.AddText(chunk);

            columnText.Go();
        }
예제 #10
0
 private void CreateStamp(string stampString)
 {
     if (!String.IsNullOrEmpty(stampString))
     {
         ColumnText ct = new ColumnText(_writerContent.DirectContent);
         ct.SetSimpleColumn(_docContent.Left, _docContent.Top + _docContent.TopMargin - 20, _docContent.Right, _docContent.Top + _docContent.TopMargin - 10, 0f, Element.ALIGN_CENTER);
         ct.AddText(new Phrase(stampString, fontStamp));
         ct.Go();
     }
 }
예제 #11
0
        public void AddParagraph(string text, ColumnText column, Font font)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var para = new Paragraph(text, font);

            column.AddText(para);
            column.Go();
        }
예제 #12
0
        public void AddParagraph(string text, ColumnText column)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var para = new Paragraph(text, GetRegularFont(false));

            column.AddText(para);
            column.Go();
        }
예제 #13
0
    public override void OnEndPage(PdfWriter writer, Document document)
    {
        //Create a simple ColumnText object
        var CT = new ColumnText(writer.DirectContent);

        //Bind it to the top of the document but take up the entire page width
        CT.SetSimpleColumn(0, document.PageSize.Height - 20, document.PageSize.Width, document.PageSize.Height);
        //Add some text
        CT.AddText(new Phrase("This is a test"));
        //Draw our ColumnText object
        CT.Go();
    }
예제 #14
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte canvas = writer.DirectContent;
         DrawRectangles(canvas);
         ColumnText ct = new ColumnText(canvas);
         ct.Alignment = Element.ALIGN_JUSTIFIED;
         ct.Leading   = 14;
         int column = 0;
         ct.SetColumns(
             new float[] { 36, 806, 36, 670, 108, 670, 108, 596, 36, 596, 36, 36 },
             new float[] { 296, 806, 296, 484, 259, 484, 259, 410, 296, 410, 296, 36 }
             );
         ct.SetColumns(LEFT[column], RIGHT[column]);
         // ct.SetColumns(LEFT[column], RIGHT[column]);
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                     DrawRectangles(canvas);
                 }
                 ct.SetColumns(LEFT[column], RIGHT[column]);
                 y = 806;
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go();
         }
     }
 }
예제 #15
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            ColumnText ct         = new ColumnText(Rep.Canvas);
            string     column_val = Rep.GetDataFieldValue(ColumnName, slno, TableIndex);
            float      ury        = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float      lly        = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);

            if (SuppressIfZero && !(Convert.ToDecimal(column_val) > 0))
            {
                column_val = String.Empty;
            }
            else
            {
                column_val = FormatDecimals(column_val, AmountInWords, DecimalPlaces, Rep.CultureInfo?.NumberFormat, FormatUsingCulture);
                if (Prefix != "" || Suffix != "")
                {
                    column_val = Prefix + " " + column_val + " " + Suffix;
                }
            }
            Phrase phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            ct.Canvas.SetColorFill(GetColor(ForeColor));
            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
예제 #16
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         ColumnText ct = new ColumnText(writer.DirectContent)
         {
             Alignment           = Element.ALIGN_JUSTIFIED,
             ExtraParagraphSpace = 6,
             Leading             = 14,
             Indent         = 10,
             RightIndent    = 3,
             SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO
         };
         int column = 0;
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int status = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             ct.AddText(CreateMovieInformation(movie));
             status = ct.Go();
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 ct.YLine = COLUMNS[column][3];
                 status   = ct.Go();
             }
         }
     }
 }
예제 #17
0
        private static void LayoutPage(PdfContentByte content, List <FilmDetails> pageFilms, string runName)
        {
            double num1 = 70.0;
            double num2 = 800.0;
            double num3 = 400.0;

            for (int index = 0; index < pageFilms.Count; ++index)
            {
                FilmDetails filmDetails = pageFilms[index];
                bool        flag        = false;
                if (filmDetails.RunTime == 0)
                {
                    flag = true;
                    filmDetails.RunTime = 120;
                }
                double    num4      = 0.0491666666666667 * (double)filmDetails.RunTime * 30.0;
                double    num5      = num1 + (double)(index % 5 * 90);
                double    num6      = num5 + 90.0;
                double    num7      = index >= 5 ? num3 : num2;
                double    num8      = index >= 5 ? num3 - num4 : num2 - num4;
                Rectangle rectangle = new Rectangle((float)num5, (float)num8, (float)num6, (float)num7);
                rectangle.BorderColor       = Color.BLACK;
                rectangle.BorderWidthBottom = 1f;
                rectangle.BorderWidthLeft   = 1f;
                rectangle.BorderWidthRight  = 1f;
                rectangle.BorderWidthTop    = 1f;
                if (flag)
                {
                    rectangle.BackgroundColor = Color.RED;
                }
                content.Rectangle(rectangle);
                ColumnText columnText1 = new ColumnText(content);
                columnText1.SetSimpleColumn((float)num5, (float)num8, (float)num6, (float)num7, 15f, 1);

                columnText1.AddText(new Phrase(FormatTitle(filmDetails.Title, filmDetails.RunTime), FormatTitleFont(filmDetails.RunTime)));
                columnText1.Go();
                columnText1.AddText(new Phrase(string.Format("{0} min", (object)filmDetails.RunTime), FontFactory.GetFont("Arial", 9f)));
                columnText1.Go();
                ColumnText columnText2 = columnText1;

                String l = FormatLanguage(filmDetails.Language, filmDetails.Country);
                String c = FormatCountry(filmDetails.Language, filmDetails.Country);

                columnText1.AddText(FormatLanguageAndCountry(l, c, filmDetails.RunTime));
                columnText1.Go();

                //Resolution/ratio
                columnText1.AddText(new Phrase(string.Format("{0} / {1}", (object)filmDetails.Resolution, (object)filmDetails.Ratio), FontFactory.GetFont("Arial", 8f)));
                columnText1.Go();

                columnText1.AddText(new Phrase(string.Format("{0} / {1}", (object)filmDetails.AucklandScreeningNo, (object)filmDetails.WellingtonScreeningNo), FontFactory.GetFont("Arial", 8f)));
                columnText1.Go();

                columnText1.AddText(new Phrase(runName, FontFactory.GetFont("Arial", 16f)));
                columnText1.Go();
            }
        }
예제 #18
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         ColumnText ct     = new ColumnText(writer.DirectContent);
         int        column = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 y = COLUMNS[column][3];
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go(false);
         }
     }
 }
예제 #19
0
        public void AddPageNumber(string str, string displaytext)
        {
            byte[] bytes = File.ReadAllBytes(str);

            iTextSharp.text.Font blackFont = FontFactory.GetFont("Arial", 6, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

            using (var stream = new MemoryStream())
            {
                stream.Flush();
                System.Windows.Forms.Application.DoEvents();
                PdfReader reader = new PdfReader(bytes);
                PdfReader.unethicalreading = true;
                Paragraph p   = new Paragraph();
                Document  doc = new Document();
                using (PdfStamper stamper = new PdfStamper(reader, stream))
                {
                    System.Windows.Forms.Application.DoEvents();

                    //PdfContentByte canvas = stamper.GetOverContent(1);
                    //iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1);
                    int pages = reader.NumberOfPages;
                    for (int i = 1; i <= pages; i++)
                    {
                        iTextSharp.text.Rectangle mediabox = reader.GetPageSize(i);
                        float x, y;
                        x = mediabox.Height;
                        y = mediabox.Width;

                        iTextSharp.text.Rectangle cropBox = reader.GetCropBox(i);
                        cropBox.GetRectangle(y - 1000, x - 50);
                        iTextSharp.text.Rectangle bottomRight = new iTextSharp.text.Rectangle(cropBox.GetRight(199), cropBox.Bottom, cropBox.Right, cropBox.GetBottom(18));
                        //TextField tf = new TextField(stamper.Writer, new iTextSharp.text.Rectangle(0, 0, 300, 100), displaytext);
                        ////Change the orientation of the text
                        //tf.Rotation = 0;

                        EmptyTextBoxSimple(stamper, i, bottomRight, BaseColor.WHITE);
                        ColumnText columnText = GenerateTextBox(stamper, i, bottomRight);
                        columnText.AddText(new Phrase(displaytext.ToString(), blackFont));
                        columnText.Go();
                    }
                }

                bytes = stream.ToArray();
                //stream.Flush();
            }
            System.Threading.Thread.Sleep(200);
            File.WriteAllBytes(str, bytes);
        }
예제 #20
0
        public void AddParagraph(string text, ColumnText column, Font font, BaseColor fontColor, int alignment)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            font.Color = fontColor;

            var para = new Paragraph(text, font)
            {
                Alignment = alignment
            };

            column.AddText(para);
            column.Go();
        }
예제 #21
0
        virtual public void WriteTextWithWordSpacing()
        {
            Document   document = new Document();
            FileStream output   = new FileStream(TARGET + "textWithWorldSpacing.pdf", FileMode.Create);
            PdfWriter  writer   = PdfWriter.GetInstance(document, output);

            document.Open();
            document.SetPageSize(PageSize.A4);
            document.NewPage();
            writer.DirectContent.SetWordSpacing(10);
            ColumnText columnText = new ColumnText(writer.DirectContent);

            columnText.SetSimpleColumn(new Rectangle(30, 0, document.PageSize.Right, document.PageSize.Top - 30));
            columnText.UseAscender = true;
            columnText.AddText(new Chunk("H H H H H H H H H  !", new Font(fontWithToUnicode, 30)));
            columnText.Go();
            document.Close();
        }
예제 #22
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            base.Decorate();

            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            iTextSharp.text.Font font      = CreateFontFromFactory(this.StyleDecorator);
            CalculatePdfFormat   pdfFormat = new CalculatePdfFormat(this.StyleDecorator, font);

            ColumnText columnText = new ColumnText(contentByte);

            if (StyleDecorator.RightToLeft.ToString() == "Yes")
            {
                columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            }

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Top - r.Height, pdfFormat.Leading, pdfFormat.Alignment);

            string formatedText = this.Text;

            if (!String.IsNullOrEmpty(StyleDecorator.FormatString))
            {
                formatedText = StandardFormatter.FormatOutput(this.Text, this.StyleDecorator.FormatString,
                                                              this.StyleDecorator.DataType, String.Empty);
            }

            Chunk chunk = new Chunk(formatedText, font);

            columnText.AddText(chunk);

            columnText.Go();
        }
예제 #23
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            ColumnText ct         = new ColumnText(Rep.Canvas);
            string     column_val = FormatDate(SummarizedValue.ToString(), Format, Rep);

            ResetSummary();
            if (column_val != string.Empty)
            {
                if (Prefix != "" || Suffix != "")
                {
                    column_val = Prefix + " " + column_val + " " + Suffix;
                }
                Phrase phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);

                ct.AddText(phrase);
                float ury = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
                float lly = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);
                ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
                ct.Go();
            }
        }
예제 #24
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            String textoPaginacao = writer.PageNumber + " / ";

            #region Adicionando pagina no cabeçalho
            if (_documentOptions.ShowPagingOnTop)
            {
                {
                    cb.BeginText();
                    cb.SetFontAndSize(bf, 8f);
                    cb.SetTextMatrix(document.PageSize.GetRight(60), document.PageSize.GetTop(55));
                    cb.ShowText(textoPaginacao);
                    cb.EndText();
                    float len = bf.GetWidthPoint(textoPaginacao, 8f);
                    //Adds "12" in Page 1 of 12
                    cb.AddTemplate(headerTemplate, document.PageSize.GetRight(60) + len, document.PageSize.GetTop(55));
                }
            }
            #endregion

            #region Adicionando pagina do rodapé
            if (_documentOptions.ShowPagingOnBottom)
            {
                {
                    cb.BeginText();
                    cb.SetFontAndSize(bf, 8f);
                    cb.SetTextMatrix(document.PageSize.GetRight(100), document.PageSize.GetBottom(30));
                    cb.ShowText(textoPaginacao);
                    cb.EndText();
                    float len = bf.GetWidthPoint(textoPaginacao, 8f);


                    #region texto do rodapé
                    if (_documentOptions.FooterOptions.ShowFooterText)
                    {
                        Paragraph paragrafoRodape1 = new Paragraph(new Chunk("Fundação para o Desenvolvimento da Educação", FontFactory.GetFont("Arial", 7f, Font.BOLD, BaseColor.BLACK)));
                        Paragraph paragrafoRodape2 = new Paragraph(new Chunk("Avenida São Luís, 99 - República 01046-001 Tel. (11) 3158-4000", FontFactory.GetFont("Arial", 7f, Font.NORMAL, BaseColor.BLACK)));
                        Paragraph paragrafoRodape3 = new Paragraph(new Chunk("www.fde.sp.gov.br", FontFactory.GetFont("Arial", 6f, Font.NORMAL, BaseColor.BLACK)).SetAnchor("http://www.fde.sp.gov.br/"));

                        float      dimInit           = 35;
                        ColumnText columnTextRodape1 = new ColumnText(cb);
                        columnTextRodape1.AddText(paragrafoRodape1);
                        if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato)
                        {
                            columnTextRodape1.SetSimpleColumn(590, dimInit, 0, 0, 0, Element.ALIGN_CENTER);
                        }
                        else
                        {
                            columnTextRodape1.SetSimpleColumn(890, dimInit, 0, 0, 0, Element.ALIGN_CENTER);
                        }

                        columnTextRodape1.Go();

                        ColumnText columnTextRodape2 = new ColumnText(cb);
                        columnTextRodape2.AddText(paragrafoRodape2);
                        if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato)
                        {
                            columnTextRodape2.SetSimpleColumn(590, (dimInit - 10f), 5, 0, 0, Element.ALIGN_CENTER);
                        }
                        else
                        {
                            columnTextRodape2.SetSimpleColumn(890, (dimInit - 10f), 5, 0, 0, Element.ALIGN_CENTER);
                        }

                        columnTextRodape2.Go();

                        ColumnText columnTextRodape3 = new ColumnText(cb);
                        columnTextRodape3.AddText(paragrafoRodape3);
                        if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato)
                        {
                            columnTextRodape3.SetSimpleColumn(590, (dimInit - 20f), 0, 0, 0, Element.ALIGN_CENTER);
                        }
                        else
                        {
                            columnTextRodape3.SetSimpleColumn(890, (dimInit - 20f), 0, 0, 0, Element.ALIGN_CENTER);
                        }

                        columnTextRodape3.Go();
                    }
                    #endregion


                    cb.AddTemplate(footerTemplate, document.PageSize.GetRight(100) + len, document.PageSize.GetBottom(30));
                }
            }
            #endregion

            #region Cabeçalho
            if (_documentOptions.ShowHeader)
            {
                float _HeaderHeight = 65f;

                PdfPTable tableHeader = new PdfPTable(1);
                tableHeader.WidthPercentage         = 95f;
                tableHeader.DefaultCell.FixedHeight = 20f;
                tableHeader.TotalWidth = document.PageSize.Width - 80f;

                PdfPCell cellHeader = new PdfPCell();
                cellHeader.Border      = PdfPCell.NO_BORDER;
                cellHeader.FixedHeight = _HeaderHeight;

                // Retrato
                if (_documentOptions.PageOrientation == PdfPageOrientation.Retrato)
                {
                    Paragraph paragrafoCabecalho1 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderTitleText, FontFactory.GetFont("Arial", 12f, Font.BOLD, BaseColor.BLACK)));
                    Paragraph paragrafoCabecalho2 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderSubtitleText, FontFactory.GetFont("Arial", 9f, Font.BOLD, BaseColor.BLACK)));

                    ColumnText columnTextCabecalho1 = new ColumnText(cb);
                    columnTextCabecalho1.AddText(paragrafoCabecalho1);
                    columnTextCabecalho1.SetSimpleColumn(34, 815, 540, 217, 10, Element.ALIGN_CENTER);
                    columnTextCabecalho1.Go();

                    ColumnText columnTextCabecalho2 = new ColumnText(cb);
                    columnTextCabecalho2.AddText(paragrafoCabecalho2);
                    columnTextCabecalho2.SetSimpleColumn(34, 800, 540, 217, 10, Element.ALIGN_CENTER);
                    columnTextCabecalho2.Go();

                    #region Imagem LOGO LEFT
                    if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.HeaderImageLeft != null)
                    {
                        MemoryStream mst = new MemoryStream();
                        _documentOptions.HeaderOptions.HeaderImageLeft.Save(mst, System.Drawing.Imaging.ImageFormat.Jpeg);
                        byte[] b = mst.ToArray();

                        //posicionando a imagem no arquivo
                        iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b);
                        imageLogo.SetAbsolutePosition(document.PageSize.Width - 580f, document.PageSize.Height - 46f);
                        imageLogo.ScalePercent(52f);
                        document.Add(imageLogo);
                    }
                    #endregion

                    #region Imagem LOGO RIGHT
                    if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.ShowImageRight && _documentOptions.HeaderOptions.HeaderImageRight != null)
                    {
                        MemoryStream mst = new MemoryStream();
                        _documentOptions.HeaderOptions.HeaderImageRight.Save(mst, System.Drawing.Imaging.ImageFormat.Png);
                        byte[] b = mst.ToArray();

                        //posicionando a imagem no arquivo
                        iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b);
                        imageLogo.SetAbsolutePosition(document.PageSize.Width - 125f, document.PageSize.Height - 46f);
                        imageLogo.ScalePercent(35f);
                        document.Add(imageLogo);
                    }
                    #endregion

                    #region Data de impressão
                    if (_documentOptions.ShowPrintDateTime)
                    {
                        Chunk  chunkDataImpressaoText  = new Chunk("Data de impressão: ", FontFactory.GetFont("Arial", 8f, Font.BOLD, BaseColor.BLACK));
                        Phrase phraseDataImpressaoText = new Phrase();
                        phraseDataImpressaoText.Add(chunkDataImpressaoText);

                        Chunk  chunkDataImpressaoData  = new Chunk(PrintDateTime.ToString(), FontFactory.GetFont("Arial", 8f, BaseColor.BLACK));
                        Phrase phraseDataImpressaoData = new Phrase();
                        phraseDataImpressaoData.Add(chunkDataImpressaoData);

                        Paragraph paragrafoTextDataImpressao = new Paragraph();
                        paragrafoTextDataImpressao.Add(chunkDataImpressaoText);
                        paragrafoTextDataImpressao.Add(chunkDataImpressaoData);

                        ColumnText columnTextDataImpressao = new ColumnText(cb);
                        columnTextDataImpressao.AddText(paragrafoTextDataImpressao);
                        columnTextDataImpressao.SetSimpleColumn(334, 775, 540, 217, 10, Element.ALIGN_RIGHT);
                        columnTextDataImpressao.Go();
                    }
                    #endregion

                    tableHeader.AddCell(cellHeader);
                }
                else // Paisagem
                {
                    Paragraph paragrafoCabecalho1 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderTitleText, FontFactory.GetFont("Arial", 12f, Font.BOLD, BaseColor.BLACK)));
                    Paragraph paragrafoCabecalho2 = new Paragraph(new Chunk(_documentOptions.HeaderOptions?.HeaderSubtitleText, FontFactory.GetFont("Arial", 9f, Font.BOLD, BaseColor.BLACK)));

                    ColumnText columnTextCabecalho1 = new ColumnText(cb);
                    columnTextCabecalho1.AddText(paragrafoCabecalho1);
                    columnTextCabecalho1.SetSimpleColumn(790, 578, 10, 0, 10, Element.ALIGN_CENTER);
                    columnTextCabecalho1.Go();

                    ColumnText columnTextCabecalho2 = new ColumnText(cb);
                    columnTextCabecalho2.AddText(paragrafoCabecalho2);
                    columnTextCabecalho2.SetSimpleColumn(790, 558, 10, 0, 10, Element.ALIGN_CENTER);
                    columnTextCabecalho2.Go();

                    #region Imagem LOGO LEFT
                    if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.HeaderImageLeft != null)
                    {
                        MemoryStream mst = new MemoryStream();
                        _documentOptions.HeaderOptions.HeaderImageLeft.Save(mst, System.Drawing.Imaging.ImageFormat.Jpeg);
                        byte[] b = mst.ToArray();

                        //posicionando a imagem no arquivo
                        iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b);
                        imageLogo.SetAbsolutePosition(document.PageSize.Width - 822f, document.PageSize.Height - 46f);
                        imageLogo.ScalePercent(52f);
                        document.Add(imageLogo);
                    }
                    #endregion

                    #region Imagem LOGO RIGHT
                    if (_documentOptions.HeaderOptions != null && _documentOptions.HeaderOptions.ShowImageRight && _documentOptions.HeaderOptions.HeaderImageRight != null)
                    {
                        MemoryStream mst = new MemoryStream();
                        _documentOptions.HeaderOptions.HeaderImageRight.Save(mst, System.Drawing.Imaging.ImageFormat.Png);
                        byte[] b = mst.ToArray();

                        //posicionando a imagem no arquivo
                        iTextSharp.text.Image imageLogo = iTextSharp.text.Image.GetInstance(b);
                        imageLogo.SetAbsolutePosition(document.PageSize.Width - 125f, document.PageSize.Height - 46f);
                        imageLogo.ScalePercent(35f);
                        document.Add(imageLogo);
                    }
                    #endregion

                    #region Data de impressão
                    if (_documentOptions.ShowPrintDateTime)
                    {
                        Chunk  chunkDataImpressaoText  = new Chunk("Data de impressão: ", FontFactory.GetFont("Arial", 8f, Font.BOLD, BaseColor.BLACK));
                        Phrase phraseDataImpressaoText = new Phrase();
                        phraseDataImpressaoText.Add(chunkDataImpressaoText);

                        Chunk  chunkDataImpressaoData  = new Chunk(PrintDateTime.ToString(), FontFactory.GetFont("Arial", 8f, BaseColor.BLACK));
                        Phrase phraseDataImpressaoData = new Phrase();
                        phraseDataImpressaoData.Add(chunkDataImpressaoData);

                        Paragraph paragrafoTextDataImpressao = new Paragraph();
                        paragrafoTextDataImpressao.Add(chunkDataImpressaoText);
                        paragrafoTextDataImpressao.Add(chunkDataImpressaoData);

                        ColumnText columnTextDataImpressao = new ColumnText(cb);
                        columnTextDataImpressao.AddText(paragrafoTextDataImpressao);
                        columnTextDataImpressao.SetSimpleColumn(790, 530, 10, 0, 10, Element.ALIGN_RIGHT);
                        columnTextDataImpressao.Go();
                    }
                    #endregion

                    tableHeader.AddCell(cellHeader);
                }

                //chamar WriteSelectedRows da PdfTable. Este escreve linhas de PdfWriter em PdfTable.
                //Primeiro parâmetro é começar a linha. -1 indica que não há linha final e todas as linhas a serem incluídos para escrever
                //Parâmetro terceiro e quarto é x e y posição para começar a escrever
                tableHeader.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent);
            }
            #endregion

            #region Linha em baixo (cabeçalho e rodapé)
            //Move o pointer e desenhar linha para separar seção de cabeçalho do resto da página
            if (_documentOptions.HeaderOptions.DrawHeaderLine)
            {
                cb.MoveTo(20, document.PageSize.GetTop(60));
                cb.LineTo(document.PageSize.Width - 20, document.PageSize.GetTop(60));
                cb.Stroke();
            }

            //Move o pointer e desenhar linha para separar seção de rodapé do resto da página
            if (_documentOptions.FooterOptions.DrawFooterLine)
            {
                cb.MoveTo(20, document.PageSize.GetBottom(50));
                cb.LineTo(document.PageSize.Width - 20, document.PageSize.GetBottom(50));
                cb.Stroke();
            }
            #endregion
        }
예제 #25
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();
        }
    }
예제 #26
0
        public Chap1008()
        {
            Console.WriteLine("Chapter 10 example 8: Irregular columns");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2: creation of the writer
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1008.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4:
                BaseFont bf   = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font     font = new Font(bf, 11, Font.NORMAL);

                // we grab the contentbyte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                PdfTemplate t      = cb.CreateTemplate(600, 800);
                Image       caesar = Image.GetInstance("caesar_coin.jpg");
                cb.AddImage(caesar, 100, 0, 0, 100, 260, 595);
                t.SetGrayFill(0.75f);
                t.MoveTo(310, 112);
                t.LineTo(280, 60);
                t.LineTo(340, 60);
                t.ClosePath();
                t.MoveTo(310, 790);
                t.LineTo(310, 710);
                t.MoveTo(310, 580);
                t.LineTo(310, 122);
                t.Stroke();
                cb.AddTemplate(t, 0, 0);

                ColumnText ct = new ColumnText(cb);
                ct.AddText(new Phrase("GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));

                float[] left1  = { 70, 790, 70, 60 };
                float[] right1 = { 300, 790, 300, 700, 240, 700, 240, 590, 300, 590, 300, 106, 270, 60 };
                float[] left2  = { 320, 790, 320, 700, 380, 700, 380, 590, 320, 590, 320, 106, 350, 60 };
                float[] right2 = { 550, 790, 550, 60 };

                int status = 0;
                int column = 0;
                while ((status & ColumnText.NO_MORE_TEXT) == 0)
                {
                    if (column == 0)
                    {
                        ct.SetColumns(left1, right1);
                        column = 1;
                    }
                    else
                    {
                        ct.SetColumns(left2, right2);
                        column = 0;
                    }
                    status       = ct.Go();
                    ct.YLine     = 790;
                    ct.Alignment = Element.ALIGN_JUSTIFIED;
                    status       = ct.Go();
                    if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0))
                    {
                        document.NewPage();
                        cb.AddTemplate(t, 0, 0);
                        cb.AddImage(caesar, 100, 0, 0, 100, 260, 595);
                    }
                }

                // step 5: we close the document
                document.Close();
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }
        }
예제 #27
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            iTextSharp.text.Font font = null;

            if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point)
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           this.StyleDecorator.Font.Size,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
            else
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
//
//			http://www.google.de/search?hl=de&q=itextsharp+%2B+measure+text&start=10&sa=N
//			http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs
//			http://www.mikesdotnetting.com/Category/20

//	itextsharp + columntext + textheight
//itextsharp + columntext + rectangle

//itextsharp + simulate
//http://www.mail-archive.com/[email protected]/msg04747.html
            base.Decorate();
            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            ColumnText columnText       = new ColumnText(contentByte);
            PdfFormat  pdfFormat        = new PdfFormat(this.StyleDecorator, font);

            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Height, pdfFormat.Leading, pdfFormat.Alignment);
//			int a = Convert.ToInt16((r.Height/font.Size) + 1);
//			columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Height,a,pdfFormat.Alignment);
            string formated = StandardFormatter.FormatOutput(this.text, this.StyleDecorator.FormatString,
                                                             this.StyleDecorator.DataType, String.Empty);

            Chunk chunk = new Chunk(formated, font);

            columnText.AddText(chunk);

            columnText.Go();
            int i = columnText.LinesWritten;

            if (i > 1)
            {
                Console.WriteLine("{0} - {1}", i, this.text);
                Console.WriteLine("dif {0}", r.Height / font.Size);
            }
        }
예제 #28
0
        public ActionResult Create([Bind(Include = "ColumnWidth_1, ColumnWidth_3, ColumnText_1, ColumnText_2, ColumnText_3")] Columns model)
        {
            if (ModelState.IsValid)
            {
                Rectangle  main = new Rectangle(1, 1, 1000, 1000);
                Document   pdf  = new Document(main);
                FileStream st   = new FileStream(Server.MapPath("~/Data/data.pdf"), FileMode.Create);
                PdfWriter  wr   = PdfWriter.GetInstance(pdf, st);


                pdf.Open();

                BaseFont             baseFont = BaseFont.CreateFont(Server.MapPath("~/fonts/ARIAL.TTF"), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font     = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);

                //Old

                /*
                 * PdfPTable table = new PdfPTable(3);
                 *
                 * PdfPCell cell1 = new PdfPCell(new Phrase(model.ColumnText_1.ToString(),font));
                 * cell1.Colspan = 1;
                 * cell1.HorizontalAlignment = 1;
                 *
                 * PdfPCell cell2 = new PdfPCell(new Phrase(model.ColumnText_2.ToString(),font));
                 * cell2.Colspan = 1;
                 * cell2.HorizontalAlignment = 1;
                 *
                 * PdfPCell cell3 = new PdfPCell(new Phrase(model.ColumnText_3.ToString(), font));
                 * cell3.Colspan = 1;
                 * cell3.HorizontalAlignment = 1;
                 *
                 * table.AddCell(cell1);
                 * table.AddCell(cell2);
                 * table.AddCell(cell3);
                 *
                 * float[] widths = new float[] { model.ColumnWidth_1, model.ColumnWidth_2, model.ColumnWidth_3};
                 * table.SetWidths(widths);
                 * pdf.Add(table);
                 */

                PdfContentByte cb = wr.DirectContent;

                var rec1 = new iTextSharp.text.Rectangle(10, 950, model.ColumnWidth_1, 850);
                rec1.Border      = iTextSharp.text.Rectangle.BOX;
                rec1.BorderWidth = 1;
                rec1.BorderColor = new BaseColor(0, 0, 0);
                cb.Rectangle(rec1);
                ColumnText column1 = new ColumnText(cb);
                column1.SetSimpleColumn(rec1);
                column1.AddText(new Phrase(model.ColumnText_1.ToString(), font));
                column1.Go();

                var rec2 = new iTextSharp.text.Rectangle(10 + model.ColumnWidth_1, 950, 1000 - 20 - model.ColumnWidth_3, 850);
                rec2.Border      = iTextSharp.text.Rectangle.BOX;
                rec2.BorderWidth = 1;
                rec2.BorderColor = new BaseColor(0, 0, 0);
                cb.Rectangle(rec2);
                ColumnText column2 = new ColumnText(cb);
                column2.SetSimpleColumn(rec2);
                column2.AddText(new Phrase(model.ColumnText_2.ToString(), font));
                column2.Go();

                var rec3 = new iTextSharp.text.Rectangle(990 - model.ColumnWidth_3, 950, 990, 850);
                rec3.Border      = iTextSharp.text.Rectangle.BOX;
                rec3.BorderWidth = 1;
                rec3.BorderColor = new BaseColor(0, 0, 0);
                cb.Rectangle(rec3);
                ColumnText column3 = new ColumnText(cb);
                column3.SetSimpleColumn(rec3);
                column3.AddText(new Phrase(model.ColumnText_3.ToString(), font));
                column3.Go();


                pdf.Close();


                ViewBag.Message = "Data is stored on the server in PDF format";
                return(View("Create"));
            }
            return(View());
        }
예제 #29
0
파일: TextBox.cs 프로젝트: long123king/pdfk
 public void newParagraph()
 {
     m_column_text.AddText(m_content);
     m_content = new Paragraph();
 }
예제 #30
0
        public Chap1006()
        {
            Console.WriteLine("Chapter 10 example 6: Simple Columns");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1006.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4:

                // we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                BaseFont bf   = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font     font = new Font(bf, 11, Font.NORMAL);

                ColumnText ct = new ColumnText(cb);
                ct.SetSimpleColumn(60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
                ct.AddText(new Phrase(15, "UNI\n", font));
                for (int i = 0; i < 27; i++)
                {
                    ct.AddText(new Phrase(15, uni[i] + "\n", font));
                }
                ct.Go();
                cb.Rectangle(103, 295, 52, 8 + 28 * 15);
                cb.Stroke();
                ct.SetSimpleColumn(105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
                ct.AddText(new Phrase(15, "char\n", font));
                for (int i = 0; i < 27; i++)
                {
                    ct.AddText(new Phrase(15, code[i] + "\n", font));
                }
                ct.Go();
                ct.SetSimpleColumn(160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
                ct.AddText(new Phrase(15, "NAME\n", font));
                for (int i = 0; i < 27; i++)
                {
                    ct.AddText(new Phrase(15, name[i] + "\n", font));
                }
                ct.Go();
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }