本文整理汇总了Java中org.jpedal.exception.PdfException类的典型用法代码示例。如果您正苦于以下问题:Java PdfException类的具体用法?Java PdfException怎么用?Java PdfException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfException类属于org.jpedal.exception包,在下文中一共展示了PdfException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: splitToExamPapersWithPDFStreams
import org.jpedal.exception.PdfException; //导入依赖的package包/类
/**
* Splits a PDF-document into exam papers.
*
* @param pdfStream PDF-file as InputStream
* @return A List of ExamPapers.
* @throws IOException If InputStream can not be read or stream doesn't
* contain a PDF-format file.
* @throws DocumentException If document contains odd number of pages.
* @throws PdfException If a document is not in the right format or error
* occurs while loading or splitting or document has an odd number of pages.
* @throws COSVisitorException if something goes wrong when visiting a PDF
* object.
*/
public List<ExamPaper> splitToExamPapersWithPDFStreams(InputStream pdfStream) throws IOException, DocumentException, PdfException, COSVisitorException {
PDDocument allPdfDocument = PDDocument.load(pdfStream);
if (allPdfDocument.getNumberOfPages() % 2 != 0) {
throw new DocumentException("Odd number of pages");
}
Splitter splitter = new Splitter();
splitter.setSplitAtPage(2);
List<PDDocument> pdfDocuments = splitter.split(allPdfDocument);
ArrayList<ExamPaper> examPapers = new ArrayList<>();
for (PDDocument pdfDocument : pdfDocuments) {
ExamPaper paper = new ExamPaper();
ByteArrayOutputStream out = new ByteArrayOutputStream();
pdfDocument.save(out);
byte[] data = out.toByteArray();
paper.setPdf(data);
examPapers.add(paper);
pdfDocument.close();
}
allPdfDocument.close();
return examPapers;
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:35,代码来源:PDFSplitter.java
示例2: renderPage
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public Image renderPage(Page page, int maxWidth, int maxHeight) throws IOException {
PdfDecoderFX pdfDecoder = docMap.get(page.getFile());
if (pdfDecoder == null) {
pdfDecoder = openDocument(page.getFile());
}
try {
return scaleImage(
pdfDecoder.getPageAsImage(page.getIndex() + 1),
maxWidth, maxHeight
);
}
catch (PdfException e) {
throw new IOException(e);
}
}
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:18,代码来源:PdfRenderer.java
示例3: run
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public final void run() {
PdfDecoder pdfDecoder = new PdfDecoder();
try {
pdfDecoder.openPdfFile(source.getAbsolutePath());
} catch (PdfException e1) {
e1.printStackTrace();
}
for (PageCluster cluster : clusters.getClusterList()) {
for (Integer pageNumber : cluster.getPagesToMerge()) {
// TODO jpedal isn't able to render big images
// correctly, so let's check if the image is big an
// throw it away
try {
if (cluster.getImageData().isRenderable()) {
BufferedImage renderedPage = pdfDecoder.getPageAsImage(pageNumber);
cluster.getImageData().addImageToPreview(renderedPage);
workerUnitCounter++;
}
} catch (PdfException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// now close the reader as it's not used anymore
pdfDecoder.closePdfFile();
}
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:31,代码来源:ClusterRenderWorker.java
示例4: writeImage
import org.jpedal.exception.PdfException; //导入依赖的package包/类
private static void writeImage(PdfDecoder dec, int page, Resource destination,String format, int scale,
boolean overwrite, boolean goodQuality, boolean transparent) throws PageException, IOException {
if(scale<1 || scale>100)
throw new ExpressionException("invalid scale definition ["+Caster.toString(scale)+"], value should be in range from 1 to 100");
Image img=null;
try {
img = new Image(transparent?dec.getPageAsTransparentImage(page):dec.getPageAsImage(page));
} catch (PdfException e) {
throw Caster.toPageException(e);
}
if(scale!=100)
img.resize(scale, goodQuality?"highestquality":"highperformance", 1);
img.writeOut(destination,format, overwrite, 1f);
}
开发者ID:lucee,项目名称:Lucee4,代码行数:17,代码来源:PDF2ImageJPedal.java
示例5: process
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public void process(List<ExamPaper> examPapers) {
ExamPaper courseInfoPage = examPapers.get(0);
CourseInfo courseInfo = null;
try {
courseInfoPage.setPageImages(pdfProcessor.getPageImages(courseInfoPage));
courseInfoPage.setQRCodeString(pdfProcessor.readQRCode(courseInfoPage));
courseInfo = getCourseInfo(courseInfoPage);
// Remove if succesful so that the page won't be processed as
// a normal exam paper.
examPapers.remove(0);
LOGGER.debug("Kurssi-info luettu onnistuneesti.");
} catch (PdfException | NotFoundException ex) {
exceptionLogger.logException(ex);
}
// Process all examPapers
while (!examPapers.isEmpty()) {
ExamPaper examPaper = examPapers.remove(0);
// Add course info (doesn't matter if null)
examPaper.setCourseInfo(courseInfo);
processNextStages(examPaper);
}
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:25,代码来源:ReadCourseInfoStage.java
示例6: process
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public void process(ExamPaper examPaper) {
try {
examPaper.setPageImages(pdfProcessor.getPageImages(examPaper));
examPaper.setQRCodeString(pdfProcessor.readQRCode(examPaper));
} catch (PdfException | NotFoundException ex) {
exceptionLogger.logException(ex);
LOGGER.debug("QR-koodia ei pystytty lukemaan.");
if (saveOnExamPaperPDFError) {
try {
InputStream stream = new ByteArrayInputStream(examPaper.getPdf());
fileSaver.saveInputStream(stream, saveErrorFolder, "" + System.currentTimeMillis() + ".pdf");
IOUtils.closeQuietly(stream);
LOGGER.debug("Tallennettin virheellinen PDF.");
} catch (FileAlreadyExistsException ex1) {
exceptionLogger.logException(ex);
}
}
// Don't continue if we couldn't read QR code.
return;
}
processNextStages(examPaper);
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:24,代码来源:ReadQRCodeStage.java
示例7: render
import org.jpedal.exception.PdfException; //导入依赖的package包/类
/**
* Renders the specified page
*
* @param nr
* number of page to render (0-based)
* @param titelPage
* draw the given page as title page
* @return Image of the page
*/
public BufferedImage render(int nr, boolean titlePage) {
BufferedImage im = new BufferedImage(600, 800,
BufferedImage.TYPE_4BYTE_ABGR);
try {
decoder.setPageParameters(1, -1);
BufferedImage page = decoder.getPageAsImage(nr + 1);
float scaleX = 600f / page.getWidth();
float scaleY = 800f / page.getHeight();
decoder.setPageParameters(Math.min(scaleX, scaleY), -1);
page = decoder.getPageAsImage(nr + 1);
if (titlePage) {
drawTitlePage(author, title, page, im.getGraphics());
} else {
drawBookPage((pages - 1), nr, page, im.getGraphics(), bookmarks);
}
} catch (PdfException e) {
e.printStackTrace();
}
return im;
}
开发者ID:schierla,项目名称:jbeagle,代码行数:30,代码来源:BeagleRenderer.java
示例8: init
import org.jpedal.exception.PdfException; //导入依赖的package包/类
public void init(String fileName) throws PdfException, AccessException,
EncryptionException {
if (decoder.isOpen()) {
decoder.flushObjectValues(true);
decoder.closePdfFile();
}
decoder.openPdfFile(fileName);
currentPage = 1;
pageCount = decoder.getPageCount();
if (!decoder.isExtractionAllowed()) {
throw new AccessException(fileName);
} else if (decoder.isEncrypted()) {
throw new EncryptionException(fileName);
}
}
开发者ID:GullyAPCBurns,项目名称:lapdftext,代码行数:18,代码来源:JPedalPageImageExtractor.java
示例9: openDocument
import org.jpedal.exception.PdfException; //导入依赖的package包/类
private PdfDecoderFX openDocument(File file) throws IOException {
ensureInitialized();
PdfDecoderFX pdfDecoder = new PdfDecoderFX();
//PdfDecoderFX.setFontReplacements(pdfDecoder);
try {
pdfDecoder.openPdfFile(file.getAbsolutePath());
}
catch (PdfException e) {
throw new IOException(e);
}
docMap.put(file, pdfDecoder);
return pdfDecoder;
}
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:16,代码来源:PdfRenderer.java
示例10: importNewPdfFile
import org.jpedal.exception.PdfException; //导入依赖的package包/类
protected void importNewPdfFile(File loadFile) throws IOException, PdfException {
lastOpenDir = loadFile.getParentFile();
previewPanel.removeAll();
cardLayout.first(wrapperPanel);
progressBar.setVisible(true);
progressBar.setString(Messages.getString("BrissGUI.loadingNewFile")); //$NON-NLS-1$
ClusterPagesTask clusterTask = new ClusterPagesTask(loadFile, null);
clusterTask.addPropertyChangeListener(this);
clusterTask.execute();
}
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:11,代码来源:BrissGUI.java
示例11: reloadWithOtherExcludes
import org.jpedal.exception.PdfException; //导入依赖的package包/类
private void reloadWithOtherExcludes() throws IOException, PdfException {
previewPanel.removeAll();
progressBar.setString(Messages.getString("BrissGUI.reloadingFile")); //$NON-NLS-1$
ClusterPagesTask clusterTask = new ClusterPagesTask(workingSet.getSourceFile(), getExcludedPages());
clusterTask.addPropertyChangeListener(this);
clusterTask.execute();
}
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:8,代码来源:BrissGUI.java
示例12: createClusterJob
import org.jpedal.exception.PdfException; //导入依赖的package包/类
public static ClusterJob createClusterJob(File origFile) throws IOException, PdfException {
PdfReader reader = new PdfReader(origFile.getAbsolutePath());
ClusterJob clusterJob = new ClusterJob(origFile);
reader.close();
return clusterJob;
}
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:8,代码来源:ClusterManager.java
示例13: run
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public void run() {
PdfDecoder pdfDecoder = new PdfDecoder(true);
try {
pdfDecoder.openPdfFile(clusterJob.getSource().getAbsolutePath());
} catch (PdfException e1) {
e1.printStackTrace();
}
for (SingleCluster cluster : clusterJob.getClusterCollection().getAsList()) {
for (Integer pageNumber : cluster.getPagesToMerge()) {
// TODO jpedal isn't able to render big images
// correctly, so let's check if the image is big an
// throw it away
try {
if (cluster.getImageData().isRenderable()) {
BufferedImage renderedPage = pdfDecoder.getPageAsImage(pageNumber);
cluster.getImageData().addImageToPreview(renderedPage);
workerUnitCounter++;
}
} catch (PdfException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// now close the reader as it's not used anymore
pdfDecoder.closePdfFile();
}
开发者ID:mbaeuerle,项目名称:Briss-2.0,代码行数:31,代码来源:ClusterManager.java
示例14: toImage
import org.jpedal.exception.PdfException; //导入依赖的package包/类
public Image toImage(byte[] input,int page) throws IOException, PageException {
try {
return new Image(createPdfDecoder(input).getPageAsImage(page));
} catch (PdfException e) {
throw Caster.toPageException(e);
}
}
开发者ID:lucee,项目名称:Lucee4,代码行数:8,代码来源:PDF2ImageJPedal.java
示例15: createPdfDecoder
import org.jpedal.exception.PdfException; //导入依赖的package包/类
private static PdfDecoder createPdfDecoder(byte[] input) throws PageException {
PdfDecoder decoder = new PdfDecoder(true);
decoder.useHiResScreenDisplay(true);
try {
decoder.openPdfArray(input);
} catch (PdfException e) {
throw Caster.toPageException(e);
}
return decoder;
}
开发者ID:lucee,项目名称:Lucee4,代码行数:11,代码来源:PDF2ImageJPedal.java
示例16: splitPDF
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public List<ExamPaper> splitPDF(InputStream pdfStream) throws DocumentException {
try {
return splitter.splitToExamPapersWithPDFStreams(pdfStream);
} catch (IOException | PdfException | DocumentException | COSVisitorException ex) {
throw new DocumentException(ex.getMessage());
}
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:9,代码来源:PDFProcessorImpl.java
示例17: getPageImages
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Override
public List<BufferedImage> getPageImages(ExamPaper examPaper) throws PdfException {
PdfDecoder pdf = new PdfDecoder(false);
pdf.setExtractionMode(PdfDecoder.FINALIMAGES);
InputStream is = new ByteArrayInputStream(examPaper.getPdf());
pdf.openPdfFileFromInputStream(is, true);
ArrayList<BufferedImage> pageImages = new ArrayList<>();
for (int i = 1; i <= pdf.getPageCount(); i++) {
pageImages.add(pdf.getPageAsImage(i));
}
return pageImages;
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:14,代码来源:PDFProcessorImpl.java
示例18: testReadQRCode
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Test
public void testReadQRCode() throws DocumentException, PdfException {
List<ExamPaper> splitPDF = processor.splitPDF(getClass().getResourceAsStream("/pdf/all.pdf"));
int errors = 0;
for (ExamPaper examPaper : splitPDF) {
try {
examPaper.setPageImages(processor.getPageImages(examPaper));
processor.readQRCode(examPaper);
} catch (NotFoundException ex) {
errors++;
}
}
assertEquals(1, errors);
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:15,代码来源:PDFProcessorImplTest.java
示例19: testAllSpeeds
import org.jpedal.exception.PdfException; //导入依赖的package包/类
@Test
public void testAllSpeeds() throws DocumentException, PdfException, NotFoundException {
Runtime runtime = Runtime.getRuntime();
double splittingTime = System.currentTimeMillis();
InputStream file = getClass().getResourceAsStream("/pdf/massive.pdf");
List<ExamPaper> examPapers = pdfProcessor.splitPDF(file);
splittingTime = System.currentTimeMillis() - splittingTime;
double readingTime = System.currentTimeMillis();
int paperAmount = examPapers.size();
long memorySum = 0;
while (!examPapers.isEmpty()) {
ExamPaper examPaper = examPapers.remove(0);
examPaper.setPageImages(pdfProcessor.getPageImages(examPaper));
examPaper.setQRCodeString(pdfProcessor.readQRCode(examPaper));
// SLOW BUT LOW MEMORY
// runtime.gc();
long memory = runtime.totalMemory() - runtime.freeMemory();
//System.out.println("total memory:"+ bytesToMegabytes(runtime.totalMemory()));
memorySum += bytesToMegabytes(memory);
}
readingTime = System.currentTimeMillis() - readingTime;
System.out.println("It took " + splittingTime + "ms to split " + paperAmount + " ExamPapers.");
System.out.println("It took " + readingTime + "ms to read " + paperAmount + " ExamPapers.");
System.out.println("It took a total of " + (splittingTime + readingTime) + " milliseconds.");
System.out.println("It took an average of " + (splittingTime + readingTime) / paperAmount + " milliseconds per examPaper");
System.out.println("Used average " + memorySum / paperAmount + "MB of memory per examPaper.");
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:28,代码来源:PDFProcessingSpeedTest.java
示例20: testProcess
import org.jpedal.exception.PdfException; //导入依赖的package包/类
/**
* Test of process method, of class ReadQRCodeStage.
*/
@Test
public void testProcess() throws PdfException, NotFoundException {
readqrCodeStage.process(examPaperMock);
verify(examPaperMock, times(1)).setPageImages(any(List.class));
verify(examPaperMock, times(1)).setQRCodeString(anyString());
verify(nextSatageMock, times(1)).process(examPaperMock);
}
开发者ID:ohtuprojekti,项目名称:OKKoPa,代码行数:12,代码来源:ReadQRCodeStageTest.java
注:本文中的org.jpedal.exception.PdfException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论