本文整理匯總了Java中com.lowagie.text.pdf.PdfContentByte.endText方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte.endText方法的具體用法?Java PdfContentByte.endText怎麽用?Java PdfContentByte.endText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.endText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setPageNumbers
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private void setPageNumbers() throws DocumentException, IOException {
int pages = getReader().getNumberOfPages();
int i = 0;
PdfContentByte overContent;
Rectangle pageSize = null;
BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
while (i < pages) {
i++;
overContent = getStamper().getOverContent(i);
pageSize = overContent.getPdfDocument().getPageSize();
overContent.beginText();
overContent.setFontAndSize(font, 9);
overContent.setTextMatrix(pageSize.getWidth() - 50, pageSize.getHeight() - 70);
overContent.showText("Page " + i + " of " + pages);
overContent.endText();
}
}
示例2: 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;
}
示例3: 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();
}
}
示例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: main
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Shading example.
*/
@Test
public void main() throws Exception {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("shading_pattern.pdf"));
document.open();
PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100,
Color.red, Color.cyan);
PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont(BaseFont.TIMES_BOLD,
BaseFont.WINANSI, false);
cb.setShadingFill(shadingPattern);
cb.beginText();
cb.setTextMatrix(100, 100);
cb.setFontAndSize(bf, 40);
cb.showText("Look at this text!");
cb.endText();
PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50,
300, 500, 100, new Color(255, 247, 148), new Color(247, 138,
107), false, false);
cb.paintShading(shadingR);
cb.sanityCheck();
document.close();
}
示例11: 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);
}
}
示例12: 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();
}
示例13: 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();
}
示例14: 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();
}
示例15: 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();
}