r736 - in trunk: . faxtomail-ui-swing faxtomail-ui-swing/src/license faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util
Author: kmorin Date: 2014-12-24 14:36:54 +0000 (Wed, 24 Dec 2014) New Revision: 736 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/736 Log: qualit?\195?\169 d'impression Modified: trunk/faxtomail-ui-swing/pom.xml trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAction.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java trunk/pom.xml Modified: trunk/faxtomail-ui-swing/pom.xml =================================================================== --- trunk/faxtomail-ui-swing/pom.xml 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/faxtomail-ui-swing/pom.xml 2014-12-24 14:36:54 UTC (rev 736) @@ -226,16 +226,6 @@ </dependency> <dependency> - <groupId>javax.media.jai</groupId> - <artifactId>com.springsource.javax.media.jai.core</artifactId> - </dependency> - - <dependency> - <groupId>javax.media.jai</groupId> - <artifactId>com.springsource.javax.media.jai.codec</artifactId> - </dependency> - - <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> </dependency> @@ -250,23 +240,29 @@ <artifactId>activation</artifactId> </dependency> + <dependency> + <groupId>javax.media.jai</groupId> + <artifactId>com.springsource.javax.media.jai.core</artifactId> + </dependency> + + <dependency> + <groupId>javax.media.jai</groupId> + <artifactId>com.springsource.javax.media.jai.codec</artifactId> + </dependency> + <!-- for pdf edition --> + <!--<dependency>--> + <!--<groupId>org.jpedal</groupId>--> + <!--<artifactId>jpedal-lgpl</artifactId>--> + <!--</dependency>--> + <dependency> - <groupId>org.jpedal</groupId> - <artifactId>jpedal-lgpl</artifactId> + <groupId>org.apache.pdfbox</groupId> + <artifactId>pdfbox</artifactId> </dependency> </dependencies> - <!-- TODO --> - <repositories> - <repository> - <id>com.springsource.repository.bundles.external</id> - <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> - <url>http://repository.springsource.com/maven/bundles/external</url> - </repository> - </repositories> - <build> <resources> <resource> Modified: trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties =================================================================== --- trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-12-24 14:36:54 UTC (rev 736) @@ -6,7 +6,6 @@ # - Apache License 2.0 # - Apache License, version 2.0 # - BSD License -# - Bouncy Castle Licence # - CDDL # - Common Development and Distribution License # - Common Development and Distribution License (CDDL) v1.0 @@ -25,10 +24,8 @@ # - GNU Library or Lesser General Public License # - GPLv2+CE # - General Public License (GPL) -# - JDL (Java Distribution License) # - LGPL # - LGPL 2.1 -# - LGPL Open Source license # - Lesser General Public License (LGPL) # - Lesser General Public License (LGPL) v 3.0 # - MIT License @@ -43,11 +40,10 @@ # Please fill the missing licenses for dependencies : # # -#Mon Dec 15 12:35:36 CET 2014 +#Wed Dec 24 11:31:43 CET 2014 commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 dom4j--dom4j--1.6.1=BSD License gui.ava--html2image--2.0.1=GNU Lesser General Public License, Version 2.1 -javax.media--jai_codec--1.1.3=Apache License -javax.media.jai--com.springsource.javax.media.jai.codec--1.1.3=Apache License -javax.media.jai--com.springsource.javax.media.jai.core--1.1.3=Apache License +javax.media.jai--com.springsource.javax.media.jai.codec--1.1.3=The Apache Software License, Version 2.0 +javax.media.jai--com.springsource.javax.media.jai.core--1.1.3=The Apache Software License, Version 2.0 org.nuiton.thirdparty--sdoc--0.5.0-beta-patchcl=Lesser General Public License (LGPL) v 3.0 Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAction.java 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAction.java 2014-12-24 14:36:54 UTC (rev 736) @@ -81,7 +81,7 @@ Email persistedEmail; String topiaId = model.getTopiaId(); FaxToMailServiceContext serviceContext = context.newServiceContext(); - if (!StringUtils.isBlank(topiaId)) { + if (StringUtils.isNotBlank(topiaId)) { persistedEmail = serviceContext.getEmailService().getFullEmailById(topiaId); } else { persistedEmail = new EmailImpl(); @@ -117,7 +117,8 @@ } FaxToMailUser currentUser = context.getCurrentUser(); - if (model.getDemandStatus() != DemandStatus.ARCHIVED && takeIfNotTaken && model.getTakenBy() == null) { + DemandStatus demandStatus = model.getDemandStatus(); + if (demandStatus != DemandStatus.ARCHIVED && takeIfNotTaken && model.getTakenBy() == null) { model.setTakenBy(getContext().getCurrentUser()); } @@ -132,9 +133,10 @@ model.fromEntity(email); MailFolder folder = model.getMailFolder(); + boolean folderWritable = folder.isFolderWritable(); if (model.getArchiveDate() != null - || !folder.isFolderWritable() - || !model.getDemandStatus().isEditableStatus()) { + || !folderWritable + || !demandStatus.isEditableStatus()) { model.setEditable(false); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-12-24 14:36:54 UTC (rev 736) @@ -35,6 +35,7 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.util.Date; import java.util.List; @@ -42,16 +43,20 @@ import javax.swing.JComponent; import javax.swing.JPanel; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfStamper; +import com.itextpdf.text.pdf.PdfWriter; import jaxx.runtime.swing.ComponentMover; import jaxx.runtime.swing.ComponentResizer; import jaxx.runtime.swing.JAXXButtonGroup; import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jpedal.PdfDecoder; -import org.jpedal.exception.PdfException; -import org.jpedal.fonts.FontMappings; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; import org.nuiton.jaxx.application.swing.util.Cancelable; import org.nuiton.jaxx.application.swing.util.CloseableUI; @@ -78,8 +83,9 @@ protected ComponentMover cm = new ComponentMover(); protected ComponentResizer cr = new ComponentResizer(); - protected PdfDecoder pdfDecoder; +// protected PdfDecoder pdfDecoder; // protected PDFFile pdf; + protected PDDocument pdDocument; @Override public void afterInit(PDFEditorUI pdfEditorUI) { @@ -102,9 +108,6 @@ String value = (String) actionGroup.getSelectedValue(); model.setSelectedComponent(PDFEditorUIModel.EditionComponent.valueOf(value)); - pdfDecoder = new PdfDecoder(); - FontMappings.setFontReplacements(); - ui.getContainer().addContainerListener(new ContainerListener() { @Override public void componentAdded(ContainerEvent e) { @@ -182,17 +185,14 @@ getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); } } + if (FaxToMailUIUtil.isFileAPDF(attachmentFile)) { try { - pdfDecoder.closePdfFile(); - pdfDecoder.openPdfFile(file.getPath()); - pdfDecoder.setExtractionMode(0, 0, 1f); - pdfDecoder.setCenterOnScaling(true); - - model.setPageNumber(pdfDecoder.getPageCount()); + pdDocument = PDDocument.load(file); + model.setPageNumber(pdDocument.getNumberOfPages()); model.setCurrentPageIndex(1); - } catch (PdfException e) { + } catch (IOException e) { if (log.isErrorEnabled()) { log.error("error while converting file to pdf", e); } @@ -254,7 +254,7 @@ @Override public void onCloseUI() { - pdfDecoder.closePdfFile(); + IOUtils.closeQuietly(pdDocument); } public void addEditionComponent(MouseEvent event) { @@ -349,19 +349,20 @@ } protected void displayPage(int pageNb, float previousZoom, int previousRotation) { - if (pageNb < 1 || pageNb > pdfDecoder.getPageCount()) { + if (pageNb < 1 || pageNb > pdDocument.getNumberOfPages()) { return; } + PDFRenderer renderer = new PDFRenderer(pdDocument); + float zoom = getModel().getZoom(); + int rotation = getModel().getRotation(); + try { - float zoom = getModel().getZoom(); - int rotation = getModel().getRotation(); - pdfDecoder.setExtractionMode(0, 0, zoom); - BufferedImage image = pdfDecoder.getPageAsImage(pageNb); + BufferedImage image = renderer.renderImage(pageNb - 1, zoom); - int width = (int) (zoom * image.getWidth()); - int height = (int) (zoom * image.getHeight()); + int width = image.getWidth(); + int height = image.getHeight(); JPanel container = getUI().getContainer(); Dimension containerSize = new Dimension(rotation % 180 == 0 ? width : height, @@ -508,7 +509,7 @@ container.updateUI(); - } catch (PdfException e) { + } catch (IOException e) { if (log.isErrorEnabled()) { log.error("error while displaying pdf", e); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-12-24 14:36:54 UTC (rev 736) @@ -56,7 +56,6 @@ import javax.media.jai.PlanarImage; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; -import javax.print.attribute.standard.MediaPrintableArea; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; @@ -79,10 +78,10 @@ import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.jpedal.PdfDecoder; -import org.jpedal.examples.simpleviewer.paper.PaperSizes; -import org.jpedal.exception.PdfException; -import org.jpedal.fonts.FontMappings; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.printing.PDFPrinter; +import org.apache.pdfbox.rendering.PDFRenderer; import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.nuiton.jaxx.application.swing.util.ApplicationUIUtil; import org.nuiton.util.FileUtil; @@ -506,16 +505,13 @@ * @param defaultPrinter if {@code true}, do not display print dialog and print with default printer * @return true if file has been printed, false otherwise */ + //TODO kmorin print in an action protected static boolean printWithPdfRenderer(String printName, FileInputStream fis, boolean defaultPrinter) { boolean result = false; - final PdfDecoder pdfDecoder = new PdfDecoder(); - FontMappings.setFontReplacements(); + PDDocument pdDocument = null; try { - pdfDecoder.openPdfFileFromInputStream(fis, false); - pdfDecoder.setExtractionMode(0, 0, 1f); - PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setJobName(printName); @@ -523,82 +519,90 @@ PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); result = defaultPrinter || printJob.printDialog(attributes); - PageFormat pageFormat = printJob.getPageFormat(attributes); - final double paperWidth = (int) pageFormat.getImageableWidth(); - final double paperHeight = (int) pageFormat.getImageableHeight(); - final int paperX = (int) pageFormat.getImageableX(); - final int paperY = (int) pageFormat.getImageableY(); + if (result) { + pdDocument = PDDocument.load(fis); + final PDFRenderer renderer = new PDFRenderer(pdDocument); + final int numOfPages = pdDocument.getNumberOfPages(); - if (log.isDebugEnabled()) { - log.debug("page width " + paperWidth); - log.debug("page height " + paperHeight); - log.debug("page x " + paperX); - log.debug("page y " + paperY); - } + printJob.setPrintable(new Printable() { + public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { + try { + if (pageIndex >= numOfPages) { + return NO_SUCH_PAGE; + } - printJob.setPrintable(new Printable() { - public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { - try { - if (pageIndex >= pdfDecoder.getPageCount()) { - return NO_SUCH_PAGE; - } - BufferedImage image = pdfDecoder.getPageAsImage(pageIndex + 1); + double paperWidth = (int) pageFormat.getImageableWidth(); + double paperHeight = (int) pageFormat.getImageableHeight(); + int paperX = (int) pageFormat.getImageableX(); + int paperY = (int) pageFormat.getImageableY(); - int imageWidth = image.getWidth(); - int imageHeight = image.getHeight(); - double widthRatio = paperWidth / imageWidth; - double heightRatio = paperHeight / imageHeight; + if (log.isDebugEnabled()) { + log.debug("page width " + paperWidth); + log.debug("page height " + paperHeight); + log.debug("page x " + paperX); + log.debug("page y " + paperY); + } - if (log.isDebugEnabled()) { - log.debug("width ratio : " + widthRatio); - log.debug("height ratio : " + heightRatio); - } + BufferedImage image = renderer.renderImageWithDPI(pageIndex, 300); - int width; - int height; - // if the image is smaller than the page - if (widthRatio >= 1 && heightRatio >= 1) { - width = imageWidth; - height = imageHeight; + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + double widthRatio = paperWidth / imageWidth; + double heightRatio = paperHeight / imageHeight; - } else { - double minRatio = Math.min(widthRatio, heightRatio); - width = (int) (minRatio * imageWidth); - height = (int) (minRatio * imageHeight); - } + if (log.isDebugEnabled()) { + log.debug("width ratio : " + widthRatio); + log.debug("height ratio : " + heightRatio); + } - if (log.isDebugEnabled()) { - log.debug("image width : " + width); - log.debug("image height : " + height); - } - graphics.drawImage(image, paperX, paperY, width, height, null); + int width; + int height; + // if the image is smaller than the page + if (widthRatio >= 1 && heightRatio >= 1) { + width = imageWidth; + height = imageHeight; - return PAGE_EXISTS; + } else { + double minRatio = Math.min(widthRatio, heightRatio); + width = (int) (minRatio * imageWidth); + height = (int) (minRatio * imageHeight); + } - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("error while printing", e); + if (log.isDebugEnabled()) { + log.debug("image width : " + width); + log.debug("image height : " + height); + } + graphics.drawImage(image, paperX, paperY, width, height, null); + + return PAGE_EXISTS; + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("error while printing", e); + } + return NO_SUCH_PAGE; } - return NO_SUCH_PAGE; } - } - }); + }); - if (result) { printJob.print(attributes); } - } catch (PrinterException | PdfException ex) { + } catch (PrinterException ex) { if (log.isErrorEnabled()) { log.error("can't print", ex); } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("", e); + } } finally { if (log.isDebugEnabled()) { log.debug("finally close the pdf file"); } - pdfDecoder.closePdfFile(); + IOUtils.closeQuietly(pdDocument); } return result; Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-12-23 16:24:48 UTC (rev 735) +++ trunk/pom.xml 2014-12-24 14:36:54 UTC (rev 736) @@ -150,6 +150,26 @@ <checksumPolicy>fail</checksumPolicy> </releases> </repository> + + <repository> + <id>repository.apache.org</id> + <url>http://repository.apache.org/content/groups/snapshots</url> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>false</enabled> + <checksumPolicy>fail</checksumPolicy> + </releases> + </repository> + + <repository> + <id>com.springsource.repository.bundles.external</id> + <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> + <url>http://repository.springsource.com/maven/bundles/external</url> + </repository> + </repositories> <pluginRepositories> @@ -654,6 +674,12 @@ <version>4.74b27</version> </dependency> + <dependency> + <groupId>org.apache.pdfbox</groupId> + <artifactId>pdfbox</artifactId> + <version>2.0.0-SNAPSHOT</version> + </dependency> + </dependencies> </dependencyManagement>
participants (1)
-
kmorin@users.forge.codelutin.com