本文整理汇总了Java中com.lowagie.text.PageSize.A4属性的典型用法代码示例。如果您正苦于以下问题:Java PageSize.A4属性的具体用法?Java PageSize.A4怎么用?Java PageSize.A4使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.lowagie.text.PageSize
的用法示例。
在下文中一共展示了PageSize.A4属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDoc
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);
}
示例2: pdfTableForInstructionalOfferings
public void pdfTableForInstructionalOfferings(
OutputStream out,
ClassAssignmentProxy classAssignment,
ExamAssignmentProxy examAssignment,
InstructionalOfferingListForm form,
String[] subjectAreaIds,
SessionContext context,
boolean displayHeader,
boolean allCoursesAreGiven) throws Exception{
setVisibleColumns(form);
iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f);
iWriter = PdfEventHandler.initFooter(iDocument, out);
for (String subjectAreaId: subjectAreaIds) {
pdfTableForInstructionalOfferings(out, classAssignment, examAssignment,
form.getInstructionalOfferings(Long.valueOf(subjectAreaId)),
Long.valueOf(subjectAreaId),
context,
displayHeader, allCoursesAreGiven,
new ClassCourseComparator(form.getSortBy(), classAssignment, false));
}
iDocument.close();
}
示例3: main
/**
* Adds some annotated images to a PDF file.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2:
// we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("annotated_images.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpeg.setAnnotation(new Annotation("picture", "This is my dog", 0, 0, 0, 0));
jpeg.setAbsolutePosition(100f, 550f);
document.add(jpeg);
Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
wmf.setAnnotation(new Annotation(0, 0, 0, 0, "http://www.lowagie.com/iText"));
wmf.setAbsolutePosition(100f, 200f);
document.add(wmf);
// step 5: we close the document
document.close();
}
示例4: main
/**
* Space Word Ratio.
*/
@Test
public void main() throws Exception {
// step 1
Document document = new Document(PageSize.A4, 50, 350, 50, 50);
// step 2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf"));
// step 3
document.open();
// step 4
String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
Paragraph p = new Paragraph(text);
p.setAlignment(Element.ALIGN_JUSTIFIED);
document.add(p);
document.newPage();
writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
document.add(p);
// step 5
document.close();
}
示例5: generate
public void generate(OutputStream os) throws Exception
{
document = new Document(PageSize.A4, 36, 36, 36, 50);
writer = PdfWriter.getInstance(document,os);
writer.setEncryption(null, null, PdfWriter.AllowCopy | PdfWriter.AllowPrinting, PdfWriter.STRENGTH40BITS);
writer.setPageEvent(new EndPage(this.getCabecera(),this.getPie(),this.getBarcode(),this.isPaginar()));
document.open();
//Pintar la cabecera que proceda: No pitar, cabecera normal o cabecera peque�a
if(!noCabecera) {
if (tipocabecera.equals(TYPE_HEAD_SMALL)) writeCabecera2();
else writeCabecera();
}
for(int i=0; i<secciones.size(); i++)
{
Seccion obj = (Seccion)secciones.get(i);
obj.write(this);
}
document.close();
}
示例6: generateReportFile
protected MemoryFileDTO generateReportFile(BaseReportDto reportData, String fileName) {
Document document = new Document(PageSize.A4);
MemoryFileDTO report = new MemoryFileDTO();
report.setFileName(fileName);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, baos);
writer.setPageEvent(this);
writer.setFullCompression();
document.open();
generateReportBody(document, reportData);
writer.flush();
document.close();
report.setFileData(baos.toByteArray());
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
return report;
}
示例7: main
/**
* Space Word Ratio.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
System.out.println("Space Word Ratio");
// step 1
Document document = new Document(PageSize.A4, 50, 350, 50, 50);
try {
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "spacewordratio.pdf"));
// step 3
document.open();
// step 4
String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
Paragraph p = new Paragraph(text);
p.setAlignment(Element.ALIGN_JUSTIFIED);
document.add(p);
document.newPage();
writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
document.add(p);
} catch (Exception de) {
de.printStackTrace();
}
// step 5
document.close();
}
示例8: main
/**
* Demonstrates the use of PageEvents.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
Document document = new Document(PageSize.A4, 50, 50, 70, 70);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "endpage.pdf"));
writer.setPageEvent(new EndPage());
document.open();
String text = "Lots of text. ";
for (int k = 0; k < 10; ++k)
text += text;
document.add(new Paragraph(text));
document.close();
} catch (Exception de) {
de.printStackTrace();
}
}
示例9: main
/**
* Generates a document with a header containing Page x of y and with a
* Watermark on every page.
*
* @param args
* no arguments needed
*/
public static void main(String args[]) {
try {
// step 1: creating the document
Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
// step 2: creating the writer
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "pageNumbersWatermark.pdf"));
// step 3: initialisations + opening the document
writer.setPageEvent(new PageNumbersWatermark());
doc.open();
// step 4: adding content
String text = "some padding text ";
for (int k = 0; k < 10; ++k)
text += text;
Paragraph p = new Paragraph(text);
p.setAlignment(Element.ALIGN_JUSTIFIED);
doc.add(p);
// step 5: closing the document
doc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: pdfTableForInstructionalOffering
public void pdfTableForInstructionalOffering(
OutputStream out,
ClassAssignmentProxy classAssignment,
ExamAssignmentProxy examAssignment,
Long instructionalOfferingId,
SessionContext context,
Comparator classComparator) throws Exception{
if (instructionalOfferingId != null && context != null){
InstructionalOfferingDAO idao = new InstructionalOfferingDAO();
InstructionalOffering io = idao.get(instructionalOfferingId);
Long subjectAreaId = io.getControllingCourseOffering().getSubjectArea().getUniqueId();
// Get Configuration
TreeSet ts = new TreeSet();
ts.add(io);
WebInstructionalOfferingTableBuilder iotbl = new WebInstructionalOfferingTableBuilder();
iotbl.setDisplayDistributionPrefs(false);
setVisibleColumns(COLUMNS);
iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f);
iWriter = PdfEventHandler.initFooter(iDocument, out);
pdfTableForInstructionalOfferings(out,
classAssignment, examAssignment,
ts, subjectAreaId, context, false, false, classComparator);
iDocument.close();
}
}
示例11: main
/**
* Add an image using different transformation matrices.
*/
@Test
public void main() throws Exception {
Document.compress = false;
// 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( "transformimage.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
cb.addImage(img, 271, -50, -30, 550, 100, 100);
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();
}
示例12: main
/**
* General example using cell events.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
// step3
document.open();
// step4
CellEventsTest event = new CellEventsTest();
Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
im.setRotationDegrees(30);
PdfPTable table = new PdfPTable(4);
table.addCell("text 1");
PdfPCell cell = new PdfPCell(im, true);
cell.setCellEvent(event);
table.addCell(cell);
table.addCell("text 3");
im.setRotationDegrees(0);
table.addCell(im);
table.setTotalWidth(300);
PdfContentByte cb = writer.getDirectContent();
table.writeSelectedRows(0, -1, 50, 600, cb);
table.setHeaderRows(3);
document.add(table);
// step5
document.close();
}
示例13: main
/**
* Demonstrates the use of layers.
*
* @param args
* no arguments needed
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("optionalcontent.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3: opening the document
document.open();
// step 4: content
PdfContentByte cb = writer.getDirectContent();
Phrase explanation = new Phrase(
"Automatic layers, form fields, images, templates and actions",
new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
650, 0);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);
PdfLayer l3 = new PdfLayer("Layer 3", writer);
PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
PdfLayerMembership m1 = new PdfLayerMembership(writer);
m1.addMember(l2);
m1.addMember(l3);
Phrase p1 = new Phrase("Text in layer 1");
Phrase p2 = new Phrase("Text in layer 2 or layer 3");
Phrase p3 = new Phrase("Text in layer 3");
cb.beginLayer(l1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
cb.endLayer();
cb.beginLayer(m1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
cb.endLayer();
cb.beginLayer(l3);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
cb.endLayer();
TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
"field1");
ff.setBorderColor(Color.blue);
ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
ff.setText("I'm a form field");
PdfFormField form = ff.getTextField();
form.setLayer(l4);
writer.addAnnotation(form);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
+ "pngnow.png");
img.setLayer(l4);
img.setAbsolutePosition(200, 550);
cb.addImage(img);
PdfTemplate tp = cb.createTemplate(100, 20);
Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
Font.NORMAL, Color.magenta));
ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
tp.setLayer(l4);
tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
cb.addTemplate(tp, 200, 500);
ArrayList<Object> state = new ArrayList<Object>();
state.add("toggle");
state.add(l1);
state.add(l2);
state.add(l3);
state.add(l4);
PdfAction action = PdfAction.setOCGstate(state, true);
Chunk ck = new Chunk("Click here to toggle the layers", new Font(
Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
Color.blue).setAction(action);
ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
250, 400, 0);
cb.sanityCheck();
// step 5: closing the document
document.close();
}
示例14: main
/**
* Creates a document with Named Actions.
*
* @param args The file to open
*/
public void main(String... args) throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OpenApplication.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
String application = args[0];
Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction(
new PdfAction(application, null, null, null)));
document.add(p);
// step 5: we close the document
document.close();
}
示例15: main
/**
* 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();
}