本文整理汇总了Java中org.apache.pdfbox.pdmodel.common.PDRectangle.A4属性的典型用法代码示例。如果您正苦于以下问题:Java PDRectangle.A4属性的具体用法?Java PDRectangle.A4怎么用?Java PDRectangle.A4使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.pdfbox.pdmodel.common.PDRectangle
的用法示例。
在下文中一共展示了PDRectangle.A4属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAlternateRowsDocument
@Test
public void createAlternateRowsDocument() throws Exception {
final PDDocument document = new PDDocument();
final PDPage page = new PDPage(PDRectangle.A4);
page.setRotation(90);
document.addPage(page);
final PDPageContentStream contentStream = new PDPageContentStream(document, page);
// TODO replace deprecated method call
contentStream.concatenate2CTM(0, 1, -1, 0, page.getMediaBox().getWidth(), 0);
final float startY = page.getMediaBox().getWidth() - 30;
(new TableDrawer(contentStream, createAndGetTableWithAlternatingColors(), 30, startY)).draw();
contentStream.close();
document.save("target/alternateRows.pdf");
document.close();
}
示例2: createRingManagerDocument
@Test
public void createRingManagerDocument() throws Exception {
final PDDocument document = new PDDocument();
final PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
final float startY = page.getMediaBox().getHeight() - 150;
final int startX = 56;
final PDPageContentStream contentStream = new PDPageContentStream(document, page);
Table table = getRingManagerTable();
(new TableDrawer(contentStream, table, startX, startY)).draw();
contentStream.setFont(PDType1Font.HELVETICA, 8.0f);
contentStream.beginText();
contentStream.newLineAtOffset(startX, startY - (table.getHeight() + 22));
contentStream.showText("Dieser Kampf muss der WB nicht entsprechen, da als Sparringskampf angesetzt.");
contentStream.endText();
contentStream.close();
document.save("target/ringmanager.pdf");
document.close();
}
示例3: testMultiPageJFreeChart
@Test
public void testMultiPageJFreeChart() throws IOException {
File parentDir = new File("target/test/multipage");
// noinspection ResultOfMethodCallIgnored
parentDir.mkdirs();
File targetPDF = new File(parentDir, "multipage.pdf");
PDDocument document = new PDDocument();
for (int i = 0; i < 4; i++) {
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
PdfBoxGraphics2D pdfBoxGraphics2D = new PdfBoxGraphics2D(document, 800, 400);
drawOnGraphics(pdfBoxGraphics2D, i);
pdfBoxGraphics2D.dispose();
PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
Matrix matrix = new Matrix();
matrix.translate(0, 30);
matrix.scale(0.7f, 1f);
contentStream.saveGraphicsState();
contentStream.transform(matrix);
contentStream.drawForm(appearanceStream);
contentStream.restoreGraphicsState();
contentStream.close();
}
document.save(targetPDF);
document.close();
}
示例4: createSampleDocument
@Test
public void createSampleDocument() throws Exception {
// Define the table structure first
TableBuilder tableBuilder = new TableBuilder()
.addColumnOfWidth(300)
.addColumnOfWidth(120)
.addColumnOfWidth(70)
.setFontSize(8)
.setFont(PDType1Font.HELVETICA);
// Header ...
tableBuilder.addRow(new RowBuilder()
.add(Cell.withText("This is right aligned without a border").setHorizontalAlignment(RIGHT))
.add(Cell.withText("And this is another cell"))
.add(Cell.withText("Sum").setBackgroundColor(Color.ORANGE))
.setBackgroundColor(Color.BLUE)
.build());
// ... and some cells
for (int i = 0; i < 10; i++) {
tableBuilder.addRow(new RowBuilder()
.add(Cell.withText(i).withAllBorders())
.add(Cell.withText(i * i).withAllBorders())
.add(Cell.withText(i + (i * i)).withAllBorders())
.setBackgroundColor(i % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE)
.build());
}
final PDDocument document = new PDDocument();
final PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
final PDPageContentStream contentStream = new PDPageContentStream(document, page);
// Define the starting point
final float startY = page.getMediaBox().getHeight() - 50;
final int startX = 50;
// Draw!
(new TableDrawer(contentStream, tableBuilder.build(), startX, startY)).draw();
contentStream.close();
document.save("target/sampleWithColorsAndBorders.pdf");
document.close();
}
示例5: exportGraphic
@SuppressWarnings("SpellCheckingInspection")
void exportGraphic(String dir, String name, GraphicsExporter exporter) {
try {
PDDocument document = new PDDocument();
PDFont pdArial = PDFontFactory.createDefaultFont();
File parentDir = new File("target/test/" + dir);
// noinspection ResultOfMethodCallIgnored
parentDir.mkdirs();
BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D imageGraphics = image.createGraphics();
exporter.draw(imageGraphics);
imageGraphics.dispose();
ImageIO.write(image, "PNG", new File(parentDir, name + ".png"));
for (Mode m : Mode.values()) {
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
PdfBoxGraphics2D pdfBoxGraphics2D = new PdfBoxGraphics2D(document, 400, 400);
PdfBoxGraphics2DFontTextDrawer fontTextDrawer = null;
contentStream.beginText();
contentStream.setStrokingColor(0, 0, 0);
contentStream.setNonStrokingColor(0, 0, 0);
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 15);
contentStream.setTextMatrix(Matrix.getTranslateInstance(10, 800));
contentStream.showText("Mode " + m);
contentStream.endText();
switch (m) {
case FontTextIfPossible:
fontTextDrawer = new PdfBoxGraphics2DFontTextDrawer();
fontTextDrawer.registerFont(
new File("src/test/resources/de/rototor/pdfbox/graphics2d/DejaVuSerifCondensed.ttf"));
break;
case DefaultFontText: {
fontTextDrawer = new PdfBoxGraphics2DFontTextDrawerDefaultFonts();
fontTextDrawer.registerFont(
new File("src/test/resources/de/rototor/pdfbox/graphics2d/DejaVuSerifCondensed.ttf"));
break;
}
case ForceFontText:
fontTextDrawer = new PdfBoxGraphics2DFontTextForcedDrawer();
fontTextDrawer.registerFont(
PdfBoxGraphics2DTestBase.class.getResourceAsStream("DejaVuSerifCondensed.ttf"));
fontTextDrawer.registerFont("Arial", pdArial);
break;
case DefaultVectorized:
default:
break;
}
if (fontTextDrawer != null) {
pdfBoxGraphics2D.setFontTextDrawer(fontTextDrawer);
}
exporter.draw(pdfBoxGraphics2D);
pdfBoxGraphics2D.dispose();
PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
Matrix matrix = new Matrix();
matrix.translate(0, 20);
contentStream.transform(matrix);
contentStream.drawForm(appearanceStream);
matrix.scale(1.5f, 1.5f);
matrix.translate(0, 100);
contentStream.transform(matrix);
contentStream.drawForm(appearanceStream);
contentStream.close();
}
document.save(new File(parentDir, name + ".pdf"));
document.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: testNestedHtmlListsInCell
/**
* <a href="http://stackoverflow.com/questions/43447829/apache-pdfbox-boxable-html-ordered-unordered-list-is-incorrectly-displayed">
* Apache PDFBox, Boxable - HTML ordered/unordered list is incorrectly displayed
* </a>
* <p>
* Using the 1.5-RC artifact like the OP did, one can indeed observe the incorrect nesting.
* </p>
* <p>
* Compiling and using the current (2017-04-25) master branch (which contains numerous changes
* added since the RC has been released but is still versioned 1.4!), though, the nested list
* is properly displayed.
* </p>
*/
@Test
public void testNestedHtmlListsInCell() throws IOException
{
PDDocument document = new PDDocument();
PDPage myPage = new PDPage(PDRectangle.A4);
document.addPage(myPage);
float yPosition = 777;
float margin = 40;
float bottomMargin = 40;
float yStartNewPage = myPage.getMediaBox().getHeight() - (margin);
float tableWidth = myPage.getMediaBox().getWidth() - (2 * margin);
BaseTable table = new BaseTable(yPosition, yStartNewPage, bottomMargin, tableWidth, margin, document, myPage, true, true);
Row<PDPage> row = table.createRow(10f);
/*Cell cell = */row.createCell((100 / 3f),"<ul><li>hello</li><li>hello 2</li><ol><li>nested</li><li>nested 2</li></ol></ul>", be.quodlibet.boxable.HorizontalAlignment.get("left"), be.quodlibet.boxable.VerticalAlignment.get("top"));
// /*Cell cell = */row.createCell((100 / 3f),"<ul><li>hello</li><li>hello 2<ol><li>nested</li><li>nested 2</li></ol></li></ul>", be.quodlibet.boxable.HorizontalAlignment.get("left"), be.quodlibet.boxable.VerticalAlignment.get("top"));
// /*Cell cell = */row.createCell((100 / 3f),"<ul><li>hello</li><li>hello 2<ul><li>nested</li><li>nested 2</li></ul></li></ul>", be.quodlibet.boxable.HorizontalAlignment.get("left"), be.quodlibet.boxable.VerticalAlignment.get("top"));
// /*Cell cell = */row.createCell((100 / 3f),"not bold <i>italic</i> <b>once bold <b>twice bold</b> once bold again <i>italic</i> </b> not bold", be.quodlibet.boxable.HorizontalAlignment.get("left"), be.quodlibet.boxable.VerticalAlignment.get("top"));
table.draw();
document.save(new File(RESULT_FOLDER, "NestedHtmlListsInCell.pdf"));
document.close();
}
示例7: HexPdf
/**
* Sole constructor, creates a new instance of HexPdf.
*/
public HexPdf() {
super();
this.ignorePagebleed = false;
this.numPages = 0;
this.rightMargin = 50f;
this.leftMargin = 50f;
this.bottomMargin = 50f;
this.topMargin = 50f;
this.fontSize = 10;
this.font = PDType1Font.TIMES_ROMAN;
this.pageSize = PDRectangle.A4;
this.normalColor = Color.black;
this.titleColor = Color.black;
this.orientation = HexPdf.PORTRAIT;
//firstPage();
}
示例8: PDFRenderer
/**
* Constructor
*
* initialize the variables
*/
public PDFRenderer(int rootWidth, int rootHeight, OutputStream out, String pageFormat) {
this.rootHeight = rootHeight;
this.pathToSave = out;
this.pageCount = 0;
switch (pageFormat) {
case "A0":
this.pageFormat = PDRectangle.A0;
break;
case "A1":
this.pageFormat = PDRectangle.A1;
break;
case "A2":
this.pageFormat = PDRectangle.A2;
break;
case "A3":
this.pageFormat = PDRectangle.A3;
break;
case "A4":
this.pageFormat = PDRectangle.A4;
break;
case "A5":
this.pageFormat = PDRectangle.A5;
break;
case "A6":
this.pageFormat = PDRectangle.A6;
break;
case "LETTER":
this.pageFormat = PDRectangle.LETTER;
break;
default:
this.pageFormat = PDRectangle.A4;
break;
}
initSettings(rootWidth);
}
示例9: testBothStyled
@Test
public void testBothStyled () throws PDFCreationException
{
final String sHeader = "This is a page header that is repeated on every page.\nIt can have multiple lines etc.\n";
final String sFooter = "This is a page footer that is repeated on every page.\nIt can have multiple lines etc.\n";
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
aPS1.setPageHeader (new PLText (sHeader + sHeader + "last line of header", r10).setBorder (Color.RED)
.setHorzAlign (EHorzAlignment.CENTER)
.setPadding (5)
.setMargin (5)
.setFillColor (Color.YELLOW));
aPS1.setPageFooter (new PLText (sFooter +
sFooter +
"last line of footer",
r10).setPadding (5)
.setMargin (5)
.setFillColor (Color.PINK)
.setHorzAlign (EHorzAlignment.RIGHT));
aPS1.addElement (new PLText ("First body line", r10).setBorder (Color.BLUE));
final PageLayoutPDF aPageLayout = new PageLayoutPDF ();
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-plpageset-both-styled.pdf")));
}
示例10: testStarWidthInline
@Test
public void testStarWidthInline () throws PDFCreationException
{
final String s = "This is a test String";
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
final PLHBox aHBox = new PLHBox ();
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.star ());
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.star ());
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.star ());
aPS1.addElement (aHBox);
final PageLayoutPDF aPageLayout = new PageLayoutPDF ();
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-plhbox-star-inline.pdf")));
}
示例11: testCellSpawningPage
@Test
public void testCellSpawningPage () throws PDFCreationException
{
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
aPS1.addElement (new PLText ("First line", r10).setID ("first-line"));
// Start table
final String sLongText = StringHelper.getRepeated ("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n",
10);
final PLTable aTable = PLTable.createWithEvenlySizedColumns (3).setID ("table");
aTable.addAndReturnRow (new PLTableCell (new PLText (sLongText, r10).setID ("longtext")).setID ("celllongtext"),
new PLTableCell (new PLSpacerX (0).setID ("empty")).setID ("cellempty"),
new PLTableCell (new PLText ("Short text",
r10).setID ("shorttext")).setID ("cellshorttext"))
.setID ("row");
EPLTableGridType.FULL.applyGridToTable (aTable, new BorderStyleSpec (Color.RED));
aPS1.addElement (aTable);
aPS1.addElement (new PLText ("Last line", r10).setID ("last-line"));
final PageLayoutPDF aPageLayout = new PageLayoutPDF ().setCompressPDF (false);
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-pltable-cell-spawning-page.pdf")));
}
示例12: main
public static void main (final String [] args) throws IOException
{
try (final PDDocument doc = new PDDocument ())
{
final PDPage page = new PDPage (PDRectangle.A4);
doc.addPage (page);
try (final PDPageContentStream contents = new PDPageContentStream (doc, page))
{
contents.beginText ();
contents.setFont (PDType0Font.load (doc,
EFontResourceOpenSans.OPEN_SANS_NORMAL.getFontResource ()
.getInputStream ()),
12);
contents.endText ();
}
// No need to save
}
}
示例13: testAbsoluteWidthInline
@Test
public void testAbsoluteWidthInline () throws PDFCreationException
{
final String s = "This is a test String";
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
final PLHBox aHBox = new PLHBox ();
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.abs (80));
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.abs (120));
aHBox.addColumn (new PLText (s, r10).setBorder (Color.RED), WidthSpec.abs (80));
aPS1.addElement (aHBox);
final PageLayoutPDF aPageLayout = new PageLayoutPDF ();
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-plhbox-abs-inline.pdf")));
}
示例14: testAbsoluteWidthBlock
@Test
public void testAbsoluteWidthBlock () throws PDFCreationException
{
final String s = "This is a test String";
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
final PLHBox aHBox = new PLHBox ();
aHBox.addColumn (new PLBox (new PLText (s, r10).setFillColor (Color.YELLOW)).setBorder (Color.RED),
WidthSpec.abs (80));
aHBox.addColumn (new PLBox (new PLText (s, r10).setFillColor (Color.YELLOW)).setBorder (Color.RED),
WidthSpec.abs (120));
aHBox.addColumn (new PLBox (new PLText (s, r10).setFillColor (Color.YELLOW)).setBorder (Color.RED),
WidthSpec.abs (80));
aPS1.addElement (aHBox);
final PageLayoutPDF aPageLayout = new PageLayoutPDF ();
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-plhbox-abs-block.pdf")));
}
示例15: testAutoWidthBlock
@Test
public void testAutoWidthBlock () throws PDFCreationException
{
final String s = "This is a test String";
final FontSpec r10 = new FontSpec (PreloadFont.REGULAR, 10);
final PLPageSet aPS1 = new PLPageSet (PDRectangle.A4);
final PLHBox aHBox = new PLHBox ();
aHBox.addColumn (new PLBox (new PLText (s, r10)).setBorder (Color.RED).setMinWidth (200), WidthSpec.auto ());
aHBox.addColumn (new PLBox (new PLText (s, r10)).setBorder (Color.RED), WidthSpec.auto ());
aHBox.addColumn (new PLBox (new PLText (s, r10)).setBorder (Color.RED).setMinWidth (200), WidthSpec.auto ());
aPS1.addElement (aHBox);
final PageLayoutPDF aPageLayout = new PageLayoutPDF ();
aPageLayout.addPageSet (aPS1);
aPageLayout.renderTo (FileHelper.getOutputStream (new File ("pdf/test-plhbox-auto-block.pdf")));
}