GetRight() public method

Returns the upper right x-coordinate, considering a given margin.
public GetRight ( float margin ) : float
margin float a margin
return float
示例#1
0
        /// <summary>
        /// Gets the contents text from page to put in TOC.
        /// </summary>
        /// <returns>The name of the page.</returns>
        /// <param name="pdfPath">The Pdf to read from.</param>
        /// <param name="page">The pages to read from.</param>
        public static string GetContentsTextFromPage(String pdfPath, int page)
        {
            PdfReader    reader = new PdfReader(pdfPath);
            StringWriter output = new StringWriter();

            //Create rectangle to read from header
            Rectangle mediabox = reader.GetPageSize(page);
            float     llx      = mediabox.GetRight(10f) - 100f;
            float     urx      = mediabox.GetRight(0f);
            float     lly      = mediabox.GetTop(10f) - 50f;
            float     ury      = mediabox.GetTop(0f);
            Rectangle rect     = new Rectangle(llx, lly, urx, ury);

            //The header contains the name of the page. Read from Heaedr.
            RenderFilter            regionFilter = new RegionTextRenderFilter(rect);
            ITextExtractionStrategy strategy     = new FilteredTextRenderListener(
                new LocationTextExtractionStrategy(), regionFilter);

            output.WriteLine(PdfTextExtractor.GetTextFromPage(reader, page, strategy));
            Console.WriteLine(output.ToString());
            string ret = output.ToString();

            //Remove newline characters
            return(Regex.Replace(ret, @"\t|\n|\r", ""));
        }
示例#2
0
        private static void ConfiguraAparenciaAssinatura(PdfSignatureAppearance signatureAppearance, string Reason, string Contact, string Location, string Creator, Bitmap bmp, float Altura, float Largura, float X, float Y, int Rotation, int Pagina, PdfReader pdfReader)
        {
            iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(bmp, System.Drawing.Imaging.ImageFormat.Jpeg);

            signatureAppearance.Reason                 = Reason;
            signatureAppearance.Contact                = Contact;
            signatureAppearance.Location               = "Indústrias Nucleares do Brasil S/A - INB";
            signatureAppearance.SignatureCreator       = "Assinador da INB - Desenvolvimento Interno";
            signatureAppearance.SignatureGraphic       = pic;
            signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC;


            float Left, Top;
            float Width, Height;
            float LarguraAssinatura = Largura;
            float AlturaAssinatura = Altura;
            float X_Ajustado, Y_Ajustado;

            iTextSharp.text.Rectangle cropBox = pdfReader.GetCropBox(Pagina);
            iTextSharp.text.Rectangle oRetangulo;
            if (Rotation == 90 || Rotation == 270)
            {
                X_Ajustado = (float)X;
                Y_Ajustado = (float)Y;

                if (Rotation == 270)
                {
                    Y_Ajustado -= 5;
                    Top         = cropBox.GetLeft(X_Ajustado);
                    Width       = cropBox.GetLeft(X_Ajustado + Largura);
                    Left        = cropBox.GetRight(Y_Ajustado);
                    Height      = cropBox.GetRight(Y_Ajustado + Altura);
                    oRetangulo  = new iTextSharp.text.Rectangle(Top, Left, Width, Height);
                }
                else
                {
                    Y_Ajustado -= 5;
                    Top         = cropBox.GetRight(X_Ajustado);
                    Width       = cropBox.GetRight(X_Ajustado + Largura);
                    Left        = cropBox.GetLeft(Y_Ajustado);
                    Height      = cropBox.GetLeft(Y_Ajustado + Altura);
                    oRetangulo  = new iTextSharp.text.Rectangle(Top, Left, Width, Height);
                }
            }
            else
            {
                X_Ajustado = (float)X;
                Y_Ajustado = (float)Y - 5;
                Left       = cropBox.GetLeft(X_Ajustado);
                Top        = cropBox.GetTop(Y_Ajustado);
                Width      = cropBox.GetLeft(X_Ajustado + LarguraAssinatura);
                Height     = cropBox.GetTop(Y_Ajustado + AlturaAssinatura);
                oRetangulo = new iTextSharp.text.Rectangle(Left, Height, Width, Top);
            }
            signatureAppearance.SetVisibleSignature(oRetangulo, Pagina, "sig" + DateTime.Now.ToString("ddMMyyHHmmss"));
        }
示例#3
0
    void IPdfPCellEvent.CellLayout(PdfPCell cell, iTextSharp.text.Rectangle position, PdfContentByte[] canvases)
    {
        PdfContentByte canvas    = canvases[PdfPTable.TEXTCANVAS];
        float          x         = 0;
        float          y         = 0;
        int            alignment = 0;

        switch (pos)
        {
        case "TOP_LEFT":
            x         = position.GetLeft(3);
            y         = position.GetTop(content.Leading);
            alignment = Element.ALIGN_LEFT;
            break;

        case "TOP_RIGHT":
            x         = position.GetRight(3);
            y         = position.GetTop(content.Leading);
            alignment = Element.ALIGN_RIGHT;
            break;

        case "BOTTOM_LEFT":
            x         = position.GetLeft(3);
            y         = position.GetBottom(3);
            alignment = Element.ALIGN_LEFT;
            break;

        case "BOTTOM_RIGHT":
            x         = position.GetRight(3);
            y         = position.GetBottom(3);
            alignment = Element.ALIGN_RIGHT;
            break;

        case "CENTER_TOP":
            x         = position.GetRight(3) + position.GetLeft(3) / 2;
            y         = position.GetTop(3);
            alignment = Element.ALIGN_RIGHT;
            break;

        case "CENTER_BOTTOM":
            x         = position.GetRight(3) + position.GetLeft(3) / 2;
            y         = position.GetBottom(3);
            alignment = Element.ALIGN_RIGHT;
            break;

        case "CENTER_MIDDLE":
            x         = position.GetRight(3) + position.GetLeft(3) / 2;
            y         = x;
            alignment = Element.ALIGN_RIGHT;
            break;
        }
        ColumnText.ShowTextAligned(canvas, alignment, content, x, y, 0);
    }
示例#4
0
        /// <summary>
        /// Clears the contents of a given page leaving header and footer.
        /// </summary>
        /// <param name="inputPdf">The pdf to modify.</param>
        /// <param name="outputPdf">The pdf created after modification.</param>
        /// <param name="pageNum">The page number to be cleared.</param>
        public static void ClearContents(string inputPdf, string outputPdf, int pageNum)
        {
            using (FileStream fs = new FileStream(outputPdf, FileMode.Create, FileAccess.Write))
            {
                PdfReader  reader  = new PdfReader(inputPdf);
                PdfStamper stamper = new PdfStamper(reader, fs);

                //Get the reactangle leaving header and footer
                Rectangle mediabox = reader.GetPageSize(pageNum);
                float     llx      = mediabox.GetLeft(10f);
                float     urx      = mediabox.GetRight(10f);
                float     lly      = mediabox.GetBottom(10f) + 100f; // Leave footer
                float     ury      = mediabox.GetTop(10f) - 120f;    //Leave header

                List <PdfCleanUpLocation> cleanUpLocations = new List <PdfCleanUpLocation>
                {
                    new PdfCleanUpLocation(pageNum, new iTextSharp.text.Rectangle(llx, lly, urx, ury), BaseColor.WHITE)
                };
                //Use the PdfCleanUpProcessor to clean the page
                PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
                cleaner.CleanUp();
                stamper.Close();
                reader.Close();
            }
        }
// ---------------------------------------------------------------------------    
    /**
     * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(
     * com.lowagie.text.pdf.PdfPCell,
     * com.lowagie.text.Rectangle, 
     * com.lowagie.text.pdf.PdfContentByte[]
     * )
     */
    public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb)
    {
      parent.AddKid(kid);
      kid.SetWidget(
        new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding),
        rect.GetRight(padding), rect.GetTop(padding)),
        PdfAnnotation.HIGHLIGHT_INVERT
      );
    }
 //creat 2 - line weight
 private void equalline(iTextSharp.text.Rectangle pagesize, int toTheTop)
 {
     cb.EndText();
     cb.SetColorStroke(new BaseColor(0x32, 0x5a, 0x75));
     cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(toTheTop - 5));
     cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(toTheTop - 5));
     cb.SetLineWidth(2f);
     cb.Stroke();
     cb.BeginText();
 }
        //create 1 - line weight
        private void line(iTextSharp.text.Rectangle pagesize, int toTheTop, Boolean summary)
        {
            cb.EndText();
            cb.SetColorStroke(new BaseColor(0x66, 0x83, 0x97));
            cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(toTheTop - 5));
            cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(toTheTop - 5));
            cb.SetLineWidth(1f);
            cb.Stroke();

            if (!summary)
            {
                cb.BeginText();
            }
        }
示例#8
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            BaseFont bf_qty = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            //int pageN = writer.PageNumber;
            //String text = "Page " + pageN.ToString();



            String text = "Page " + 1 + " of ";
            float  len  = bf_qty.GetWidthPoint(text, 8);

            //float len = this.RunDateFont.BaseFont.GetWidthPoint(text, this.RunDateFont.Size);

            iTextSharp.text.Rectangle pageSize = document.PageSize;

            // cb.SetRGBColorFill(100, 100, 100);

            cb.BeginText();

            //Font font_qty = new Font(bf_qty, 10, Font.NORMAL);
            cb.SetFontAndSize(bf_qty, 10f);
            cb.SetTextMatrix(document.LeftMargin, pageSize.GetBottom(document.BottomMargin));
            // cb.ShowText(text);
            cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT,
                               "Printed On " + DateTime.Now.ToString(),
                               pageSize.GetRight(40),
                               pageSize.GetBottom(30), 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT,
                               text,
                               pageSize.GetLeft(40),
                               pageSize.GetBottom(30), 0);

            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT,
                               "This is a Computer generated Invoice",
                               pageSize.GetLeft(200),
                               pageSize.GetBottom(30), 0);


            cb.EndText();

            // cb.AddTemplate(template, document.LeftMargin, pageSize.GetBottom(document.BottomMargin));

            cb.AddTemplate(template, pageSize.GetLeft(40) + len, pageSize.GetBottom(30));
        }
示例#9
0
    public override void OnEndPage(PdfWriter writer, Document document)
    {
        base.OnEndPage(writer, document);
        int       pageN    = writer.PageNumber;
        String    text     = "Página " + pageN + "/";
        float     len      = bf.GetWidthPoint(text, 8);
        Rectangle pageSize = document.PageSize;

        cb.SetRgbColorFill(100, 100, 100);
        cb.BeginText();
        cb.SetFontAndSize(bf, 8);
        cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetBottom(30));
        cb.ShowText(text);
        cb.EndText();

        cb.AddTemplate(template, pageSize.GetLeft(40) + len, pageSize.GetBottom(30));
        cb.BeginText();
        cb.SetFontAndSize(bf, 8);
        cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT,
                           "Fecha Impre.: " + PrintTime.ToString(),
                           pageSize.GetRight(40),
                           pageSize.GetBottom(30), 0);
        cb.EndText();
    }
 /**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
 virtual public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
     if (cellField == null || (fieldWriter == null && parent == null)) throw new ArgumentException(MessageLocalization.GetComposedMessage("you.have.used.the.wrong.constructor.for.this.fieldpositioningevents.class"));
     cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     if (parent == null)
         fieldWriter.AddAnnotation(cellField);
     else
         parent.AddKid(cellField);
 }
 /**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
 public override void OnGenericTag(PdfWriter writer, Document document,
         Rectangle rect, String text) {
     rect.Bottom = rect.Bottom - 3;
     PdfFormField field;
     genericChunkFields.TryGetValue(text, out field);
     if (field == null) {
         TextField tf = new TextField(writer, new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), text);
         tf.FontSize = 14;
         field = tf.GetTextField();
     }
     else {
         field.Put(PdfName.RECT,  new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     }
     if (parent == null)
         writer.AddAnnotation(field);
     else
         parent.AddKid(field);
 }
示例#12
0
 /**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
 public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
     float sp_left = spacing_left;
     if (float.IsNaN(sp_left)) sp_left = 0f;
     float sp_right = spacing_right;
     if (float.IsNaN(sp_right)) sp_right = 0f;
     float sp_top = spacing_top;
     if (float.IsNaN(sp_top)) sp_top = 0f;
     float sp_bottom = spacing_bottom;
     if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
     Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top));
     rect.CloneNonPositionParameters(this);
     canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
     rect.BackgroundColor = null;
     canvases[PdfPTable.LINECANVAS].Rectangle(rect);
 }
示例#13
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);
        }
示例#14
0
 /// <summary>
 /// Returns the upper right x-coordinate, considering a given margin.
 /// </summary>
 /// <param name="margin">a margin</param>
 /// <returns>the upper right x-coordinate</returns>
 public float GetRight(float margin)
 {
     return(pageSize.GetRight(marginRight + margin));
 }
示例#15
0
 // Private Methods (4)
 private void addPrintDate(Rectangle pageSize, string printTime)
 {
     ColumnText.ShowTextAligned(
                 canvas: _pdfContentByte,
                 alignment: Element.ALIGN_RIGHT,
                 phrase: _pdfRptFont.FontSelector.Process(printTime),
                 x: pageSize.GetRight(40),
                 y: pageSize.GetBottom(30),
                 rotation: 0,
                 runDirection: (int)_direction,
                 arabicOptions: 0);
 }
示例#16
0
        /**
         * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
         */
        public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
        {
            float sp_left = spacing_left;

            if (float.IsNaN(sp_left))
            {
                sp_left = 0f;
            }
            float sp_right = spacing_right;

            if (float.IsNaN(sp_right))
            {
                sp_right = 0f;
            }
            float sp_top = spacing_top;

            if (float.IsNaN(sp_top))
            {
                sp_top = 0f;
            }
            float sp_bottom = spacing_bottom;

            if (float.IsNaN(sp_bottom))
            {
                sp_bottom = 0f;
            }
            Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top));

            rect.CloneNonPositionParameters(this);
            canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
            rect.BackgroundColor = null;
            canvases[PdfPTable.LINECANVAS].Rectangle(rect);
        }
 /**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
 public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases)
 {
     if (cellField == null || (fieldWriter == null && parent == null)) throw new ArgumentException("You have used the wrong constructor for this FieldPositioningEvents class.");
     cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     if (parent == null)
         fieldWriter.AddAnnotation(cellField);
     else
         parent.AddKid(cellField);
 }