add color/gray detection
This commit is contained in:
parent
2fdccf2c79
commit
319dd41658
1 changed files with 12 additions and 6 deletions
|
@ -8,6 +8,8 @@ import org.apache.pdfbox.pdmodel.PDDocument;
|
|||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDResources;
|
||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
|
||||
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
|
||||
import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
|
||||
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
||||
|
||||
|
@ -99,10 +101,9 @@ public class DocumentAnalyzer {
|
|||
m.put("mediabox", Map.of("height", page.getMediaBox().getHeight(), "width", page.getMediaBox().getWidth()));
|
||||
m.put("bleedbox", Map.of("height", page.getBleedBox().getHeight(), "width", page.getBleedBox().getWidth()));
|
||||
m.put("rotation", page.getRotation());
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
ImageGraphicsExtractor extractor = new ImageGraphicsExtractor(list, page);
|
||||
ImageGraphicsExtractor extractor = new ImageGraphicsExtractor(page);
|
||||
extractor.process();
|
||||
m.put("images", list);
|
||||
m.put("images", extractor.getList());
|
||||
List<Map<String, Object>> fonts = new ArrayList<>();
|
||||
PDResources res = page.getResources();
|
||||
for (COSName cosName : res.getFontNames()) {
|
||||
|
@ -125,18 +126,21 @@ public class DocumentAnalyzer {
|
|||
|
||||
private final List<Map<String, Object>> list;
|
||||
|
||||
protected ImageGraphicsExtractor(List<Map<String, Object>> list, PDPage page) {
|
||||
protected ImageGraphicsExtractor(PDPage page) {
|
||||
super(page);
|
||||
this.list = list;
|
||||
this.list = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void process() throws IOException {
|
||||
processPage(getPage());
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,6 +156,8 @@ public class DocumentAnalyzer {
|
|||
m.put("height", xobject.getHeight());
|
||||
m.put("bitspercomponent", xobject.getBitsPerComponent());
|
||||
m.put("colorspace", xobject.getColorSpace().getName());
|
||||
m.put("iscolor", PDDeviceRGB.INSTANCE.getName().equals(xobject.getColorSpace().getName()));
|
||||
m.put("isgray", PDDeviceGray.INSTANCE.getName().equals(xobject.getColorSpace().getName()));
|
||||
m.put("suffix", xobject.getSuffix());
|
||||
list.add(m);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue