本文整理匯總了Java中com.lowagie.text.pdf.PdfContentByte.saveState方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte.saveState方法的具體用法?Java PdfContentByte.saveState怎麽用?Java PdfContentByte.saveState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.saveState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: main
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
@Test
public void main() throws Exception {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "shading.pdf"));
document.open();
PdfFunction function1 = PdfFunction.type2(writer, new float[] { 0, 1 },
null, new float[] { .929f, .357f, 1, .298f }, new float[] {
.631f, .278f, 1, .027f }, 1.048f);
PdfFunction function2 = PdfFunction.type2(writer, new float[] { 0, 1 },
null, new float[] { .929f, .357f, 1, .298f }, new float[] {
.941f, .4f, 1, .102f }, 1.374f);
PdfFunction function3 = PdfFunction.type3(writer, new float[] { 0, 1 },
null, new PdfFunction[] { function1, function2 },
new float[] { .708f }, new float[] { 1, 0, 0, 1 });
PdfShading shading = PdfShading.type3(writer,
new CMYKColor(0, 0, 0, 0),
new float[] { 0, 0, .096f, 0, 0, 1 }, null, function3,
new boolean[] { true, true });
PdfContentByte cb = writer.getDirectContent();
cb.moveTo(316.789f, 140.311f);
cb.curveTo(303.222f, 146.388f, 282.966f, 136.518f, 279.122f, 121.983f);
cb.lineTo(277.322f, 120.182f);
cb.curveTo(285.125f, 122.688f, 291.441f, 121.716f, 298.156f, 119.386f);
cb.lineTo(336.448f, 119.386f);
cb.curveTo(331.072f, 128.643f, 323.346f, 137.376f, 316.789f, 140.311f);
cb.clip();
cb.newPath();
cb.saveState();
cb.concatCTM(27.7843f, 0, 0, -27.7843f, 310.2461f, 121.1521f);
cb.paintShading(shading);
cb.restoreState();
cb.sanityCheck();
document.close();
}
示例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: draw
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
*/
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
canvas.saveState();
canvas.setLineWidth(lineWidth);
canvas.setLineCap(PdfContentByte.LINE_CAP_ROUND);
canvas.setLineDash(0, gap, gap / 2);
drawLine(canvas, llx, urx, y);
canvas.restoreState();
}
示例11: paintToPDF
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public void paintToPDF(JEditorPane jep,File file) {
try {
jep.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));
Document document = new Document();
FileOutputStream fos = new FileOutputStream(file);
PdfWriter writer = PdfWriter.getInstance(document, fos);
document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.concatCTM(1, 0, 0, 1, 0, 0);
DefaultFontMapper mapper = new DefaultFontMapper();
mapper.insertDirectory("c:/windows/fonts");
Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);
AffineTransform at = new AffineTransform();
at.translate(convertToPixels(20), convertToPixels(20));
at.scale(pixelToPoint, pixelToPoint);
g2.transform(at);
g2.setColor(Color.WHITE);
g2.fill(jep.getBounds());
Rectangle alloc = getVisibleEditorRect(jep);
jep.getUI().getRootView(jep).paint(g2, alloc);
g2.setColor(Color.BLACK);
g2.draw(jep.getBounds());
g2.dispose();
cb.restoreState();
document.close();
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: draw
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float)
*/
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) {
canvas.saveState();
drawLine(canvas, llx, urx, y);
canvas.restoreState();
}
示例13: saveState
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public void saveState(PdfContentByte cb) {
cb.saveState();
MetaState state = new MetaState(this);
savedStates.push(state);
}
示例14: main
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Changing the Graphics State with saveState() and restoreState().
*
*/
@Test
public void main() throws Exception {
// 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,
PdfTestBase.getOutputStream( "state.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();
cb.circle(260.0f, 500.0f, 250.0f);
cb.fill();
cb.saveState();
cb.setColorFill(Color.red);
cb.circle(260.0f, 500.0f, 200.0f);
cb.fill();
cb.saveState();
cb.setColorFill(Color.blue);
cb.circle(260.0f, 500.0f, 150.0f);
cb.fill();
cb.restoreState();
cb.circle(260.0f, 500.0f, 100.0f);
cb.fill();
cb.restoreState();
cb.circle(260.0f, 500.0f, 50.0f);
cb.fill();
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: onEndPage
import com.lowagie.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
*/
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
// write the headertable
table.setTotalWidth(document.right() - document.left());
table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
// compose the footer
String text = "Page " + writer.getPageNumber() + " of ";
float textSize = helv.getWidthPoint(text, 12);
float textBase = document.bottom() - 20;
cb.beginText();
cb.setFontAndSize(helv, 12);
// for odd pagenumbers, show the footer at the left
if ((writer.getPageNumber() & 1) == 1) {
cb.setTextMatrix(document.left(), textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(tpl, document.left() + textSize, textBase);
}
// for even numbers, show the footer at the right
else {
float adjust = helv.getWidthPoint("0", 12);
cb.setTextMatrix(document.right() - textSize - adjust, textBase);
cb.showText(text);
cb.endText();
cb.addTemplate(tpl, document.right() - adjust, textBase);
}
// draw a Rectangle around the page
cb.setColorStroke(Color.orange);
cb.setLineWidth(2);
cb.rectangle(20, 20, document.getPageSize().getWidth() - 40, document.getPageSize().getHeight() - 40);
cb.stroke();
// starting on page 3, a watermark with an Image that is made transparent
if (writer.getPageNumber() >= 3) {
cb.setGState(gstate);
cb.setColorFill(Color.red);
cb.beginText();
cb.setFontAndSize(helv, 48);
cb.showTextAligned(Element.ALIGN_CENTER, "Watermark Opacity " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
cb.endText();
try {
cb.addImage(headerImage, headerImage.getWidth(), 0, 0, headerImage.getHeight(), 440, 80);
}
catch(Exception e) {
throw new ExceptionConverter(e);
}
}
cb.restoreState();
cb.sanityCheck();
}