public virtual void SeveralTabsInRowTest() { String fileName = "severalTabsInRowTest.pdf"; String outFileName = destinationFolder + fileName; String cmpFileName = sourceFolder + "cmp_" + fileName; Document doc = InitDocument(outFileName); float tabInterval = doc.GetPdfDocument().GetDefaultPageSize().GetWidth() / 8; float[] positions = new float[] { tabInterval * 2, tabInterval * 4, tabInterval * 6 }; TabAlignment[] alignments = new TabAlignment[] { TabAlignment.RIGHT, TabAlignment.CENTER, TabAlignment.CENTER }; // Drawable[] leaders = {null, null, null}; ILineDrawer[] leaders = new ILineDrawer[] { new DottedLine(), new DashedLine(.5f), new SolidLine(.5f) }; Paragraph p = new Paragraph(); p.SetFontSize(8); IList <TabStop> tabStops = new List <TabStop>(); for (int i = 0; i < positions.Length; ++i) { TabStop tabStop = new TabStop(positions[i], alignments[i], leaders[i]); tabStops.Add(tabStop); } p.AddTabStops(tabStops); p.Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttt").Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n" ); p.Add(new Tab()).Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n" ); p.Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttt").Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttt" ); doc.Add(p); DrawTabStopsPositions(positions, doc, 1, 0, 120); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + outFileName)); }
public virtual void AnchorTabStopsTest01() { String fileName = "anchorTabStopsTest01.pdf"; String outFileName = destinationFolder + fileName; String cmpFileName = sourceFolder + "cmp_" + fileName; Document doc = InitDocument(outFileName); float tabInterval = doc.GetPdfDocument().GetDefaultPageSize().GetWidth() / 8; float[] positions1 = new float[] { tabInterval * 2, tabInterval * 3, tabInterval * 4, tabInterval * 5, tabInterval * 6 }; TabAlignment[] alignments1 = new TabAlignment[] { TabAlignment.ANCHOR, TabAlignment.CENTER, TabAlignment.ANCHOR , TabAlignment.RIGHT, TabAlignment.ANCHOR }; ILineDrawer[] leaders1 = new ILineDrawer[] { new DottedLine(), null, new DashedLine(.5f), null, new SolidLine (.5f) }; char?[] anchors1 = new char?[] { ' ', null, '\\', null, '.' }; Paragraph p = new Paragraph(); p.SetFontSize(8); AddTabbedTextToParagraph(p, text2, positions1, alignments1, leaders1, anchors1); doc.Add(p); DrawTabStopsPositions(positions1, doc, 1, 0, 120); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + outFileName)); }
public virtual void LinkTest02() { String outFileName = destinationFolder + "linkTest02.pdf"; String cmpFileName = sourceFolder + "cmp_linkTest02.pdf"; FileStream file = new FileStream(outFileName, FileMode.Create); PdfWriter writer = new PdfWriter(file); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); doc.Add(new AreaBreak()).Add(new AreaBreak()); PdfArray array = new PdfArray(); array.Add(doc.GetPdfDocument().GetPage(1).GetPdfObject()); array.Add(PdfName.XYZ); array.Add(new PdfNumber(36)); array.Add(new PdfNumber(100)); array.Add(new PdfNumber(1)); PdfDestination dest = PdfDestination.MakeDestination(array); PdfAction action = PdfAction.CreateGoTo(dest); Link link = new Link("TestLink", action); doc.Add(new Paragraph(link)); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void FixedPositioningTest02() { String outFileName = destinationFolder + "fixedPositioningTest02.pdf"; String cmpFileName = sourceFolder + "cmp_fixedPositioningTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); document.GetPdfDocument().AddNewPage(); new PdfCanvas(document.GetPdfDocument().GetPage(1)).SetFillColor(Color.BLACK).Rectangle(300, 300, 100, 100 ).Fill().Release(); Paragraph p = new Paragraph("Hello").SetBackgroundColor(Color.BLUE).SetHeight(100).SetFixedPosition(1, 300 , 300, 100); document.Add(p); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
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(); }
public virtual void FixedPositioningTest04() { String outFileName = destinationFolder + "fixedPositioningTest04.pdf"; String cmpFileName = sourceFolder + "cmp_fixedPositioningTest04.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); document.GetPdfDocument().AddNewPage(); Div div = new Div().SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetHeight(100).SetFixedPosition(1, 300, 300, 100).Add(new Paragraph("Hello, this is fairly long text. Lorem ipsum dolor sit amet, " + "consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna " + "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex " + "ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " + "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum.").SetMargin(0)); document.Add(div); new PdfCanvas(document.GetPdfDocument().GetPage(1)).SetStrokeColor(ColorConstants.BLACK).Rectangle(300, 300 , 100, 100).Stroke().Release(); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void SimpleTabStopsTest() { String fileName = "simpleTabStopsTest.pdf"; String outFileName = destinationFolder + fileName; String cmpFileName = sourceFolder + "cmp_" + fileName; Document doc = InitDocument(outFileName); float tabInterval = doc.GetPdfDocument().GetDefaultPageSize().GetWidth() / 8; //left alignments float[] positions1 = new float[] { tabInterval * 2, tabInterval * 4, tabInterval * 5 }; TabAlignment[] alignments1 = new TabAlignment[] { TabAlignment.LEFT, TabAlignment.LEFT, TabAlignment.LEFT }; ILineDrawer[] leaders1 = new ILineDrawer[] { null, null, null }; char?[] anchors1 = new char?[] { null, null, null }; Paragraph p = new Paragraph(); p.SetFontSize(8); AddTabbedTextToParagraph(p, text1, positions1, alignments1, leaders1, anchors1); doc.Add(p); doc.Add(new Paragraph("\n")); //right alignments float[] positions2 = new float[] { tabInterval * 3, tabInterval * 4, tabInterval * 6 }; TabAlignment[] alignments2 = new TabAlignment[] { TabAlignment.RIGHT, TabAlignment.RIGHT, TabAlignment.RIGHT }; ILineDrawer[] leaders2 = new ILineDrawer[] { null, null, null }; char?[] anchors2 = new char?[] { null, null, null }; p = new Paragraph(); p.SetFontSize(8); AddTabbedTextToParagraph(p, text1, positions2, alignments2, leaders2, anchors2); doc.Add(p); doc.Add(new Paragraph("\n")); //center alignments float[] positions3 = new float[] { tabInterval * 3, tabInterval * 4, tabInterval * 6 }; TabAlignment[] alignments3 = new TabAlignment[] { TabAlignment.CENTER, TabAlignment.CENTER, TabAlignment.CENTER }; ILineDrawer[] leaders3 = new ILineDrawer[] { null, null, null }; char?[] anchors3 = new char?[] { null, null, null }; p = new Paragraph(); p.SetFontSize(8); AddTabbedTextToParagraph(p, text1, positions3, alignments3, leaders3, anchors3); doc.Add(p); DrawTabStopsPositions(positions1, doc, 1, 0, 120); DrawTabStopsPositions(positions2, doc, 1, 125, 95); DrawTabStopsPositions(positions3, doc, 1, 235, 95); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
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")); }
public virtual void LinkTest03() { String outFileName = destinationFolder + "linkTest03.pdf"; String cmpFileName = sourceFolder + "cmp_linkTest03.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document doc = new Document(pdfDoc); PdfArray array = new PdfArray(); array.Add(doc.GetPdfDocument().AddNewPage().GetPdfObject()); array.Add(PdfName.XYZ); array.Add(new PdfNumber(36)); array.Add(new PdfNumber(100)); array.Add(new PdfNumber(1)); PdfDestination dest = PdfDestination.MakeDestination(array); Link link = new Link("TestLink", dest); link.SetAction(PdfAction.CreateURI("http://itextpdf.com/", false)); doc.Add(new Paragraph(link)); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }