Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r43 - trunk/java/ch/idok/qtgui

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r43 - trunk/java/ch/idok/qtgui


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r43 - trunk/java/ch/idok/qtgui
  • Date: Thu, 13 Mar 2008 16:34:02 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: huebner AT PSI.CH
Date: Thu Mar 13 16:34:01 2008
New Revision: 43

Log:
Improved the preview of PDF files by using Suns pdf-renderer and removing the
need for a temporary file for conversion, speeding up the loading and display
of PDFs in the preview Widget.

Modified:
trunk/java/ch/idok/qtgui/PreviewWidget.java

Modified: trunk/java/ch/idok/qtgui/PreviewWidget.java
==============================================================================
--- trunk/java/ch/idok/qtgui/PreviewWidget.java (original)
+++ trunk/java/ch/idok/qtgui/PreviewWidget.java Thu Mar 13 16:34:01 2008
@@ -19,22 +19,26 @@

package ch.idok.qtgui;

+import java.awt.Rectangle;
import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

-import org.jpedal.PdfDecoder;
-import org.jpedal.exception.PdfException;
-
import ch.idok.common.errorhandling.DmsException;
import ch.idok.common.repository.RepositoryPath;

+import com.sun.pdfview.PDFFile;
+import com.sun.pdfview.PDFPage;
import com.trolltech.qt.core.QByteArray;
import com.trolltech.qt.core.QFile;
import com.trolltech.qt.core.QIODevice;
@@ -51,6 +55,7 @@
import com.trolltech.qt.gui.QMessageBox;
import com.trolltech.qt.gui.QMouseEvent;
import com.trolltech.qt.gui.QPalette;
+import com.trolltech.qt.gui.QPixmap;
import com.trolltech.qt.gui.QScrollArea;
import com.trolltech.qt.gui.QSpacerItem;
import com.trolltech.qt.gui.QSpinBox;
@@ -101,8 +106,8 @@

public Signal1<RepositoryPath> documentSelected = new
Signal1<RepositoryPath>();

- /** the decoder object which decodes the pdf and returns a data object */
- private PdfDecoder decode_pdf_ = null;
+
+ private PDFFile pdfFile_ = null;

private static QCursor BUSYCURSOR = new
QCursor(Qt.CursorShape.BusyCursor);

@@ -152,10 +157,6 @@
setLineWidth(1);
}

- decode_pdf_ = new PdfDecoder(true);
- // true as we are rendering page
- int dpi = 144;
- decode_pdf_.setExtractionMode(0, dpi, dpi / 72);
try {
tempPageFile_ = File.createTempFile("lastViewedPage", "");
} catch (IOException e) {
@@ -227,15 +228,17 @@
} else if (ext.equals("pdf")) {
// fileName_ contains the local copy of the PDF file
try {
- decode_pdf_.openPdfFile(fileName_);
- numPages_ = decode_pdf_.getPageCount();
+ File file = new File(fileName_);
+ RandomAccessFile raf = new RandomAccessFile(file, "r");
+ FileChannel channel = raf.getChannel();
+ ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
0, channel.size());
+ pdfFile_ = new PDFFile(buf);
+ numPages_ = pdfFile_.getNumPages();
+
pdfPageSpinBox_.setRange(1, numPages_);
previewPdfFile(1);
pdfPageSpinBox_.show();
pdfPageSpinBox_.setValue(1);
- } catch (PdfException e) {
- QMessageBox.warning(null, tr("iDok Warning"),
- tr("PDF file could not be decoded:") +
e.getMessage());
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
@@ -291,27 +294,26 @@
private void previewPdfFile(int page) {
setCursor(BUSYCURSOR);
try {
- if ((decode_pdf_.isEncrypted() && (!decode_pdf_
- .isPasswordSupplied()))
- && (!decode_pdf_.isExtractionAllowed())) {
- QMessageBox
- .warning(
- null,
- tr("iDok Warning"),
- tr("PDF file can not be decoded (encrypted
or password protected)"));
- } else {
- // get the current page as a BufferedImage
- BufferedImage image_to_save =
decode_pdf_.getPageAsImage(page);
- if (image_to_save != null) {
- // convert to QT format via external file (not elegant
but
- // works
- // TODO: display directly without intermediate file (AWT
QT
- // conversion)
- ImageIO.write(image_to_save, "png", tempPageFile_);
- fileName_ = tempPageFile_.getAbsolutePath();
- previewImage();
- }
- decode_pdf_.flushObjectValues(true);
+ PDFPage pdfPage = pdfFile_.getPage(page);
+ Rectangle rect = new
Rectangle(0,0,(int)pdfPage.getBBox().getWidth(),(int)pdfPage.getBBox().getHeight());

+ int width = rect.width;
+ int height =rect.height;
+ BufferedImage image = (BufferedImage)pdfPage.getImage(
+ width, height, //width & height
+ rect, // clip rect
+ null, // null for the ImageObserver
+ true, // fill background with white
+ true // block until drawing is done
+ );
+
+ if (image != null) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ImageIO.write(image, "png", out);
+ byte[] buf = out.toByteArray();
+ QPixmap pixMap = new QPixmap(width,height);
+ pixMap.loadFromData(buf);
+ imageView_.setImage(pixMap.toImage());
+ enableImageView();
}
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),



  • [idok-commit] idok commit r43 - trunk/java/ch/idok/qtgui, Apache, 03/13/2008

Archive powered by MHonArc 2.6.19.

Top of Page