本文整理汇总了Java中com.lowagie.text.pdf.PdfContentByte.showTextAligned方法的典型用法代码示例。如果您正苦于以下问题:Java PdfContentByte.showTextAligned方法的具体用法?Java PdfContentByte.showTextAligned怎么用?Java PdfContentByte.showTextAligned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.showTextAligned方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
* Print footer string on each page
* @param writer
* @param document
*/
public void onEndPage(PdfWriter writer, Document document) {
if(getDateTime() == null) {
setDateTime(new Date());
}
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()),
document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()),
document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
(document.left() + document.right()) / 2, 20, 0);
cb.endText();
return;
}
示例2: onStartPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
* @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
*/
public void onStartPage(PdfWriter writer, Document document) {
if (writer.getPageNumber() < 3) {
PdfContentByte cb = writer.getDirectContentUnder();
cb.saveState();
cb.setColorFill(Color.pink);
cb.beginText();
cb.setFontAndSize(helv, 48);
cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
cb.endText();
cb.restoreState();
}
}
示例3: footer
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void footer() {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
Date now = new Date();
String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
if (promoTxt == null) {
promoTxt = new String();
}
String strFooter = promoTxt + " " + formatter.format(now);
float textBase = document.bottom();
cb.beginText();
cb.setFontAndSize(font.getBaseFont(), FONTSIZE);
Rectangle page = document.getPageSize();
float width = page.getWidth();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 20, 0);
strFooter = "-" + writer.getPageNumber() + "-";
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 10, 0);
cb.endText();
cb.restoreState();
}
示例4: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void onEndPage(PdfWriter writer, Document document) {
//Footer contains page numbers and date printed on all pages
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String strFooter = promoTxt + " " + formatter.format(now);
float textBase = document.bottom();
cb.beginText();
cb.setFontAndSize(font.getBaseFont(), FONTSIZE);
Rectangle page = document.getPageSize();
float width = page.getWidth();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 20, 0);
strFooter = "-" + writer.getPageNumber() + "-";
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 10, 0);
cb.endText();
cb.restoreState();
}
示例5: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void onEndPage( PdfWriter writer, Document document ) {
//Footer contains page numbers and date printed on all pages
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String strFooter = promoTxt + " " + formatter.format(now);
float textBase = document.bottom();
cb.beginText();
cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
Rectangle page = document.getPageSize();
float width = page.getWidth();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);
strFooter = "-" + writer.getPageNumber() + "-";
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);
cb.endText();
cb.restoreState();
}
示例6: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
* Adds promo text, date and current page number to each page
*
* @param writer
* @param document
*/
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
float textBase = document.bottom() - getBaseOffset();
float width = document.getPageSize().getWidth();
float center = width / 2.0f;
cb.beginText();
cb.setFontAndSize(getFont(), getFontSize());
cb.setTextMatrix(document.left(), textBase);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, center, textBase, 0);
cb.endText();
cb.restoreState();
}
示例7: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String text = "Page " + writer.getPageNumber() + " of ";
// height where text starts
float textBase = document.bottom() - getBaseOffset();
float textSize = getFont().getWidthPoint(text, getFontSize());
float width = document.getPageSize().getWidth();
float center = width / 2.0f;
cb.beginText();
cb.setFontAndSize(getFont(), getFontSize());
cb.setTextMatrix(document.left(), textBase);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, center, textBase, 0);
cb.endText();
cb.addTemplate(total, center + (textSize / 2.0f), textBase);
cb.restoreState();
}
示例8: footer
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void footer() {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
Date now = new Date();
String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
if( promoTxt == null ) {
promoTxt = new String();
}
String strFooter = promoTxt + " " + formatter.format(now);
float textBase = document.bottom();
cb.beginText();
cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
Rectangle page = document.getPageSize();
float width = page.getWidth();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);
strFooter = "-" + writer.getPageNumber() + "-";
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);
cb.endText();
cb.restoreState();
}
示例9: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void onEndPage( PdfWriter writer, Document document ) {
//Footer contains page numbers and date printed on all pages
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String strFooter = promoTxt + " " + formatter.format(now);
float textBase = document.bottom();
cb.beginText();
cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
Rectangle page = document.getPageSize();
float width = page.getWidth();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);
strFooter = "-" + writer.getPageNumber() + "-";
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);
cb.endText();
cb.restoreState();
}
示例10: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void onEndPage(PdfWriter writer, Document document){
try {
Rectangle page = document.getPageSize();
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
int pageNum = document.getPageNumber();
float width = page.getWidth();
float height = page.getHeight();
//add patient name header for every page but the first.
if (pageNum > 1){
cb.beginText();
cb.setFontAndSize(bf, 8);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, handler.getPatientName(), 575, height - 30, 0);
cb.endText();
}
//add footer for every page
cb.beginText();
cb.setFontAndSize(bf, 8);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "-"+pageNum+"-", width/2, 30, 0);
cb.endText();
// add promotext as footer if it is enabled
if ( OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null){
cb.beginText();
cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA,BaseFont.CP1252,BaseFont.NOT_EMBEDDED), 6);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), width/2, 19, 0);
cb.endText();
}
// throw any exceptions
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
示例11: main
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
*/
@Test
public void main() throws Exception {
// we create a reader for a certain document
PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR +"ChapterSection.pdf");
int n = reader.getNumberOfPages();
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader,PdfTestBase.getOutputStream("watermark_pagenumbers.pdf"));
// adding some metadata
HashMap<String, String> moreInfo = new HashMap<String, String>();
moreInfo.put("Author", "Bruno Lowagie");
stamp.setMoreInfo(moreInfo);
// adding content to each page
int i = 0;
PdfContentByte under;
PdfContentByte over;
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR +"watermark.jpg");
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
// watermark under the existing page
under = stamp.getUnderContent(i);
under.addImage(img);
// text over the existing page
over = stamp.getOverContent(i);
over.beginText();
over.setFontAndSize(bf, 18);
over.setTextMatrix(30, 30);
over.showText("page " + i);
over.setFontAndSize(bf, 32);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE", 230, 430, 45);
over.endText();
}
// adding an extra page
stamp.insertPage(1, PageSize.A4);
over = stamp.getOverContent(1);
over.beginText();
over.setFontAndSize(bf, 18);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
over.endText();
// adding a page from another document
PdfReader reader2 = new PdfReader(PdfTestBase.RESOURCES_DIR +"SimpleAnnotations1.pdf");
under = stamp.getUnderContent(1);
under.addTemplate(stamp.getImportedPage(reader2, 3), 1, 0, 0, 1, 0, 0);
// closing PdfStamper will generate the new PDF file
stamp.close();
}
示例12: main
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
* Reads the pages of an existing PDF file and puts 2 pages from the
* existing doc into one of the new doc.
*/
@Test
public void main() throws Exception {
// we create a reader for a certain document
PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR + "ChapterSection.pdf");
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
// we retrieve the size of the first page
Rectangle psize = reader.getPageSize(1);
float width = psize.getHeight();
float height = psize.getWidth();
// step 1: creation of a document-object
Document document = new Document(new Rectangle(width, height));
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("2on1.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
PdfContentByte cb = writer.getDirectContent();
int i = 0;
int p = 0;
while (i < n) {
document.newPage();
p++;
i++;
PdfImportedPage page1 = writer.getImportedPage(reader, i);
cb.addTemplate(page1, .5f, 0, 0, .5f, 60, 120);
if (i < n) {
i++;
PdfImportedPage page2 = writer.getImportedPage(reader, i);
cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2 + 60, 120);
}
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 14);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "page " + p + " of " + ((n / 2) + (n % 2 > 0 ? 1 : 0)),
width / 2, 40, 0);
cb.endText();
}
// step 5: we close the document
document.close();
}
示例13: main
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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();
}
示例14: main
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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();
}
示例15: main
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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();
}