当前位置: 首页>>代码示例>>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;未经允许,请勿转载。