當前位置: 首頁>>代碼示例>>Java>>正文


Java PDDocument.load方法代碼示例

本文整理匯總了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;
}
 
開發者ID:malikalamgirian,項目名稱:PDF2RDF,代碼行數:27,代碼來源:TitleExtractor.java

示例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);
	}
	
}
 
開發者ID:CoffeeCodeSwitzerland,項目名稱:Lernkartei_2017,代碼行數:16,代碼來源:Printer.java

示例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();
		}
	}
}
 
開發者ID:mgropp,項目名稱:pdfjumbler,代碼行數:35,代碼來源:PdfEditor.java

示例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()));
    }
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:14,代碼來源:TestObjectExtractor.java

示例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());

}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:12,代碼來源:TestObjectExtractor.java

示例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));
    }
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:12,代碼來源:TestObjectExtractor.java

示例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);

}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:12,代碼來源:TestObjectExtractor.java

示例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();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:11,代碼來源:PDFExtractionExample.java

示例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;
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:40,代碼來源:Settings.java

示例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());
    }
}
 
開發者ID:rostrovsky,項目名稱:pdf-table,代碼行數:12,代碼來源:PdfTableReaderTest.java

示例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);

}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:10,代碼來源:TestObjectExtractor.java

示例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;
}
 
開發者ID:neal1991,項目名稱:everywhere,代碼行數:14,代碼來源:FileBeanParser.java

示例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;
}
 
開發者ID:malikalamgirian,項目名稱:PDF2RDF,代碼行數:29,代碼來源:AuthorExtractor.java

示例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);
}
 
開發者ID:redmyers,項目名稱:484_P7_1-Java,代碼行數:13,代碼來源:TestObjectExtractor.java


注:本文中的org.apache.pdfbox.pdmodel.PDDocument.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。