本文整理汇总了Java中com.lowagie.text.pdf.PdfContentByte.restoreState方法的典型用法代码示例。如果您正苦于以下问题:Java PdfContentByte.restoreState方法的具体用法?Java PdfContentByte.restoreState怎么用?Java PdfContentByte.restoreState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.restoreState方法的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: restoreState
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void restoreState(int index, PdfContentByte cb) {
int pops;
if (index < 0)
pops = Math.min(-index, savedStates.size());
else
pops = Math.max(savedStates.size() - index, 0);
if (pops == 0)
return;
MetaState state = null;
while (pops-- != 0) {
cb.restoreState();
state = (MetaState)savedStates.pop();
}
setMetaState(state);
}
示例12: 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();
}
}
示例13: 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();
}
示例14: cleanup
import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void cleanup(PdfContentByte cb) {
int k = savedStates.size();
while (k-- > 0)
cb.restoreState();
}
示例15: 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();
}