/// <exception cref="System.Exception"/> private PdfDocument CreatePdfWithOverlappingTextVertical(String[] text1, String[] text2) { MemoryStream baos = new MemoryStream(); Document doc = new Document(new PdfDocument(new PdfWriter(baos).SetCompressionLevel(0))); float ystart = 500; float x = 50; float y = ystart; foreach (String text in text1) { doc.ShowTextAligned(text, x, y, TextAlignment.LEFT); y -= 25.0f; } y = ystart - 13; foreach (String text in text2) { doc.ShowTextAligned(text, x, y, TextAlignment.LEFT); y -= 25.0f; } doc.Close(); return(new PdfDocument(new PdfReader(new MemoryStream(baos.ToArray())))); }
/// <exception cref="System.Exception"/> protected internal virtual byte[] CreatePdfWithOverlappingTextHorizontal(String[] text1, String[] text2) { MemoryStream baos = new MemoryStream(); Document doc = new Document(new PdfDocument(new PdfWriter(baos).SetCompressionLevel(0))); float ystart = 500; float xstart = 50; float x = xstart; float y = ystart; foreach (String text in text1) { doc.ShowTextAligned(text, x, y, TextAlignment.LEFT); x += 70.0f; } x = xstart + 12; y = ystart; foreach (String text in text2) { doc.ShowTextAligned(text, x, y, TextAlignment.LEFT); x += 70.0f; } doc.Close(); return(baos.ToArray()); }
public virtual void ArtifactTest01() { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "artifactTest01.pdf")); pdfDocument.SetTagged(); Document document = new Document(pdfDocument); String watermarkText = "WATERMARK"; Paragraph watermark = new Paragraph(watermarkText); watermark.SetFontColor(new DeviceGray(0.75f)).SetFontSize(72); document.ShowTextAligned(watermark, PageSize.A4.GetWidth() / 2, PageSize.A4.GetHeight() / 2, 1, TextAlignment .CENTER, VerticalAlignment.MIDDLE, (float)(Math.PI / 4)); String textContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" + "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.\n" + "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.\n"; document.Add(new Paragraph(textContent + textContent + textContent)); document.Add(new Paragraph(textContent + textContent + textContent)); document.Close(); CompareResult("artifactTest01.pdf", "cmp_artifactTest01.pdf"); }
public virtual void ShowTextAlignedOnFlushedPageTest01() { NUnit.Framework.Assert.That(() => { String outFileName = destinationFolder + "showTextAlignedOnFlushedPageTest01.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document doc = new Document(pdfDoc); Paragraph p = new Paragraph(); for (int i = 0; i < 1000; ++i) { p.Add("abcdefghijklkmnopqrstuvwxyz"); } doc.Add(p); // First page will be flushed by now, because immediateFlush is set to false by default. int pageNumberToDrawTextOn = 1; doc.ShowTextAligned(new Paragraph("Hello Bruno on page 1!"), 36, 36, pageNumberToDrawTextOn, TextAlignment .LEFT, VerticalAlignment.TOP, 0); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(PdfException.CannotDrawElementsOnAlreadyFlushedPages)) ; }
public virtual void ShowTextAlignedTest02() { String outFileName = destinationFolder + "showTextAlignedTest02.pdf"; String cmpFileName = sourceFolder + "cmp_showTextAlignedTest02.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document document = new Document(pdfDocument); String watermarkText = "WATERMARK"; Paragraph watermark = new Paragraph(watermarkText); watermark.SetFontColor(new DeviceGray(0.75f)).SetFontSize(72); document.ShowTextAligned(watermark, PageSize.A4.GetWidth() / 2, PageSize.A4.GetHeight() / 2, 1, TextAlignment .CENTER, VerticalAlignment.MIDDLE, (float)(Math.PI / 4)); String textContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.\n" + "Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.\n" + "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.\n"; document.Add(new Paragraph(textContent + textContent + textContent)); document.Add(new Paragraph(textContent + textContent + textContent)); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void ShowTextAlignedTest01() { String outFileName = destinationFolder + "showTextAlignedTest01.pdf"; String cmpFileName = sourceFolder + "cmp_showTextAlignedTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); pdfDocument.AddNewPage(); PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage()); String text = "textapqgaPQGatext"; float width = 200; float x; float y; y = 700; x = 115; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 * 1 )); x = 300; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.MIDDLE, 0); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 * 3 )); x = 485; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.TOP, 0); document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.TOP, (float)(Math.PI / 6 * 5)); y = 400; x = 115; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 * 2)); x = 300; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 * 4)); x = 485; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.TOP, 0); document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.TOP, (float)(Math.PI / 6 * 8) ); y = 100; x = 115; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, 0); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 * 9)); x = 300; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, 0); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 * 7)); x = 485; DrawCross(canvas, x, y); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.TOP, 0); document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.TOP, (float)(Math.PI / 6 * 6)); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }