本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPage.getCropBox方法的典型用法代码示例。如果您正苦于以下问题:Java PDPage.getCropBox方法的具体用法?Java PDPage.getCropBox怎么用?Java PDPage.getCropBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.PDPage
的用法示例。
在下文中一共展示了PDPage.getCropBox方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRotateMoveBox
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content and then move its crop box and
* media box accordingly to make it appear as if the content was rotated around
* the center of the crop box.
* </p>
*/
@Test
public void testRotateMoveBox() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
cs.transform(matrix);
cs.close();
PDRectangle cropBox = page.getCropBox();
float cx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float cy = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
Point2D.Float newC = matrix.transformPoint(cx, cy);
float tx = (float)newC.getX() - cx;
float ty = (float)newC.getY() - cy;
page.setCropBox(new PDRectangle(cropBox.getLowerLeftX() + tx, cropBox.getLowerLeftY() + ty, cropBox.getWidth(), cropBox.getHeight()));
PDRectangle mediaBox = page.getMediaBox();
page.setMediaBox(new PDRectangle(mediaBox.getLowerLeftX() + tx, mediaBox.getLowerLeftY() + ty, mediaBox.getWidth(), mediaBox.getHeight()));
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-move-box.pdf"));
}
}
示例2: testRotateCenter
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content around the center of its crop box.
* </p>
*/
@Test
public void testRotateCenter() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
cs.transform(Matrix.getTranslateInstance(tx, ty));
cs.transform(Matrix.getRotateInstance(Math.toRadians(45), 0, 0));
cs.transform(Matrix.getTranslateInstance(-tx, -ty));
cs.close();
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center.pdf"));
}
}
示例3: testRotateCenterScale
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content around the center of its crop box
* and then crop it to make all previously visible content fit.
* </p>
*/
@Test
public void testRotateCenterScale() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
PDRectangle cropBox = page.getCropBox();
float tx = (cropBox.getLowerLeftX() + cropBox.getUpperRightX()) / 2;
float ty = (cropBox.getLowerLeftY() + cropBox.getUpperRightY()) / 2;
Rectangle rectangle = cropBox.transform(matrix).getBounds();
float scale = Math.min(cropBox.getWidth() / (float)rectangle.getWidth(), cropBox.getHeight() / (float)rectangle.getHeight());
cs.transform(Matrix.getTranslateInstance(tx, ty));
cs.transform(matrix);
cs.transform(Matrix.getScaleInstance(scale, scale));
cs.transform(Matrix.getTranslateInstance(-tx, -ty));
cs.close();
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-center-scale.pdf"));
}
}
示例4: markPageForLoading
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
private void markPageForLoading() {
int numberOfPages = mPdf.getNumberOfPages();
if (mPageIndex >= 0 && mPageIndex == numberOfPages) {
mPageIndex = numberOfPages - 1;
}
if (mPageIndex >= 0 && mPageIndex < numberOfPages) {
PDPage page = mPdf.getPage(mPageIndex);
PDRectangle cropBox = page.getCropBox();
float scale = SCALES[mScaleIndex] * Toolkit.getDefaultToolkit().getScreenResolution();
mWidth = (int) Math.ceil(cropBox.getWidth() / 72 * scale);
mHeight = (int) Math.ceil(cropBox.getHeight() / 72 * scale);
mImg = null;
mNeedLoad = true;
Dimension size = new Dimension(mWidth, mHeight);
UIUtilities.setOnlySize(this, size);
setSize(size);
repaint();
mIgnorePageChange = true;
mOwner.updateStatus(mPageIndex, numberOfPages, SCALES[mScaleIndex]);
mIgnorePageChange = false;
}
}
示例5: writeString
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
@Override
protected void writeString(String string, List<TextPosition> pos) throws IOException {
PDPage page = this.getCurrentPage();
if (!pagesList.contains(page)) {
currentPage = new Page(page.getCropBox(), ++pageCount);
pagesList.add(page);
}
if (!previousPages.contains(currentPage))
previousPages.add(currentPage);
PDGraphicsState gs = this.getGraphicsState();
for (TextPosition tp : pos) {
this.processTextPositionNew(tp, gs, string);
}
coalesceRows(currentPage, string);
removeDuplicates(currentPage);
}
示例6: processPage
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
@Override
public void processPage(PDPage page) throws IOException {
PDRectangle pageSize = page.getCropBox();
lowerLeftX = pageSize.getLowerLeftX();
lowerLeftY = pageSize.getLowerLeftY();
super.processPage(page);
}
示例7: testRotateExpandBox
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40611736/rotate-pdf-around-its-center-using-pdfbox-in-java">
* Rotate PDF around its center using PDFBox in java
* </a>
* <p>
* This test shows how to rotate the page content and then set the crop
* box and media box to the bounding rectangle of the rotated page area.
* </p>
*/
@Test
public void testRotateExpandBox() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("IRJET_Copy_Right_form.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDPage page = document.getDocumentCatalog().getPages().get(0);
PDPageContentStream cs = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false, false);
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(45), 0, 0);
cs.transform(matrix);
cs.close();
PDRectangle cropBox = page.getCropBox();
Rectangle rectangle = cropBox.transform(matrix).getBounds();
PDRectangle newBox = new PDRectangle((float)rectangle.getX(), (float)rectangle.getY(), (float)rectangle.getWidth(), (float)rectangle.getHeight());
page.setCropBox(newBox);
page.setMediaBox(newBox);
document.save(new File(RESULT_FOLDER, "IRJET_Copy_Right_form-rotated-expand-box.pdf"));
}
}
示例8: assertPositionAndSize
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* Quick method to validate position and size.
*/
private void assertPositionAndSize(float x, float y, PDImageXObject image, PDPage page) throws PdfProcessingException {
PDRectangle pageArea = page.getCropBox();
// Assert position is in page
if (x < pageArea.getLowerLeftX() || x > pageArea.getUpperRightX())
throw new PdfProcessingException("X position not valid. (" + x + "," + y + ") out of page");
if (y < pageArea.getLowerLeftY() || y > pageArea.getUpperRightY())
throw new PdfProcessingException("Y position not valid. (" + x + "," + y + ") out of page");
// Assert image fits
if (x + image.getWidth() > pageArea.getUpperRightX() ||
y + image.getHeight() > pageArea.getUpperRightY())
throw new PdfProcessingException("Image dos not fit in page");
}