本文整理汇总了Java中com.lowagie.text.Rectangle类的典型用法代码示例。如果您正苦于以下问题:Java Rectangle类的具体用法?Java Rectangle怎么用?Java Rectangle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于com.lowagie.text包,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportVectorGraphics
import com.lowagie.text.Rectangle; //导入依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
Component component = printableComponent.getExportComponent();
int width = component.getWidth();
int height = component.getHeight();
try (FileOutputStream fs = new FileOutputStream(outputFile)) {
switch (formatName) {
case PDF:
// create pdf document with slightly increased width and height
// (otherwise the image gets cut off)
Document document = new Document(new Rectangle(width + 5, height + 5));
PdfWriter writer = PdfWriter.getInstance(document, fs);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
component.print(g2);
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
break;
case SVG:
exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
break;
case EPS:
exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
break;
default:
// cannot happen
break;
}
} catch (Exception e) {
throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
"error.image_export.export_failed"), e);
}
}
示例2: write
import com.lowagie.text.Rectangle; //导入依赖的package包/类
public void write(PDFDocument document, PdfPTable tabla) throws DocumentException {
com.lowagie.text.List list = new com.lowagie.text.List(false,10f);
list.setListSymbol(new Chunk("\u2022"));
PdfPCell cell = new PdfPCell();
if(!titulo.equals(""))
{
cell.addElement(new Phrase(titulo,document.getContext().getDefaultFont()));
}
for(int i=0; i<campos.size(); i++)
{
list.add(new ListItem((String)campos.get(i),document.getContext().getDefaultFont()));
}
cell.addElement(list);
cell.setPaddingLeft(30f);
cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
cell.setColspan(2);
tabla.addCell(cell);
}
示例3: close
import com.lowagie.text.Rectangle; //导入依赖的package包/类
@Override
public void close() throws IOException {
try {
float width = 0;
float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
for (int i = 0; i < iMaxWidth.length; i++)
if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
PdfWriter writer = PdfWriter.getInstance(document, iOutput);
writer.setPageEvent(new PdfEventHandler());
document.open();
iTable.setWidths(w);
document.add(iTable);
document.close();
} catch (DocumentException e) {
throw new IOException(e.getMessage(), e);
}
}
示例4: createDoc
import com.lowagie.text.Rectangle; //导入依赖的package包/类
public void createDoc() throws FileNotFoundException{
/** 创建Document对象(word文档) */
Rectangle rectPageSize = new Rectangle(PageSize.A4);
rectPageSize = rectPageSize.rotate();
// 创建word文档,并设置纸张的大小
doc = new Document(PageSize.A4);
file=new File(path+docFileName);
fileOutputStream=new FileOutputStream(file);
/** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 */
RtfWriter2.getInstance(doc, fileOutputStream );
doc.open();
//设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f
doc.setMargins(90f, 90f, 72f, 72f);
//设置标题字体样式,粗体、二号、华文中宋
tfont = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);
//设置正文内容的字体样式,常规、三号、仿宋_GB2312
bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
示例5: export
import com.lowagie.text.Rectangle; //导入依赖的package包/类
public void export(OutputStream out) throws Exception {
int nrCols = getNrColumns();
iDocument = (iForm.getDispMode()==sDispModeInRowHorizontal || iForm.getDispMode()==sDispModeInRowVertical ?
new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)).rotate(), 30, 30, 30, 30)
:
new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)), 30, 30, 30, 30));
PdfEventHandler.initFooter(iDocument, out);
iDocument.open();
printTable();
printLegend();
iDocument.close();
}
示例6: startPage
import com.lowagie.text.Rectangle; //导入依赖的package包/类
/**
* Any work to start off printing a page of the document
* m_currentPage will contain the page being printed, and
* m_currentTemplatePage will contain the template page number to base this
* new page on.
* @throws FormPrintException Thrown if there is any form processing problems
*/
protected void startPage() throws FormPrintException {
log.debug("startPage: Page=" + getCurrentPage());
Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
log.debug( "Page Size : t="+r.getTop()+",l="+r.getLeft()+",b="+r.getBottom()+",r="+r.getRight()+", rot="+r.getRotation() );
r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
log.debug( "Page Size w/Rot: t="+r.getTop()+",l="+r.getLeft()+",b="+r.getBottom()+",r="+r.getRight()+", rot="+r.getRotation() );
// Get rotation quadrent 0..3
int q = (m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()).getRotation() % 360)/90;
float tX = (q==2?r.getTop():0)+(q==3?r.getRight():0);
float tY = (q==1?r.getTop():0)+(q==2?r.getRight():0);
float sX=1f, sY=1f;
double angle = -r.getRotation()*(Math.PI/180f);
double transformA = sX * Math.cos(angle);
double transformB = sY * Math.sin(angle);
double transformC = -sX * Math.sin(angle);
double transformD = sY * Math.cos(angle);
double transformE = tX;
double transformF = tY;
m_generatedDoc.setPageSize(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()) );
//m_generatedDoc.setPageSize(m_templateReader.getPageSize(getCurrentTemplatePage()) );
/**
* try {
* m_generatedDoc.newPage();
* } catch (DocumentException e) {
* log.error("Error Creating New Page - " + e.getMessage() ,e);
* throw new EngineProcessingException("Error Creating New Page - " + e.getMessage());
* }
**/
m_generatedDoc.newPage();
PdfImportedPage page = m_writer.getImportedPage(m_templateReader, getCurrentTemplatePage() );
PdfContentByte cb = m_writer.getDirectContent();
//cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
cb.addTemplate(page, (float)transformA, (float)transformB, (float)transformC,
(float)transformD, (float)transformE, (float)transformF);
log.debug("Matrix = [A=" + transformA +", B=" + transformB +", C=" + transformC +
", D=" + transformD +", E=" + transformE +", F=" + transformF +" ]");
}
示例7: testSimplePdf
import com.lowagie.text.Rectangle; //导入依赖的package包/类
@Test
public void testSimplePdf() throws FileNotFoundException, DocumentException {
// create document
Document document = PdfTestBase.createPdf("testSimplePdf.pdf");
try {
// new page with a rectangle
document.open();
document.newPage();
Annotation ann = new Annotation("Title", "Text");
Rectangle rect = new Rectangle(100, 100);
document.add(ann);
document.add(rect);
} finally {
// close document
if (document != null)
document.close();
}
}
示例8: addDocumentProps
import com.lowagie.text.Rectangle; //导入依赖的package包/类
private void addDocumentProps(Document document, String title, Properties props) {
document.addTitle(title);
document.addSubject("");
document.addKeywords("pdf, itext");
document.addCreator("OSCAR");
document.addAuthor("");
// A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA
// and FLSE
// the following shows a temp way to get a print page size
final String PAGESIZE = "printPageSize";
Rectangle pageSize = PageSize.LETTER;
if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE)))
pageSize = PageSize.HALFLETTER;
if ("PageSize.A6".equals(props.getProperty(PAGESIZE)))
pageSize = PageSize.A6;
document.setPageSize(pageSize);
document.open();
}
示例9: createScreen
import com.lowagie.text.Rectangle; //导入依赖的package包/类
/**
* Creates a screen PdfAnnotation
* @param writer
* @param rect
* @param clipTitle
* @param fs
* @param mimeType
* @param playOnDisplay
* @return a screen PdfAnnotation
* @throws IOException
*/
public static PdfAnnotation createScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs,
String mimeType, boolean playOnDisplay) throws IOException {
PdfAnnotation ann = new PdfAnnotation(writer, rect);
ann.put(PdfName.SUBTYPE, PdfName.SCREEN);
ann.put (PdfName.F, new PdfNumber(FLAGS_PRINT));
ann.put(PdfName.TYPE, PdfName.ANNOT);
ann.setPage();
PdfIndirectReference ref = ann.getIndirectReference();
PdfAction action = PdfAction.rendition(clipTitle,fs,mimeType, ref);
PdfIndirectReference actionRef = writer.addToBody(action).getIndirectReference();
// for play on display add trigger event
if (playOnDisplay)
{
PdfDictionary aa = new PdfDictionary();
aa.put(new PdfName("PV"), actionRef);
ann.put(PdfName.AA, aa);
}
ann.put(PdfName.A, actionRef);
return ann;
}
示例10: createMarkup
import com.lowagie.text.Rectangle; //导入依赖的package包/类
public static PdfAnnotation createMarkup(PdfWriter writer, Rectangle rect, String contents, int type, float quadPoints[]) {
PdfAnnotation annot = new PdfAnnotation(writer, rect);
PdfName name = PdfName.HIGHLIGHT;
switch (type) {
case MARKUP_UNDERLINE:
name = PdfName.UNDERLINE;
break;
case MARKUP_STRIKEOUT:
name = PdfName.STRIKEOUT;
break;
case MARKUP_SQUIGGLY:
name = PdfName.SQUIGGLY;
break;
}
annot.put(PdfName.SUBTYPE, name);
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
PdfArray array = new PdfArray();
for (int k = 0; k < quadPoints.length; ++k)
array.add(new PdfNumber(quadPoints[k]));
annot.put(PdfName.QUADPOINTS, array);
return annot;
}
示例11: setVisibleSignature
import com.lowagie.text.Rectangle; //导入依赖的package包/类
/**
* Sets the signature to be visible. It creates a new visible signature field.
* @param pageRect the position and dimension of the field in the page
* @param page the page to place the field. The fist page is 1
* @param fieldName the field name or <CODE>null</CODE> to generate automatically a new field name
*/
public void setVisibleSignature(Rectangle pageRect, int page, String fieldName) {
if (fieldName != null) {
if (fieldName.indexOf('.') >= 0)
throw new IllegalArgumentException("Field names cannot contain a dot.");
AcroFields af = writer.getAcroFields();
AcroFields.Item item = af.getFieldItem(fieldName);
if (item != null)
throw new IllegalArgumentException("The field " + fieldName + " already exists.");
this.fieldName = fieldName;
}
if (page < 1 || page > writer.reader.getNumberOfPages())
throw new IllegalArgumentException("Invalid page number: " + page);
this.pageRect = new Rectangle(pageRect);
this.pageRect.normalize();
rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight());
this.page = page;
newField = true;
}
示例12: onEndPage
import com.lowagie.text.Rectangle; //导入依赖的package包/类
/**
* @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
*/
public void onEndPage(PdfWriter writer, Document document) {
try {
Rectangle page = document.getPageSize();
if (headerFooterPolicy.getHeader(writer.getPageNumber())!=null) {
Hdr hdr = headerFooterPolicy.getHeader(writer.getPageNumber()).getJaxbElement();
PdfPTable head = new PdfPTable(1); // num cols
// TODO - no cell borders
traverseBlockLevelContent( hdr.getEGBlockLevelElts(), head);
head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(),
writer.getDirectContent());
}
if (headerFooterPolicy.getFooter(writer.getPageNumber())!=null) {
Ftr ftr = headerFooterPolicy.getFooter(writer.getPageNumber()).getJaxbElement();
PdfPTable foot = new PdfPTable(1);
traverseBlockLevelContent( ftr.getEGBlockLevelElts(), foot);
foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
writer.getDirectContent());
}
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
示例13: applyRotation
import com.lowagie.text.Rectangle; //导入依赖的package包/类
void applyRotation(PdfDictionary pageN, ByteBuffer out) {
if (!cstp.rotateContents)
return;
Rectangle page = reader.getPageSizeWithRotation(pageN);
int rotation = page.getRotation();
switch (rotation) {
case 90:
out.append(PdfContents.ROTATE90);
out.append(page.getTop());
out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
break;
case 180:
out.append(PdfContents.ROTATE180);
out.append(page.getRight());
out.append(' ');
out.append(page.getTop());
out.append(PdfContents.ROTATEFINAL);
break;
case 270:
out.append(PdfContents.ROTATE270);
out.append('0').append(' ');
out.append(page.getRight());
out.append(PdfContents.ROTATEFINAL);
break;
}
}
示例14: rotateAnnotations
import com.lowagie.text.Rectangle; //导入依赖的package包/类
public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
PdfArray array = new PdfArray();
int rotation = pageSize.getRotation() % 360;
int currentPage = writer.getCurrentPageNumber();
for (int k = 0; k < annotations.size(); ++k) {
PdfAnnotation dic = (PdfAnnotation)annotations.get(k);
int page = dic.getPlaceInPage();
if (page > currentPage) {
delayedAnnotations.add(dic);
continue;
}
if (dic.isForm()) {
if (!dic.isUsed()) {
HashMap templates = dic.getTemplates();
if (templates != null)
acroForm.addFieldTemplates(templates);
}
PdfFormField field = (PdfFormField)dic;
if (field.getParent() == null)
acroForm.addDocumentField(field.getIndirectReference());
}
if (dic.isAnnotation()) {
array.add(dic.getIndirectReference());
if (!dic.isUsed()) {
PdfRectangle rect = (PdfRectangle)dic.get(PdfName.RECT);
if (rect != null) {
switch (rotation) {
case 90:
dic.put(PdfName.RECT, new PdfRectangle(
pageSize.getTop() - rect.bottom(),
rect.left(),
pageSize.getTop() - rect.top(),
rect.right()));
break;
case 180:
dic.put(PdfName.RECT, new PdfRectangle(
pageSize.getRight() - rect.left(),
pageSize.getTop() - rect.bottom(),
pageSize.getRight() - rect.right(),
pageSize.getTop() - rect.top()));
break;
case 270:
dic.put(PdfName.RECT, new PdfRectangle(
rect.bottom(),
pageSize.getRight() - rect.left(),
rect.top(),
pageSize.getRight() - rect.right()));
break;
}
}
}
}
if (!dic.isUsed()) {
dic.setUsed();
try {
writer.addToBody(dic, dic.getIndirectReference());
}
catch (IOException e) {
throw new ExceptionConverter(e);
}
}
}
return array;
}
示例15: onEndPage
import com.lowagie.text.Rectangle; //导入依赖的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();
}