本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPage.getContents方法的典型用法代码示例。如果您正苦于以下问题:Java PDPage.getContents方法的具体用法?Java PDPage.getContents怎么用?Java PDPage.getContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.PDPage
的用法示例。
在下文中一共展示了PDPage.getContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildImgKeyToPolNameMapping
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
private static void buildImgKeyToPolNameMapping(PDPage page) throws IOException {
PDStream contents = page.getContents();
PDFStreamParser parser = new PDFStreamParser(contents.getStream());
parser.parse();
List tokens = parser.getTokens();
boolean concatStringPhase = false;
String polName = "";
String lastText = "";
for (int index = 0; index < tokens.size(); index++) {
Object obj = tokens.get(index);
if (obj instanceof PDFOperator) {
PDFOperator op = (PDFOperator) obj;
if (op.getOperation().equals("BT")) {
concatStringPhase = true;
polName = lastText;
lastText = "";
}
else if (op.getOperation().equals("ET")) {
concatStringPhase = false;
}
}
else if (concatStringPhase && obj instanceof COSString) {
COSString cosString = (COSString) obj;
lastText += " " + cosString.getString();
lastText = lastText.trim();
}
else if (!concatStringPhase && obj instanceof COSName) {
COSName cosName = (COSName) obj;
if (cosName.getName().startsWith("img")) {
mapImgKeyToPolName.put(cosName.getName(), polName);
}
}
}
}
示例2: processPages
import org.apache.pdfbox.pdmodel.PDPage; //导入方法依赖的package包/类
/**
* This will process all of the pages and the text that is in them.
*
* @param pages The pages object in the document.
*
* @throws IOException If there is an error parsing the text.
*/
protected void processPages( List<COSObjectable> pages ) throws IOException
{
if( startBookmark != null )
{
startBookmarkPageNumber = getPageNumber( startBookmark, pages );
}
if( endBookmark != null )
{
endBookmarkPageNumber = getPageNumber( endBookmark, pages );
}
if( startBookmarkPageNumber == -1 && startBookmark != null &&
endBookmarkPageNumber == -1 && endBookmark != null &&
startBookmark.getCOSObject() == endBookmark.getCOSObject() )
{
//this is a special case where both the start and end bookmark
//are the same but point to nothing. In this case
//we will not extract any text.
startBookmarkPageNumber = 0;
endBookmarkPageNumber = 0;
}
Iterator<COSObjectable> pageIter = pages.iterator();
while( pageIter.hasNext() )
{
PDPage nextPage = (PDPage)pageIter.next();
PDStream contentStream = nextPage.getContents();
currentPageNo++;
if( contentStream != null )
{
COSStream contents = contentStream.getStream();
processPage( nextPage, contents );
}
}
}