本文整理汇总了Java中org.apache.pdfbox.pdmodel.graphics.PDXObject类的典型用法代码示例。如果您正苦于以下问题:Java PDXObject类的具体用法?Java PDXObject怎么用?Java PDXObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PDXObject类属于org.apache.pdfbox.pdmodel.graphics包,在下文中一共展示了PDXObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: findPhoto
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
public static void findPhoto(String path,int empId) throws IOException, SQLException, Error{
// Loading an existing document
int imageFound=0;
File file = new File(path);
PDDocument document=PDDocument.load(file);
PDPageTree list=document.getPages();
for(PDPage page:list){ //check in all pages of pdf
PDResources pdResources=page.getResources(); //get all resources
for(COSName cosName:pdResources.getXObjectNames()) //loop for all resources
{
PDXObject pdxObject=pdResources.getXObject(cosName);
if (pdxObject instanceof PDImageXObject) { //check that the resource is image
BufferedImage br=((PDImageXObject) pdxObject).getImage();
RgbImage im = RgbImageJ2se.toRgbImage(br);
// step #3 - convert image to greyscale 8-bits
RgbAvgGray toGray = new RgbAvgGray();
toGray.push(im);
// step #4 - initialize face detector with correct Haar profile
InputStream is = ExtractPhoto.class.getResourceAsStream("/haar/HCSB.txt");
Gray8DetectHaarMultiScale detectHaar = new Gray8DetectHaarMultiScale(is, 1,40);
// step #5 - apply face detector to grayscale image
List<Rect> result= detectHaar.pushAndReturn(toGray.getFront());
if(result.size()!=0)
{
database.StorePhoto.storePhoto(empId,br);
imageFound=1;
break;
}
}
}
if(imageFound==1)
break;
}
System.out.println(imageFound);
if(imageFound!=1){
BufferedImage in = ImageIO.read(ExtractPhoto.class.getResource("/images/nopic.jpg"));
database.StorePhoto.storePhoto(empId,in);
}
document.close();
}
开发者ID:djdivix,项目名称:IDBuilderFX,代码行数:41,代码来源:ExtractPhoto.java
示例2: getImagesFromResources
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
private List<RenderedImage> getImagesFromResources(PDResources resources) throws IOException {
List<RenderedImage> images = new ArrayList<>();
for (COSName xObjectName : resources.getXObjectNames()) {
PDXObject xObject = resources.getXObject(xObjectName);
if (xObject instanceof PDImageXObject) {
images.add(((PDImageXObject) xObject).getImage());
} else if (xObject instanceof PDFormXObject) {
images.addAll(getImagesFromResources(((PDFormXObject) xObject).getResources()));
}
}
return images;
}
开发者ID:abelsromero,项目名称:pdf-box-examples,代码行数:14,代码来源:PdfImagesHelper.java
示例3: put
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
public void put(COSObject indirect, PDXObject xobject) throws IOException {
final int length = xobject.getStream().getLength();
if (length > Environment.getMaxImageSize()) {
LOG.trace("Not caching image with Size: {}", length);
return;
}
if (xobject instanceof PDImageXObject) {
PDImageXObject imageObj = (PDImageXObject) xobject;
if (imageObj.getWidth() * imageObj.getHeight() > Environment.getMaxImageSize()) {
return;
}
}
this.xobjects.put(indirect, new SoftReference(xobject));
}
开发者ID:red6,项目名称:pdfcompare,代码行数:16,代码来源:ResourceCacheWithLimitedImages.java
示例4: extractFontResources
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
private void extractFontResources(PDResources resources) throws IOException {
for (COSName key : resources.getFontNames()) {
PDFont font = resources.getFont(key);
extractStrategy.extract(font);
}
for (COSName name : resources.getXObjectNames()) {
PDXObject xobject = resources.getXObject(name);
if (xobject instanceof PDFormXObject) {
PDFormXObject xObjectForm = (PDFormXObject) xobject;
PDResources formResources = xObjectForm.getResources();
if (formResources != null)
extractFontResources(formResources);
}
}
}
开发者ID:m-abboud,项目名称:FontVerter,代码行数:18,代码来源:PdfFontExtractor.java
示例5: testExtractPageImageResources10948
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40531871/how-can-i-check-if-pdf-page-is-imagescanned-by-pdfbox-xpdf">
* How can I check if PDF page is image(scanned) by PDFBOX, XPDF
* </a>
* <br/>
* <a href="https://drive.google.com/file/d/0B9izTHWJQ7xlT2ZoQkJfbGRYcFE">
* 10948.pdf
* </a>
* <p>
* The only special thing about the two images returned for the sample PDF is that
* one image is merely a mask used for the other image, and the other image is the
* actual image used on the PDF page. If one only wants the images immediately used
* in the page content, one also has to scan the page content.
* </p>
*/
@Test
public void testExtractPageImageResources10948() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("10948.pdf"))
{
PDDocument document = PDDocument.load(resource);
int page = 1;
for (PDPage pdPage : document.getPages())
{
PDResources resources = pdPage.getResources();
if (resource != null)
{
int index = 0;
for (COSName cosName : resources.getXObjectNames())
{
PDXObject xobject = resources.getXObject(cosName);
if (xobject instanceof PDImageXObject)
{
PDImageXObject image = (PDImageXObject)xobject;
File file = new File(RESULT_FOLDER, String.format("10948-%s-%s.%s", page, index, image.getSuffix()));
ImageIO.write(image.getImage(), image.getSuffix(), file);
index++;
}
}
}
page++;
}
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:45,代码来源:ExtractImages.java
示例6: testExtractPageImageResources10948New
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/40531871/how-can-i-check-if-pdf-page-is-imagescanned-by-pdfbox-xpdf">
* How can I check if PDF page is image(scanned) by PDFBOX, XPDF
* </a>
* <br/>
* <a href="https://drive.google.com/open?id=0B9izTHWJQ7xlYi1XN1BxMmZEUGc">
* 10948.pdf
* </a>, renamed "10948-new.pdf" here to prevent a collision
* <p>
* Here the code extracts no image at all because the images are not immediate page
* resources but wrapped in form xobjects.
* </p>
*/
@Test
public void testExtractPageImageResources10948New() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("10948-new.pdf"))
{
PDDocument document = PDDocument.load(resource);
int page = 1;
for (PDPage pdPage : document.getPages())
{
PDResources resources = pdPage.getResources();
if (resource != null)
{
int index = 0;
for (COSName cosName : resources.getXObjectNames())
{
PDXObject xobject = resources.getXObject(cosName);
if (xobject instanceof PDImageXObject)
{
PDImageXObject image = (PDImageXObject)xobject;
File file = new File(RESULT_FOLDER, String.format("10948-new-%s-%s.%s", page, index, image.getSuffix()));
ImageIO.write(image.getImage(), image.getSuffix(), file);
index++;
}
}
}
page++;
}
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:43,代码来源:ExtractImages.java
示例7: processFontResources
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
private void processFontResources(PDResources resources, FontTable table) throws IOException
{
String fontNotSupportedMessage = "Font: {} skipped because type '{}' is not supported.";
for (COSName key : resources.getFontNames())
{
PDFont font = resources.getFont(key);
if (font instanceof PDTrueTypeFont)
{
table.addEntry( font);
log.debug("Font: " + font.getName() + " TTF");
}
else if (font instanceof PDType0Font)
{
PDCIDFont descendantFont = ((PDType0Font) font).getDescendantFont();
if (descendantFont instanceof PDCIDFontType2)
table.addEntry(font);
else
log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
}
else if (font instanceof PDType1CFont)
table.addEntry(font);
else
log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
}
for (COSName name : resources.getXObjectNames())
{
PDXObject xobject = resources.getXObject(name);
if (xobject instanceof PDFormXObject)
{
PDFormXObject xObjectForm = (PDFormXObject) xobject;
PDResources formResources = xObjectForm.getResources();
if (formResources != null)
processFontResources(formResources, table);
}
}
}
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:40,代码来源:PDFBoxTree.java
示例8: processImageOperation
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
protected void processImageOperation(List<COSBase> arguments) throws IOException
{
COSName objectName = (COSName)arguments.get( 0 );
PDXObject xobject = getResources().getXObject( objectName );
if (xobject instanceof PDImageXObject)
{
PDImageXObject pdfImage = (PDImageXObject) xobject;
BufferedImage outputImage = pdfImage.getImage();
outputImage = rotateImage(outputImage);
ImageResource imageData = new ImageResource(getTitle(), outputImage);
Rectangle2D bounds = calculateImagePosition(pdfImage);
float x = (float) bounds.getX();
float y = (float) bounds.getY();
renderImage(x, y, (float) bounds.getWidth(), (float) bounds.getHeight(), imageData);
}
}
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:20,代码来源:PDFBoxTree.java
示例9: getXObject
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
public PDXObject getXObject(COSObject indirect) throws IOException {
SoftReference<PDXObject> xobject = this.xobjects.get(indirect);
if (xobject != null) {
return xobject.get();
}
return null;
}
开发者ID:red6,项目名称:pdfcompare,代码行数:9,代码来源:ResourceCacheWithLimitedImages.java
示例10: processOperator
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
/**
* This is used to handle an operation.
*
* @param operator The operation to perform.
* @param operands The list of arguments.
* @throws IOException If there is an error processing the operation.
*/
@Override
protected void processOperator(Operator operator, List<COSBase> operands) throws IOException {
String operation = operator.getName();
if (INVOKE_OPERATOR.equals(operation)) {
COSName objectName = (COSName) operands.get(0);
PDXObject xobject = getResources().getXObject(objectName);
if (xobject instanceof PDImageXObject) {
PDImageXObject image = (PDImageXObject) xobject;
Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix();
Image im = new Image();
im.setPage(currentPage);
im.setXPosition(ctmNew.getTranslateX());
im.setYPosition(ctmNew.getTranslateY());
im.setOriginalHeight(image.getHeight());
im.setOriginalWidth(image.getWidth());
im.setRenderedWidth(Math.round(ctmNew.getScaleX()));
im.setRenderedHeight(Math.round(ctmNew.getScaleY()));
images.add(im);
if (!output.exists()) output.mkdirs();
// TODO enable option to set the output format. right now it uses original which means: tiff needs extra dependency and tiff are HUGE!
// String extension = "png";
String extension = image.getSuffix();
File out = new File(output, basename + "-" + currentPage + "-" + count + "." + extension);
ImageIO.write(image.getImage(), extension, new FileOutputStream(out));
count++;
} else if (xobject instanceof PDFormXObject) {
PDFormXObject form = (PDFormXObject) xobject;
showForm(form);
}
} else {
super.processOperator(operator, operands);
}
}
开发者ID:abelsromero,项目名称:pdf-box-examples,代码行数:46,代码来源:ImageExtractor.java
示例11: removeEldestEntry
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
protected boolean removeEldestEntry(final Entry<COSObject, SoftReference<PDXObject>> eldest) {
return size() > Environment.getNrOfImagesToCache();
}
开发者ID:red6,项目名称:pdfcompare,代码行数:5,代码来源:ResourceCacheWithLimitedImages.java
示例12: getXObject
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
public PDXObject getXObject(final COSObject indirect) throws IOException {
return null;
}
开发者ID:red6,项目名称:pdfcompare,代码行数:5,代码来源:DummyResourceCache.java
示例13: put
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
public void put(final COSObject indirect, final PDXObject xobject) throws IOException {}
开发者ID:red6,项目名称:pdfcompare,代码行数:3,代码来源:DummyResourceCache.java
示例14: removeToUnicodeMaps
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
void removeToUnicodeMaps(PDResources pdResources) throws IOException
{
COSDictionary resources = pdResources.getCOSObject();
COSDictionary fonts = asDictionary(resources, COSName.FONT);
if (fonts != null)
{
for (COSBase object : fonts.getValues())
{
while (object instanceof COSObject)
object = ((COSObject)object).getObject();
if (object instanceof COSDictionary)
{
COSDictionary font = (COSDictionary)object;
font.removeItem(COSName.TO_UNICODE);
}
}
}
for (COSName name : pdResources.getXObjectNames())
{
PDXObject xobject = pdResources.getXObject(name);
if (xobject instanceof PDFormXObject)
{
PDResources xobjectPdResources = ((PDFormXObject)xobject).getResources();
removeToUnicodeMaps(xobjectPdResources);
}
}
}
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:30,代码来源:ExtractText.java
示例15: process
import org.apache.pdfbox.pdmodel.graphics.PDXObject; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
// Get the name of the PDXOject.
COSName name = (COSName) arguments.get(0);
// Get the PDXObject.
PDXObject xobject = context.getResources().getXObject(name);
if (xobject instanceof PDFormXObject) {
context.processStream((PDFormXObject) xobject);
} else if(xobject instanceof PDImageXObject) {
PDImageXObject image = (PDImageXObject) xobject;
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
Matrix ctm = context.getCurrentTransformationMatrix().clone();
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f / imageWidth, 1f / imageHeight);
Matrix at = new Matrix(ctmAT);
Rectangle boundBox = SimpleRectangle.from2Vertices(
new SimplePoint(ctm.getTranslateX(), ctm.getTranslateY()),
new SimplePoint(ctm.getTranslateX() + at.getScaleX() * imageWidth,
ctm.getTranslateY() + at.getScaleY() * imageHeight));
// Rectangle boundBox = new SimpleRectangle();
// boundBox.setMinX(ctm.getTranslateX());
// boundBox.setMinY(ctm.getTranslateY());
// boundBox.setMaxX(ctm.getTranslateX() + at.getScaleX() * imageWidth);
// boundBox.setMaxY(ctm.getTranslateY() + at.getScaleY() * imageHeight);
PdfBoxColor exclusiveColor = getExclusiveColor(image.getImage());
if (exclusiveColor != null) {
PdfBoxShape shape = new PdfBoxShape(context.getCurrentPage());
shape.setRectangle(boundBox);
shape.setColor(exclusiveColor);
context.showShape(shape);
} else {
PdfBoxFigure figure = new PdfBoxFigure(context.getCurrentPage());
figure.setRectangle(boundBox);
context.showFigure(figure);
}
}
}
开发者ID:ckorzen,项目名称:icecite,代码行数:48,代码来源:Invoke.java
注:本文中的org.apache.pdfbox.pdmodel.graphics.PDXObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论