本文整理匯總了Java中org.apache.pdfbox.io.RandomAccessBufferedFileInputStream類的典型用法代碼示例。如果您正苦於以下問題:Java RandomAccessBufferedFileInputStream類的具體用法?Java RandomAccessBufferedFileInputStream怎麽用?Java RandomAccessBufferedFileInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RandomAccessBufferedFileInputStream類屬於org.apache.pdfbox.io包,在下文中一共展示了RandomAccessBufferedFileInputStream類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPdfFromStringTo
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; //導入依賴的package包/類
@Test
public void testPdfFromStringTo() throws Exception {
// GIVEN an html template containing special characters that java stores in utf-16 internally
Pdf pdf = pdfBuilder.build();
pdf.addPage("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>", PageType.htmlAsString);
String tempFolder = temporaryFolder.newFolder().getPath();
pdf.saveAs(tempFolder+"/output.pdf");
// WHEN
byte[] pdfBytes = pdf.getPDF();
PDFParser parser = new PDFParser(new RandomAccessBufferedFileInputStream(new ByteArrayInputStream(pdfBytes)));
// that is a valid PDF (otherwise an IOException occurs)
parser.parse();
PDFTextStripper pdfTextStripper = new PDFTextStripper();
String pdfText = pdfTextStripper.getText(new PDDocument(parser.getDocument()));
assertThat("document should contain the creditorName", pdfText, containsString("Müller"));
}
示例2: readThesaurus
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; //導入依賴的package包/類
private List<SubstanceInteraction> readThesaurus(File dir) throws IOException {
File file = new File(dir, "thesaurus.pdf");
PDFParser parser = new PDFParser(new RandomAccessBufferedFileInputStream(file));
parser.parse();
COSDocument cosDoc = parser.getDocument();
ThesaurusPDFStripper pdfStripper = new ThesaurusPDFStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(2);
pdfStripper.setEndPage(pdDoc.getNumberOfPages());
pdfStripper.getText(pdDoc);
cosDoc.close();
return pdfStripper.substances;
}
示例3: parse
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; //導入依賴的package包/類
@Test
public void parse() throws IOException {
File file = new File(MedicamentTest.class.getClassLoader().getResource(".").getFile(), "thesaurus.pdf");
PDFParser parser = new PDFParser(new RandomAccessBufferedFileInputStream(file));
parser.parse();
COSDocument cosDoc = parser.getDocument();
AdvancedPDFStripper pdfStripper = new AdvancedPDFStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(2);
pdfStripper.setEndPage(pdDoc.getNumberOfPages());
pdfStripper.getText(pdDoc);
System.out.println(pdfStripper.substances);
}
示例4: sanitize
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; //導入依賴的package包/類
@Override
public void sanitize(InputStream inputStream, OutputStream outputStream, BleachSession session) throws BleachException {
try (RandomAccessRead source = new RandomAccessBufferedFileInputStream(inputStream)) {
sanitize(source, outputStream, session);
} catch (IOException e) {
throw new BleachException(e);
}
}
示例5: readInteractions
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; //導入依賴的package包/類
private Map<String, List<Interaction>> readInteractions(File dir) throws IOException {
File file = new File(dir, "interactions.pdf");
PDFParser parser = new PDFParser(new RandomAccessBufferedFileInputStream(file));
parser.parse();
COSDocument cosDoc = parser.getDocument();
InteractionPDFStripper pdfStripper = new InteractionPDFStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(2);
pdfStripper.setEndPage(pdDoc.getNumberOfPages());
pdfStripper.getText(pdDoc);
cosDoc.close();
Map<String, List<Interaction>> interactions = pdfStripper.interactions;
Map<String, List<Interaction>> newInteractions = new HashMap<>();
for (List<Interaction> tmp : interactions.values()) {
for (Interaction interaction : tmp) {
String famille2 = normalize(interaction.getFamille2(), true);
// cas particuliers
switch (famille2) {
case "medicaments hyponatremiants":
famille2 = "hyponatremiants";
break;
}
List<Interaction> interactions2 = interactions.get(famille2);
if (interactions2 == null) {
LOG.warn("interaction " + interaction.getFamille2() + " inconnu");
Interaction newInteraction;
if (newInteractions.get(famille2) == null) {
newInteractions.put(famille2, new ArrayList<>());
newInteraction = pdfStripper.createEmptyInteraction(-1, interaction.getFamille2());
} else {
newInteraction = pdfStripper.createEmptyInteraction(Integer.parseInt(newInteractions.get(famille2).get(0).getId1()), interaction.getFamille2());
}
newInteraction.setId2(interaction.getId1());
newInteraction.setFamille2(interaction.getFamille1());
newInteraction.setDescription(interaction.getDescription());
newInteraction.setConseil(interaction.getConseil());
newInteractions.get(famille2).add(newInteraction);
interaction.setId2(newInteraction.getId1());
} else {
interaction.setId2(interactions2.get(0).getId1());
}
}
}
for (String key : newInteractions.keySet()) {
interactions.put(key, newInteractions.get(key));
}
return interactions;
}