本文整理汇总了Java中org.jpedal.exception.PdfException类的典型用法代码示例。如果您正苦于以下问题:Java PdfException类的具体用法?Java PdfException怎么用?Java PdfException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfException类属于org.jpedal.exception包,在下文中一共展示了PdfException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}