本文整理匯總了Java中org.apache.pdfbox.pdmodel.PDDocument.load方法的典型用法代碼示例。如果您正苦於以下問題:Java PDDocument.load方法的具體用法?Java PDDocument.load怎麽用?Java PDDocument.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.pdfbox.pdmodel.PDDocument
的用法示例。
在下文中一共展示了PDDocument.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
private boolean process() throws IOException {
boolean toReturn = false;
PDFTextStripper stripper = new TitleExtractor();
PDDocument document = null;
try {
document = PDDocument.load(new File(this.getFileNamePathWithExtension()));
//((TitleExtractor) stripper).setFileNamePathWithExtension(this.getFileNamePathWithExtension());
stripper.setSortByPosition(true);
stripper.setStartPage(0);
stripper.setEndPage(1);
Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
stripper.writeText(document, dummy);
setTitle(((TitleExtractor) stripper).getTitle());
toReturn = true;
} finally {
if (document != null) {
document.close();
}
}
return toReturn;
}
示例2: printDocument
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
public static void printDocument() throws IOException, PrinterException
{
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.TWO_SIDED_SHORT_EDGE);
PDDocument input = PDDocument.load(new File("Karteikarten.pdf"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(input));
if (job.printDialog(pras)) {
job.print(pras);
}
}
示例3: saveDocument
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Override
public void saveDocument(List<Page> pages, File file) throws IOException {
if (pages.size() == 0) {
throw new IOException("Empty document.");
}
PDDocument outDoc = new PDDocument();
Map<File,PDDocument> docs = new HashMap<File,PDDocument>();
try {
for (Page page : pages) {
PDDocument pageDoc = docs.get(page.getFile());
if (pageDoc == null) {
pageDoc = PDDocument.load(page.getFile());
docs.put(page.getFile(), pageDoc);
}
outDoc.addPage((PDPage)pageDoc.getPrintable(page.getIndex()));
}
try {
outDoc.save(file.toString());
}
catch (COSVisitorException e) {
throw new IOException(e);
}
}
finally {
outDoc.close();
for (PDDocument doc : docs.values()) {
doc.close();
}
}
}
示例4: testShouldDetectRulings
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test
public void testShouldDetectRulings() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/should_detect_rulings.pdf"));
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
Page page = pi.next();
List<Ruling> rulings = page.getRulings();
for (Ruling r: rulings) {
assertTrue(page.contains(r.getBounds()));
}
}
示例5: testTextExtractionDoesNotRaise
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test
public void testTextExtractionDoesNotRaise() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/rotated_page.pdf"));
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
assertTrue(pi.hasNext());
assertNotNull(pi.next());
assertFalse(pi.hasNext());
}
示例6: testTextElementsContainedInPage
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test
public void testTextElementsContainedInPage() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/cs-en-us-pbms.pdf"));
ObjectExtractor oe = new ObjectExtractor(pdf_document);
Page page = oe.extractPage(1);
for (TextElement te: page.getText()) {
assertTrue(page.contains(te));
}
}
示例7: testExtractOnePage
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test
public void testExtractOnePage() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf"));
assertEquals(2, pdf_document.getNumberOfPages());
ObjectExtractor oe = new ObjectExtractor(pdf_document);
Page page = oe.extract(2);
assertNotNull(page);
}
示例8: main
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
PDDocument document = PDDocument.load(new File("PDF File.pdf"));
PDFTextStripper Tstripper = new PDFTextStripper();
String documentText = Tstripper.getText(document);
System.out.println(documentText);
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: checkPDFTemplateFileName
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
private static String checkPDFTemplateFileName(String PDFTemplateFileName, String path) throws IOException, IllegalArgumentException {
String template;
if (PDFTemplateFileName != null && PDFTemplateFileName.length() > 0) {
File file = new File(PDFTemplateFileName);
if (file.exists()) {
if (file.isFile()) {
if (file.canRead()) {
PDDocument doc = null;
try {
doc = PDDocument.load(file);
PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
contentStream.close();
template = file.getCanonicalPath();
} catch (Exception e) {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR,
DefaultMessages.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR, PDFTemplateFileName), e);
} finally {
if (doc != null) {
doc.close();
}
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_ACCESS_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_ACCESS_ERROR,
PDFTemplateFileName));
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_NOTAFILE_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_NOTAFILE_ERROR,
PDFTemplateFileName));
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR,
PDFTemplateFileName));
}
} else {
template = "";
}
return template;
}
示例10: getTestPDF
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
private PDDocument getTestPDF() {
try {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(TEST_FILENAME).getFile());
return PDDocument.load(file);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getCause());
}
}
示例11: testExtractWrongPageNumber
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test(expected = IndexOutOfBoundsException.class)
public void testExtractWrongPageNumber() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf"));
assertEquals(2, pdf_document.getNumberOfPages());
ObjectExtractor oe = new ObjectExtractor(pdf_document);
oe.extract(3);
}
示例12: extractPdfText
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
/**
* Extracts all the Text inside a Pdf
*/
private static String extractPdfText(byte[] pdfData) throws IOException {
PDDocument pdfDocument = PDDocument.load(new ByteArrayInputStream(pdfData));
try {
return new PDFTextStripper().getText(pdfDocument);
} finally {
pdfDocument.close();
}
}
開發者ID:jonashackt,項目名稱:cxf-spring-cloud-netflix-docker,代碼行數:12,代碼來源:WeatherBackendApplicationTests.java
示例13: readPdf
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
private static String readPdf(InputStream is) throws Exception {
String result;
PDDocument doc = PDDocument.load(is);
PDFTextStripper stripper = new PDFTextStripper();
result = stripper.getText(doc);
if(doc!= null) {
doc.close();
}
if (is != null) {
is.close();
}
return result;
}
示例14: process
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
private boolean process() throws IOException {
boolean toReturn = false;
PDFTextStripper stripper = new AuthorExtractor();
PDDocument document = null;
try {
document = PDDocument.load(new File(this.getFileNamePathWithExtension()));
//((TitleExtractor) stripper).setFileNamePathWithExtension(this.getFileNamePathWithExtension());
stripper.setSortByPosition(true);
stripper.setStartPage(0);
stripper.setEndPage(1);
Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
stripper.writeText(document, dummy);
setAuthorNames(((AuthorExtractor) stripper).getAuthorNames());
setAuthorAffiliations(((AuthorExtractor) stripper).getAuthorAffiliations());
setAuthorContacts(((AuthorExtractor) stripper).getAuthorContacts());
toReturn = true;
} finally {
if (document != null) {
document.close();
}
}
return toReturn;
}
示例15: testCanReadPDFWithOwnerEncryption
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
@Test
public void testCanReadPDFWithOwnerEncryption() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf"));
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
int i = 0;
while (pi.hasNext()) {
i++;
pi.next();
}
assertEquals(2, i);
}