use of org.apache.pdfbox.cos.COSString in project ddf by codice.
the class GeoPdfParserImpl method apply.
/**
* Generates a WKT compliant String from a PDF Document if it contains GeoPDF information.
* Currently, only WGS84 Projections are supported (GEOGRAPHIC GeoPDF ProjectionType).
*
* @param pdfDocument - The PDF document
* @return the WKT String
* @throws IOException
*/
@Override
public String apply(PDDocument pdfDocument) throws IOException {
ToDoubleVisitor toDoubleVisitor = new ToDoubleVisitor();
LinkedList<String> polygons = new LinkedList<>();
for (PDPage pdPage : pdfDocument.getPages()) {
COSDictionary cosObject = pdPage.getCOSObject();
COSBase lgiDictObject = cosObject.getObjectFromPath(LGIDICT);
// Handle Multiple Map Frames
if (lgiDictObject instanceof COSArray) {
for (int i = 0; i < ((COSArray) lgiDictObject).size(); i++) {
COSDictionary lgidict = (COSDictionary) cosObject.getObjectFromPath(LGIDICT + "/[" + i + "]");
COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION);
if (projectionArray != null) {
String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString();
if (GEOGRAPHIC.equals(projectionType)) {
COSArray neatlineArray = (COSArray) cosObject.getObjectFromPath(LGIDICT + "/[" + i + "]/" + NEATLINE);
String wktString = getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor);
polygons.add(wktString);
} else {
LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType);
}
} else {
LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped.");
}
}
// Handle One Map Frame
} else if (lgiDictObject instanceof COSDictionary) {
COSDictionary lgidict = (COSDictionary) lgiDictObject;
COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION);
if (projectionArray != null) {
String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString();
if (GEOGRAPHIC.equals(projectionType)) {
COSArray neatlineArray = (COSArray) cosObject.getObjectFromPath(LGIDICT + "/" + NEATLINE);
if (neatlineArray == null) {
neatlineArray = generateNeatLineFromPDFDimensions(pdPage);
}
polygons.add(getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor));
} else {
LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType);
}
} else {
LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped.");
}
}
}
if (polygons.size() == 0) {
LOGGER.debug("No GeoPDF information found on PDF during transformation. Metacard location will not be set.");
return null;
}
if (polygons.size() == 1) {
return POLYGON + polygons.get(0) + "))";
} else {
return polygons.stream().map(polygon -> "((" + polygon + "))").collect(Collectors.joining(",", MULTIPOLYGON, ")"));
}
}
use of org.apache.pdfbox.cos.COSString in project ddf by codice.
the class GeoPdfParserImpl method generateNeatLineFromPDFDimensions.
/**
* A PDF Neatline defines the area of a PDF image with relation to the PDF page. If no neatline is given
* it is assumed that the image encompasses the entire page. This functiong generates a NeatLine
* in this fashion.
* @param pdPage the page to generate the NeatLine
* @return an array of points representing the NeatLine
*/
private COSArray generateNeatLineFromPDFDimensions(PDPage pdPage) {
COSArray neatLineArray = new COSArray();
String width = String.valueOf(pdPage.getMediaBox().getWidth());
String height = String.valueOf(pdPage.getMediaBox().getHeight());
neatLineArray.add(new COSString("0"));
neatLineArray.add(new COSString("0"));
neatLineArray.add(new COSString(width));
neatLineArray.add(new COSString("0"));
neatLineArray.add(new COSString(width));
neatLineArray.add(new COSString(height));
neatLineArray.add(new COSString("0"));
neatLineArray.add(new COSString(height));
return neatLineArray;
}
use of org.apache.pdfbox.cos.COSString in project ddf by codice.
the class GeoPdfDocumentGenerator method generateNeatLineArray.
private static COSArray generateNeatLineArray() {
COSArray neatLineArray = new COSArray();
neatLineArray.add(new COSString("1563.749999999969"));
neatLineArray.add(new COSString("1992.384698215686"));
neatLineArray.add(new COSString("1563.75000000011"));
neatLineArray.add(new COSString("239.6265517842302"));
neatLineArray.add(new COSString("74.23874999988999"));
neatLineArray.add(new COSString("239.6265517846492"));
neatLineArray.add(new COSString("74.23875000008906"));
neatLineArray.add(new COSString("1992.38469821535"));
neatLineArray.add(new COSString("1563.749999999969"));
neatLineArray.add(new COSString("1992.384698215686"));
return neatLineArray;
}
use of org.apache.pdfbox.cos.COSString in project ddf by codice.
the class GeoPdfDocumentGenerator method generateCTMArray.
private static COSArray generateCTMArray() {
COSArray ctmArray = new COSArray();
ctmArray.add((new COSString("0.003591954022988553")));
ctmArray.add((new COSString("7.868785750012534e-017")));
ctmArray.add((new COSString("-7.868785750012534e-017")));
ctmArray.add((new COSString("0.003591954022988553")));
ctmArray.add((new COSString("-80.77532309213824")));
ctmArray.add((new COSString("36.77844766314338")));
return ctmArray;
}
Aggregations