Beispiel #1
0
        public virtual void TabsInParagraphTest01()
        {
            String      outFileName = destinationFolder + "tabsInParagraphTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_tabsInParagraphTest01.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);
            float       tabWidth    = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin();
            Paragraph   p           = new Paragraph();

            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Text2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Long Long Long Long Long Long Long Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg"
                                                                                                    )));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then texts and an image."
                                                                         ).Add(new Tab()).Add("Text1").Add(image).Add("Text3");
            doc.Add(p);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Beispiel #2
0
        private void DrawTabStopsPositions(float[] positions, Document doc, int pageNum, int yStart, int dy)
        {
            PdfCanvas canvas = new PdfCanvas(doc.GetPdfDocument().GetPage(pageNum));
            float     left   = doc.GetLeftMargin();
            float     h      = doc.GetPdfDocument().GetPage(pageNum).GetCropBox().GetHeight() - yStart;

            canvas.SaveState();
            canvas.SetLineDash(4, 2);
            canvas.SetLineWidth(0.5f);
            canvas.SetLineDash(4, 2);
            foreach (float f in positions)
            {
                canvas.MoveTo(left + f, h);
                canvas.LineTo(left + f, h - dy);
            }
            canvas.Stroke();
            canvas.RestoreState();
            canvas.Release();
        }
Beispiel #3
0
        public virtual void DefaultTabsTest()
        {
            String      outFileName = destinationFolder + "defaultTabTest.pdf";
            String      cmpFileName = sourceFolder + "cmp_defaultTabTest.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);
            Paragraph   p           = new Paragraph();

            AddTabbedTextToParagraph(p, text0, new float[0], null, null, null);
            doc.Add(p);
            float left      = doc.GetLeftMargin();
            float right     = doc.GetRightMargin();
            float pageWidth = doc.GetPdfDocument().GetDefaultPageSize().GetWidth();

            float[] defaultStopPositions = new float[] { 0f, 50f, 100f, 150f, 200f, 250f, 300f, 350f, 400f, 450f, 500f
                                                         , pageWidth - left - right };
            DrawTabStopsPositions(defaultStopPositions, doc, 1, 0, 120);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }