private void drawCircle() { _template.SetLineWidth(1f); _template.Circle(_circleCenterX0, _circleCenterY0, _circleRadius); _template.SetColorStroke(BaseColor.GRAY); _template.Stroke(); _template.SetLineWidth(0f); }
public void ImageTaggingExpansionTest() { String filename = "TextExpansionTest.pdf"; Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(DEST_FOLDER + filename, FileMode.Create)); writer.SetTagged(); doc.Open(); Chunk c1 = new Chunk("ABC"); c1.SetTextExpansion("the alphabet"); Paragraph p1 = new Paragraph(); p1.Add(c1); doc.Add(p1); PdfTemplate t = writer.DirectContent.CreateTemplate(6, 6); t.SetLineWidth(1f); t.Circle(3f, 3f, 1.5f); t.SetGrayFill(0); t.FillStroke(); Image i = Image.GetInstance(t); Chunk c2 = new Chunk(i, 100, -100); doc.Add(c2); Chunk c3 = new Chunk("foobar"); c3.SetTextExpansion("bar bar bar"); Paragraph p3 = new Paragraph(); p3.Add(c3); doc.Add(p3); doc.Close(); CompareTool compareTool = new CompareTool(); String error = compareTool.CompareByContent(DEST_FOLDER + filename, SOURCE_FOLDER + "cmp_" + filename, DEST_FOLDER, "diff_"); if (error != null) { Assert.Fail(error); } }
public Chap1003() { Console.WriteLine("Chapter 10 example 3: Templates"); // 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("Chap1003.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; // we create a PdfTemplate PdfTemplate template = cb.CreateTemplate(500, 200); // we add some graphics template.MoveTo(0, 200); template.LineTo(500, 0); template.Stroke(); template.SetRGBColorStrokeF(255f, 0f, 0f); template.Circle(250f, 100f, 80f); template.Stroke(); // we add some text template.BeginText(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); template.SetFontAndSize(bf, 12); template.SetTextMatrix(100, 100); template.ShowText("Text at the position 100,100 (relative to the template!)"); template.EndText(); // we add the template on different positions cb.AddTemplate(template, 0, 0); cb.AddTemplate(template, 0, 1, -1, 0, 500, 200); cb.AddTemplate(template, .5f, 0, 0, .5f, 100, 400); // we go to a new page document.NewPage(); cb.AddTemplate(template, 0, 400); cb.AddTemplate(template, 2, 0, 0, 2, -200, 400); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); }