本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPage.getRotation方法的典型用法代码示例。如果您正苦于以下问题:Java PDPage.getRotation方法的具体用法?Java PDPage.getRotation怎么用?Java PDPage.getRotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.PDPage
的用法示例。
在下文中一共展示了PDPage.getRotation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotate180
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
public ActionForward rotate180(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
Document doc = documentDao.getDocument(request.getParameter("document"));
String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
FileInputStream input = new FileInputStream(docdownload + doc.getDocfilename());
PDFParser parser = new PDFParser(input);
parser.parse();
PDDocument pdf = parser.getPDDocument();
int x = 1;
for (Object p : pdf.getDocumentCatalog().getAllPages()) {
PDPage pg = (PDPage)p;
Integer r = (pg.getRotation() != null ? pg.getRotation() : 0);
pg.setRotation((r+180)%360);
ManageDocumentAction.deleteCacheVersion(doc, x);
x++;
}
pdf.save(docdownload + doc.getDocfilename());
pdf.close();
input.close();
return null;
}
示例2: rotate90
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
public ActionForward rotate90(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
Document doc = documentDao.getDocument(request.getParameter("document"));
String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
FileInputStream input = new FileInputStream(docdownload + doc.getDocfilename());
PDFParser parser = new PDFParser(input);
parser.parse();
PDDocument pdf = parser.getPDDocument();
int x = 1;
for (Object p : pdf.getDocumentCatalog().getAllPages()) {
PDPage pg = (PDPage)p;
Integer r = (pg.getRotation() != null ? pg.getRotation() : 0);
pg.setRotation((r+90)%360);
ManageDocumentAction.deleteCacheVersion(doc, x);
x++;
}
pdf.save(docdownload + doc.getDocfilename());
pdf.close();
input.close();
return null;
}
示例3: extractPage
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
protected Page extractPage(Integer pageNumber) throws IOException {
if (pageNumber > this.pdfDocument.getNumberOfPages() || pageNumber < 1) {
throw new java.lang.IndexOutOfBoundsException(
"Page number does not exist");
}
PDPage p = this.pdfDocument.getPage(pageNumber - 1);
ObjectExtractorStreamEngine se = new ObjectExtractorStreamEngine(p);
se.processPage(p);
TextStripper pdfTextStripper = new TextStripper(this.pdfDocument, pageNumber);
pdfTextStripper.process();
Utils.sort(pdfTextStripper.textElements, Rectangle.ILL_DEFINED_ORDER);
float w, h;
int pageRotation = p.getRotation();
if (Math.abs(pageRotation) == 90 || Math.abs(pageRotation) == 270) {
w = p.getCropBox().getHeight();
h = p.getCropBox().getWidth();
} else {
w = p.getCropBox().getWidth();
h = p.getCropBox().getHeight();
}
return new Page(0, 0, w, h, pageRotation, pageNumber, p, pdfTextStripper.textElements,
se.rulings, pdfTextStripper.minCharWidth, pdfTextStripper.minCharHeight, pdfTextStripper.spatialIndex);
}
示例4: writeString
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
@Override
protected void writeString(String text, List<TextPosition> textPositions) throws IOException {
text = text.toLowerCase();
int index = text.indexOf(mTextToHighlight);
if (index != -1) {
PDPage currentPage = getCurrentPage();
PDRectangle pageBoundingBox = currentPage.getBBox();
AffineTransform flip = new AffineTransform();
flip.translate(0, pageBoundingBox.getHeight());
flip.scale(1, -1);
PDRectangle mediaBox = currentPage.getMediaBox();
float mediaHeight = mediaBox.getHeight();
float mediaWidth = mediaBox.getWidth();
int size = textPositions.size();
while (index != -1) {
int last = index + mTextToHighlight.length() - 1;
for (int i = index; i <= last; i++) {
TextPosition pos = textPositions.get(i);
PDFont font = pos.getFont();
BoundingBox bbox = font.getBoundingBox();
Rectangle2D.Float rect = new Rectangle2D.Float(0, bbox.getLowerLeftY(), font.getWidth(pos.getCharacterCodes()[0]), bbox.getHeight());
AffineTransform at = pos.getTextMatrix().createAffineTransform();
if (font instanceof PDType3Font) {
at.concatenate(font.getFontMatrix().createAffineTransform());
} else {
at.scale(1 / 1000f, 1 / 1000f);
}
Shape shape = flip.createTransformedShape(at.createTransformedShape(rect));
AffineTransform transform = mGC.getTransform();
int rotation = currentPage.getRotation();
if (rotation != 0) {
switch (rotation) {
case 90:
mGC.translate(mediaHeight, 0);
break;
case 270:
mGC.translate(0, mediaWidth);
break;
case 180:
mGC.translate(mediaWidth, mediaHeight);
break;
default:
break;
}
mGC.rotate(Math.toRadians(rotation));
}
mGC.fill(shape);
if (rotation != 0) {
mGC.setTransform(transform);
}
}
index = last < size - 1 ? text.indexOf(mTextToHighlight, last + 1) : -1;
}
}
}
示例5: getPageRotation
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
public static int getPageRotation(final PDPage page) {
return page.getRotation();
}
示例6: getPageRotation
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
public static int getPageRotation(final PDPage page) {
return page.getRotation() == null ? 0 : page.getRotation();
}