本文整理汇总了Java中com.lowagie.text.pdf.PdfTemplate.setFontAndSize方法的典型用法代码示例。如果您正苦于以下问题:Java PdfTemplate.setFontAndSize方法的具体用法?Java PdfTemplate.setFontAndSize怎么用?Java PdfTemplate.setFontAndSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfTemplate
的用法示例。
在下文中一共展示了PdfTemplate.setFontAndSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTextVertical
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception {
if (text==null) return;
if (text.indexOf("<span")>=0)
text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
Font font = PdfFont.getFont(bold);
BaseFont bf = font.getBaseFont();
float width = bf.getWidthPoint(text, font.getSize());
PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
template.beginText();
template.setColorFill(Color.BLACK);
template.setFontAndSize(bf, font.getSize());
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(font.getSize() + 2);
//make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(270);
//embed the image in a Chunk
Chunk ck = new Chunk(img, 0, 0);
if (cell.getPhrase()==null) {
cell.setPhrase(new Paragraph(ck));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
} else {
cell.getPhrase().add(ck);
}
}
示例2: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* PdfTemplates can be wrapped in an Image.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle rect = new Rectangle(PageSize.A4);
rect.setBackgroundColor(new Color(238, 221, 88));
Document document = new Document(rect, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
template.sanityCheck();
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
Chunk ck = new Chunk(img, 0, 0);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
Paragraph p1 = new Paragraph("This is a template ");
p1.add(ck);
p1.add(" just here.");
p1.setLeading(img.getScaledHeight() * 1.1f);
document.add(p1);
document.add(table);
Paragraph p2 = new Paragraph("More templates ");
p2.setLeading(img.getScaledHeight() * 1.1f);
p2.setAlignment(Element.ALIGN_JUSTIFIED);
img.scalePercent(70);
for (int k = 0; k < 20; ++k)
p2.add(ck);
document.add(p2);
// step 5: we close the document
document.close();
}
示例3: 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();
}
示例4: 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();
}
示例5: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Example with vertical text in Cells.
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("VerticalText.pdf"));
// step3
document.open();
// step4
// make a PdfTemplate with the vertical text
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
// make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
document.add(table);
// step5
document.close();
}
示例6: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* PdfTemplates can be wrapped in an Image.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("PdfTemplate wrapped in an Image");
// step 1: creation of a document-object
Rectangle rect = new Rectangle(PageSize.A4);
rect.setBackgroundColor(new Color(238, 221, 88));
Document document = new Document(rect, 50, 50, 50, 50);
try {
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "templateImages.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
template.sanityCheck();
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
Chunk ck = new Chunk(img, 0, 0);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
Paragraph p1 = new Paragraph("This is a template ");
p1.add(ck);
p1.add(" just here.");
p1.setLeading(img.getScaledHeight() * 1.1f);
document.add(p1);
document.add(table);
Paragraph p2 = new Paragraph("More templates ");
p2.setLeading(img.getScaledHeight() * 1.1f);
p2.setAlignment(Element.ALIGN_JUSTIFIED);
img.scalePercent(70);
for (int k = 0; k < 20; ++k)
p2.add(ck);
document.add(p2);
// step 5: we close the document
document.close();
} catch (Exception de) {
System.err.println(de.getMessage());
}
}
示例7: 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();
}
示例8: 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();
}
示例9: main
import com.lowagie.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
* Example with vertical text in Cells.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Vertical text in cells");
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "VerticalText.pdf"));
// step3
document.open();
// step4
// make a PdfTemplate with the vertical text
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
// make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
// step5
document.close();
}