本文整理汇总了Java中com.lowagie.text.pdf.PdfTemplate.stroke方法的典型用法代码示例。如果您正苦于以下问题:Java PdfTemplate.stroke方法的具体用法?Java PdfTemplate.stroke怎么用?Java PdfTemplate.stroke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfTemplate
的用法示例。
在下文中一共展示了PdfTemplate.stroke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templates.pdf"));
// step 3: we open the document
document.open();
// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
// 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();
template.sanityCheck();
// 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);
cb.sanityCheck();
// step 5: we close the document
document.close();
}
示例2: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Creates a PDF document with shapes, lines and text at specific X and Y coordinates.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "XandY.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\", 10\")", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 5\")", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 7\")", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\", 2\")", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\", 4\")", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例3: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Adding a template using different transformation matrices.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("transformations.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(120, 120);
// we add some graphics
template.moveTo(30, 10);
template.lineTo(90, 10);
template.lineTo(90, 80);
template.lineTo(110, 80);
template.lineTo(60, 110);
template.lineTo(10, 80);
template.lineTo(30, 80);
template.closePath();
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 0, 0);
cb.addTemplate(template, 0, 1, -1, 0, 200, 600);
cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
cb.sanityCheck();
// we go to a new page
document.newPage();
cb.addTemplate(template, 0, 500);
cb.addTemplate(template, 2, 0, -1, 2, 200, 300);
cb.sanityCheck();
// step 5: we close the document
document.close();
}
示例4: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Changes the default coordinate system so that the origin is in the upper left corner
* instead of the lower left corner.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "upsidedown.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
cb.concatCTM(1f, 0f, 0f, -1f, 0f, PageSize.A4.getHeight());
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\", 10\")", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 5\")", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 7\")", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\", 2\")", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\", 4\")", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例5: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Changes the transformation matrix with AffineTransform.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("affinetransformation.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
cb.transform(AffineTransform.getScaleInstance(1.2, 0.75));
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
"(3\" * 1.2, 10\" * .75)", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
"(5\" * 1.2, 5\" * .75)", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
"(5\" * 1.2, 7\" * .75)", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
"(1\" * 1.2, 2\" * .75)", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
"(2\" * 1.2, 4\" * .75)", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
// step 5: we close the document
document.close();
}
示例6: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Draws the iText logo.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("logo.pdf"));
// step 3: we open the document
document.open();
// step 4:
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(500, 200);
template.setLineWidth(2f);
template.rectangle(2.5f, 2.5f, 495f, 195f);
template.stroke();
template.setLineWidth(12f);
template.arc(40f - (float) Math.sqrt(12800),
120f + (float) Math.sqrt(12800),
200f - (float) Math.sqrt(12800),
-40f + (float) Math.sqrt(12800), 281.25f, 33.75f);
template.arc(40f, 120f, 200f, -40f, 90f, 45f);
template.stroke();
template.setLineCap(1);
template.setLineWidth(12f);
template.arc(80f, 40f, 160f, 120f, 90f, 180f);
template.arc(115f, 75f, 125f, 85f, 0f, 360f);
template.stroke();
template.beginText();
template.setFontAndSize(bf, 180);
template.setRGBColorFill(0xFF, 0x00, 0x00);
template.showTextAligned(PdfContentByte.ALIGN_LEFT, "T", 125f, 35f, 0f);
template.resetRGBColorFill();
template.showTextAligned(PdfContentByte.ALIGN_LEFT, "ext", 220f, 35f,
0f);
template.endText();
template.sanityCheck();
cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
cb.addTemplate(template, 0.25f, 0, 0, 0.25f, 100, 100);
cb.sanityCheck();
// step 5: we close the document
document.close();
}
示例7: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Creates a document with some goto actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Destinations.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the destinations
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
// we add the template on different positions
cb.addTemplate(template, 287, 787);
cb.addTemplate(template, 187, 487);
cb.addTemplate(template, 487, 287);
cb.addTemplate(template, 87, 87);
// we define the destinations
PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
// we define the outlines
PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
new PdfOutline(out1, d3, "sub 2");
new PdfOutline(out2, d4, "sub 2.1");
new PdfOutline(out2, d5, "sub 2.2");
// step 5: we close the document
document.close();
}
示例8: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Demonstrates the use of ColumnText.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("columnirregular.pdf"));
// step 3: we open the document
document.open();
// step 4:
// we grab the contentbyte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
PdfTemplate t = cb.createTemplate(600, 800);
Image caesar = Image.getInstance(PdfTestBase.RESOURCES_DIR + "caesar_coin.jpg");
cb.addImage(caesar, 100, 0, 0, 100, 260, 595);
t.setGrayFill(0.75f);
t.moveTo(310, 112);
t.lineTo(280, 60);
t.lineTo(340, 60);
t.closePath();
t.moveTo(310, 790);
t.lineTo(310, 710);
t.moveTo(310, 580);
t.lineTo(310, 122);
t.stroke();
cb.addTemplate(t, 0, 0);
ColumnText ct = new ColumnText(cb);
ct.addText(new Phrase(
"GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n",
FontFactory.getFont(FontFactory.HELVETICA, 12)));
ct.addText(new Phrase(
"[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n",
FontFactory.getFont(FontFactory.HELVETICA, 12)));
ct.addText(new Phrase(
"Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n",
FontFactory.getFont(FontFactory.HELVETICA, 12)));
ct.addText(new Phrase(
"His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n",
FontFactory.getFont(FontFactory.HELVETICA, 12)));
ct.addText(new Phrase(
"Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
FontFactory.getFont(FontFactory.HELVETICA, 12)));
float[] left1 = { 70, 790, 70, 60 };
float[] right1 = { 300, 790, 300, 700, 240, 700, 240, 590, 300, 590, 300, 106, 270, 60 };
float[] left2 = { 320, 790, 320, 700, 380, 700, 380, 590, 320, 590, 320, 106, 350, 60 };
float[] right2 = { 550, 790, 550, 60 };
int status = 0;
int column = 0;
while ((status & ColumnText.NO_MORE_TEXT) == 0) {
if (column == 0) {
ct.setColumns(left1, right1);
column = 1;
} else {
ct.setColumns(left2, right2);
column = 0;
}
status = ct.go();
ct.setYLine(790);
ct.setAlignment(Element.ALIGN_JUSTIFIED);
status = ct.go();
if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0)) {
document.newPage();
cb.addTemplate(t, 0, 0);
cb.addImage(caesar, 100, 0, 0, 100, 260, 595);
}
}
// step 5: we close the document
document.close();
}
示例9: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Creates a PDF document with shapes, lines and text at specific X and Y
* coordinates.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("X and Y coordinate system");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "XandY.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\", 10\")", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 5\")", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 7\")", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\", 2\")", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\", 4\")", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例10: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Changes the transformation matrix with AffineTransform.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("Affine Transformation");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "affinetransformation.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
cb.transform(AffineTransform.getScaleInstance(1.2, 0.75));
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\" * 1.2, 10\" * .75)", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\" * 1.2, 5\" * .75)", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\" * 1.2, 7\" * .75)", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\" * 1.2, 2\" * .75)", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\" * 1.2, 4\" * .75)", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例11: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Adding a template using different transformation matrices.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("Transformations");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "transformations.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(120, 120);
// we add some graphics
template.moveTo(30, 10);
template.lineTo(90, 10);
template.lineTo(90, 80);
template.lineTo(110, 80);
template.lineTo(60, 110);
template.lineTo(10, 80);
template.lineTo(30, 80);
template.closePath();
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 0, 0);
cb.addTemplate(template, 0, 1, -1, 0, 200, 600);
cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
cb.sanityCheck();
// we go to a new page
document.newPage();
cb.addTemplate(template, 0, 500);
cb.addTemplate(template, 2, 0, -1, 2, 200, 300);
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例12: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Changes the default coordinate system so that the origin is in the upper
* left corner instead of the lower left corner.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("UpsideDown");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "upsidedown.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
cb.concatCTM(1f, 0f, 0f, -1f, 0f, PageSize.A4.getHeight());
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the coordinates
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
template.sanityCheck();
// we add the template on different positions
cb.addTemplate(template, 216 - 13, 720 - 13);
cb.addTemplate(template, 360 - 13, 360 - 13);
cb.addTemplate(template, 360 - 13, 504 - 13);
cb.addTemplate(template, 72 - 13, 144 - 13);
cb.addTemplate(template, 144 - 13, 288 - 13);
cb.moveTo(216, 720);
cb.lineTo(360, 360);
cb.lineTo(360, 504);
cb.lineTo(72, 144);
cb.lineTo(144, 288);
cb.stroke();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\", 10\")", 216 + 25, 720 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 5\")", 360 + 25, 360 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 7\")", 360 + 25, 504 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\", 2\")", 72 + 25, 144 + 5, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\", 4\")", 144 + 25, 288 + 5, 0);
cb.endText();
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例13: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Draws the iText logo.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("iText logo");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "logo.pdf"));
// step 3: we open the document
document.open();
// step 4:
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(500, 200);
template.setLineWidth(2f);
template.rectangle(2.5f, 2.5f, 495f, 195f);
template.stroke();
template.setLineWidth(12f);
template.arc(40f - (float) Math.sqrt(12800), 120f + (float) Math.sqrt(12800), 200f - (float) Math
.sqrt(12800), -40f + (float) Math.sqrt(12800), 281.25f, 33.75f);
template.arc(40f, 120f, 200f, -40f, 90f, 45f);
template.stroke();
template.setLineCap(1);
template.setLineWidth(12f);
template.arc(80f, 40f, 160f, 120f, 90f, 180f);
template.arc(115f, 75f, 125f, 85f, 0f, 360f);
template.stroke();
template.beginText();
template.setFontAndSize(bf, 180);
template.setRGBColorFill(0xFF, 0x00, 0x00);
template.showTextAligned(PdfContentByte.ALIGN_LEFT, "T", 125f, 35f, 0f);
template.resetRGBColorFill();
template.showTextAligned(PdfContentByte.ALIGN_LEFT, "ext", 220f, 35f, 0f);
template.endText();
template.sanityCheck();
cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
cb.addTemplate(template, 0.25f, 0, 0, 0.25f, 100, 100);
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例14: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("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 FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "templates.pdf"));
// step 3: we open the document
document.open();
// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
// 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();
template.sanityCheck();
// 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);
cb.sanityCheck();
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例15: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Creates a document with some goto actions.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Destinations");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "Destinations.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
// we create a PdfTemplate
PdfTemplate template = cb.createTemplate(25, 25);
// we add some crosses to visualize the destinations
template.moveTo(13, 0);
template.lineTo(13, 25);
template.moveTo(0, 13);
template.lineTo(50, 13);
template.stroke();
// we add the template on different positions
cb.addTemplate(template, 287, 787);
cb.addTemplate(template, 187, 487);
cb.addTemplate(template, 487, 287);
cb.addTemplate(template, 87, 87);
// we define the destinations
PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
// we define the outlines
PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
new PdfOutline(out1, d3, "sub 2");
new PdfOutline(out2, d4, "sub 2.1");
new PdfOutline(out2, d5, "sub 2.2");
} catch (Exception de) {
de.printStackTrace();
}
// step 5: we close the document
document.close();
}