private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException {
GeneralPath path = null;
AffineTransform at = textRenderingMatrix.createAffineTransform();
at.concatenate(font.getFontMatrix().createAffineTransform());
if (font instanceof PDType3Font) {
// It is difficult to calculate the real individual glyph bounds for type 3
// fonts
// because these are not vector fonts, the content stream could contain almost
// anything
// that is found in page content streams.
PDType3Font t3Font = (PDType3Font) font;
PDType3CharProc charProc = t3Font.getCharProc(code);
if (charProc != null) {
BoundingBox fontBBox = t3Font.getBoundingBox();
PDRectangle glyphBBox = charProc.getGlyphBBox();
if (glyphBBox != null) {
// PDFBOX-3850: glyph bbox could be larger than the font bbox
glyphBBox.setLowerLeftX(Math.max(fontBBox.getLowerLeftX(), glyphBBox.getLowerLeftX()));
glyphBBox.setLowerLeftY(Math.max(fontBBox.getLowerLeftY(), glyphBBox.getLowerLeftY()));
glyphBBox.setUpperRightX(Math.min(fontBBox.getUpperRightX(), glyphBBox.getUpperRightX()));
glyphBBox.setUpperRightY(Math.min(fontBBox.getUpperRightY(), glyphBBox.getUpperRightY()));
path = glyphBBox.toGeneralPath();
}
}
} else if (font instanceof PDVectorFont) {
PDVectorFont vectorFont = (PDVectorFont) font;
path = vectorFont.getPath(code);
if (font instanceof PDTrueTypeFont) {
PDTrueTypeFont ttFont = (PDTrueTypeFont) font;
int unitsPerEm = ttFont.getTrueTypeFont().getHeader().getUnitsPerEm();
at.scale(1000d / unitsPerEm, 1000d / unitsPerEm);
}
if (font instanceof PDType0Font) {
PDType0Font t0font = (PDType0Font) font;
if (t0font.getDescendantFont() instanceof PDCIDFontType2) {
int unitsPerEm = ((PDCIDFontType2) t0font.getDescendantFont()).getTrueTypeFont().getHeader()
.getUnitsPerEm();
at.scale(1000d / unitsPerEm, 1000d / unitsPerEm);
}
}
} else if (font instanceof PDSimpleFont) {
PDSimpleFont simpleFont = (PDSimpleFont) font;
// these two lines do not always work, e.g. for the TT fonts in file 032431.pdf
// which is why PDVectorFont is tried first.
String name = simpleFont.getEncoding().getName(code);
path = simpleFont.getPath(name);
} else {
// shouldn't happen, please open issue in JIRA
System.out.println("Unknown font class: " + font.getClass());
}
if (path == null) {
return null;
}
return at.createTransformedShape(path.getBounds2D());
}
Итак, я использовал приведенный выше код, чтобы сохранить тег из PDF-файла с тегами и сохранить его как JSon. Но ограничивающая рамка таблицы и списка не становится правильной. Ограничение абзацев и заголовков корректируется согласно приведенной выше логике. поэтому, пожалуйста, помогите. Заранее спасибо.
Я пытаюсь сохранить тег из документа PDF с тегами. Я попробовал один подход, но мне нужно
получить правильную ограничивающую рамку таблицы и списка, используя следующий код. пожалуйста, помогите кому-нибудь в этом. [code] public void Process(TaggedJsonPart taggedJsonPart) throws IOException { Map > markedContents = new HashMap();
for (PDPage page : document.getPages()) { PDFMarkedContentExtractor extractor = new PDFMarkedContentExtractor(); extractor.processPage(page); Map theseMarkedContents = new HashMap(); markedContents.put(page, theseMarkedContents); for (PDMarkedContent markedContent : extractor.getMarkedContents()) { addToMap(theseMarkedContents, markedContent); } }
PDStructureNode root = document.getDocumentCatalog().getStructureTreeRoot(); Map visualizations = new HashMap();
return box; } [/code] [code]private Shape calculateGlyphBounds(Matrix textRenderingMatrix, PDFont font, int code) throws IOException { GeneralPath path = null; AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); if (font instanceof PDType3Font) { // It is difficult to calculate the real individual glyph bounds for type 3 // fonts // because these are not vector fonts, the content stream could contain almost // anything // that is found in page content streams. PDType3Font t3Font = (PDType3Font) font; PDType3CharProc charProc = t3Font.getCharProc(code); if (charProc != null) { BoundingBox fontBBox = t3Font.getBoundingBox(); PDRectangle glyphBBox = charProc.getGlyphBBox(); if (glyphBBox != null) { // PDFBOX-3850: glyph bbox could be larger than the font bbox glyphBBox.setLowerLeftX(Math.max(fontBBox.getLowerLeftX(), glyphBBox.getLowerLeftX())); glyphBBox.setLowerLeftY(Math.max(fontBBox.getLowerLeftY(), glyphBBox.getLowerLeftY())); glyphBBox.setUpperRightX(Math.min(fontBBox.getUpperRightX(), glyphBBox.getUpperRightX())); glyphBBox.setUpperRightY(Math.min(fontBBox.getUpperRightY(), glyphBBox.getUpperRightY())); path = glyphBBox.toGeneralPath(); } } } else if (font instanceof PDVectorFont) { PDVectorFont vectorFont = (PDVectorFont) font; path = vectorFont.getPath(code);
// these two lines do not always work, e.g. for the TT fonts in file 032431.pdf // which is why PDVectorFont is tried first. String name = simpleFont.getEncoding().getName(code); path = simpleFont.getPath(name); } else { // shouldn't happen, please open issue in JIRA System.out.println("Unknown font class: " + font.getClass()); } if (path == null) { return null; }
return at.createTransformedShape(path.getBounds2D()); } [/code] Итак, я использовал приведенный выше код, чтобы сохранить тег из PDF-файла с тегами и сохранить его как JSon. Но ограничивающая рамка таблицы и списка не становится правильной. Ограничение абзацев и заголовков корректируется согласно приведенной выше логике. поэтому, пожалуйста, помогите. Заранее спасибо.
Я хочу использовать PDFBox, чтобы получить тексты из PDF-файла с их ограничивающими рамками. Мне удалось собрать здесь код, который делает почти это, но, как вы можете видеть, полученные мной ограничивающие рамки (нарисованные синим цветом) имеют...
Я разрабатываю приложение для Android, в котором мне нужно добавлять и удалять изображения из PDF-документа. Для этой цели я использую библиотеку PDFBox. Я успешно добавил изображения в PDF-файл с определенным тегом, но пытаюсь удалить их на основе...
Я разрабатываю приложение для Android, в котором мне нужно добавлять и удалять изображения из PDF-документа. Для этой цели я использую библиотеку PDFBox. Я успешно добавил изображения в PDF-файл с определенным тегом, но пытаюсь удалить их на основе...