This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git commit a401c487eef23d7bc42220472b72cb1d7fd63050 Author: Kevin Morin <morin@codelutin.com> Date: Wed Apr 27 15:14:35 2016 +0200 sauvegarde des tammons image dans le pdf (fixes #8288) --- .../actions/GenerateAnnotatedAttachmentAction.java | 109 ++++++++++++++------- 1 file changed, 76 insertions(+), 33 deletions(-) diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/actions/GenerateAnnotatedAttachmentAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/actions/GenerateAnnotatedAttachmentAction.java index e723bd7..fbb90fa 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/actions/GenerateAnnotatedAttachmentAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/actions/GenerateAnnotatedAttachmentAction.java @@ -32,6 +32,7 @@ import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorCrossUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorHighlighterUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorLineUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorNoteUI; +import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorStampImageUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorStampTextUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIHandler; @@ -42,6 +43,7 @@ import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.ExceptionConverter; import com.itextpdf.text.Font; +import com.itextpdf.text.Image; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.ColumnText; @@ -52,9 +54,16 @@ import com.itextpdf.text.pdf.PdfStamper; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXUtil; -import javax.swing.*; -import java.awt.*; +import javax.imageio.ImageIO; +import javax.swing.JLabel; +import javax.swing.JTextArea; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Point; +import java.awt.image.BufferedImage; import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -120,7 +129,11 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P } for (PDFEditorStampTextUI panel : page.getTextStamps()) { - addStampToPdf(zoom, rotation, cb, panel); + addTextStampToPdf(zoom, rotation, cb, panel); + } + + for (PDFEditorStampImageUI panel : page.getImageStamps()) { + addImageStampToPdf(zoom, rotation, cb, panel); } } @@ -138,11 +151,7 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P } protected void addHighlightToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorHighlighterUI panel) { - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + Coordinates coordinates = computeCoordinates(panel, rotation, zoom); cb.saveState(); PdfGState gs1 = new PdfGState(); @@ -150,17 +159,17 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P cb.setGState(gs1); cb.setColorFill(BaseColor.YELLOW); - cb.rectangle(x, y, width, height); + cb.rectangle(coordinates.x, coordinates.y, coordinates.width, coordinates.height); cb.fill(); cb.restoreState(); } protected void addLineToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorLineUI panel) { - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + Coordinates coordinates = computeCoordinates(panel, rotation, zoom); + int width = coordinates.width; + int height = coordinates.height; + int x = coordinates.x; + int y = coordinates.y; if (rotation % 180 == 0 ^ !panel.isHorizontal()) { y += height / 2; @@ -181,11 +190,11 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P } protected void addCrossToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorCrossUI panel) { - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + Coordinates coordinates = computeCoordinates(panel, rotation, zoom); + int width = coordinates.width; + int height = coordinates.height; + int x = coordinates.x; + int y = coordinates.y; cb.saveState(); cb.setColorStroke(BaseColor.BLUE); @@ -199,11 +208,11 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P } protected void addNoteToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorNoteUI note) throws DocumentException, IOException { - int[] coordinates = computeCoordinates(note, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + Coordinates coordinates = computeCoordinates(note, rotation, zoom); + int width = coordinates.width; + int height = coordinates.height; + int x = coordinates.x; + int y = coordinates.y; Insets insets = note.getInsets(); @@ -266,12 +275,12 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P cb.restoreState(); } - protected void addStampToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorStampTextUI stamp) throws DocumentException, IOException { - int[] coordinates = computeCoordinates(stamp, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + protected void addTextStampToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorStampTextUI stamp) throws DocumentException, IOException { + Coordinates coordinates = computeCoordinates(stamp, rotation, zoom); + int width = coordinates.width; + int height = coordinates.height; + int x = coordinates.x; + int y = coordinates.y; Insets insets = stamp.getInsets(); @@ -326,7 +335,31 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P cb.restoreState(); } - protected int[] computeCoordinates(Component panel, int rotation, float zoom) { + protected void addImageStampToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorStampImageUI stamp) throws DocumentException, IOException { + Coordinates coordinates = computeCoordinates(stamp, rotation, zoom); + int x = coordinates.x; + int y = coordinates.y; + + cb.saveState(); + + java.awt.Image image = stamp.getImage(); + BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1); + Graphics gc = bufferedImage.createGraphics(); + gc.drawImage(image, 0, 0, null); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "jpeg", bos); + byte[] imageByteArray = bos.toByteArray(); + + Image stampImage = Image.getInstance(imageByteArray); + stampImage.setAbsolutePosition(x, y); + stampImage.setRotationDegrees(rotation); + cb.addImage(stampImage); + + cb.restoreState(); + } + + protected Coordinates computeCoordinates(Component panel, int rotation, float zoom) { Point location = panel.getLocation(); int width = rotation % 180 == 0 ? panel.getWidth() : panel.getHeight(); @@ -355,8 +388,7 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P y = (int) ((getUI().getContainer().getWidth() - location.x) / zoom) - height; } - int[] result = new int[] { width, height, x, y }; - return result; + return new Coordinates(width, height, x, y); } protected void showTextAligned(PdfContentByte canvas, String text, float x, float y, float rotation, BaseFont baseFont, float fontSize) { @@ -408,4 +440,15 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P getHandler().closeFrame(); } + + private class Coordinates { + private int x, y, width, height; + + public Coordinates(int width, int height, int x, int y) { + this.height = height; + this.width = width; + this.x = x; + this.y = y; + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.