diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java index 2f0d01ff1..dc61252d8 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java @@ -678,6 +678,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import javax.imageio.ImageIO; import javax.swing.ImageIcon; @@ -1535,5 +1536,42 @@ private static BufferedImage rotateImage(BufferedImage originalImage, double deg return rotatedImage; } + + public void removePages(int[] pageIndexes) { + + try { + PDDocument inputPDF = PDDocument.load(new ByteArrayInputStream(content)); + + // Remove pages from highest index to lowest to avoid index shifting + Arrays.sort(pageIndexes); + for (int i = pageIndexes.length - 1; i >= 0; i--) { + int pageNumber = pageIndexes[i]; + inputPDF.removePage(pageNumber); + } + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + inputPDF.save(bout); + inputPDF.close(); + this.content = bout.toByteArray(); + if (this.saveCallback != null) { + this.saveCallback.savePreview(documentId, fileName, content); + } + + } catch (Exception ex) { + log.error("Could not remove PDF pages", ex); + JOptionPane.showMessageDialog(this, "Fehler beim Aktualisieren des PDFs: " + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE); + return; + } + + // Clear and re-render the content + this.orgImage.clear(); + this.pnlPages.removeAll(); + this.renderedPages = 0; + this.totalPages = 0; + this.currentPage = 0; + this.renderContent(0, 0, MAX_RENDER_PAGES - 1, this.zoomFactor); + + } + } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.form b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.form index c09580c8e..5842db8e0 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.form +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.form @@ -19,9 +19,12 @@ - - - + + + + + + @@ -41,7 +44,9 @@ - + + + @@ -81,6 +86,17 @@ + + + + + + + + + + + diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.java index b1dd6546a..637f6347b 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfPageImage.java @@ -665,6 +665,7 @@ You should also get your employer (if you work as a programmer) or school, import java.awt.Color; import javax.swing.ImageIcon; +import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import themes.colors.DefaultColorTheme; @@ -726,6 +727,7 @@ private void initComponents() { lblPage = new javax.swing.JLabel(); cmdRotateLeft = new javax.swing.JButton(); cmdRotateRight = new javax.swing.JButton(); + cmdDeletePage = new javax.swing.JButton(); lblPageNumber = new javax.swing.JLabel(); lblPage.setText("jLabel1"); @@ -755,6 +757,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + cmdDeletePage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/outline_backspace_black_48dp.png"))); // NOI18N + cmdDeletePage.setToolTipText("Ausgewählte Seite entfernen"); + cmdDeletePage.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cmdDeletePageActionPerformed(evt); + } + }); + lblPageNumber.setFont(lblPageNumber.getFont().deriveFont(lblPageNumber.getFont().getStyle() | java.awt.Font.BOLD)); lblPageNumber.setForeground(new java.awt.Color(255, 255, 255)); lblPageNumber.setText("1"); @@ -766,9 +776,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(cmdRotateLeft) - .addComponent(cmdRotateRight) - .addComponent(lblPageNumber, javax.swing.GroupLayout.Alignment.TRAILING)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(cmdRotateLeft) + .addComponent(cmdRotateRight) + .addComponent(lblPageNumber, javax.swing.GroupLayout.Alignment.TRAILING)) + .addComponent(cmdDeletePage)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblPage) .addContainerGap(38, Short.MAX_VALUE)) @@ -785,7 +797,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(cmdRotateLeft) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cmdRotateRight) - .addContainerGap(82, Short.MAX_VALUE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cmdDeletePage) + .addContainerGap(50, Short.MAX_VALUE)))) ); }// //GEN-END:initComponents @@ -805,8 +819,16 @@ private void lblPageMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:even this.highlightPage(false); }//GEN-LAST:event_lblPageMouseExited + private void cmdDeletePageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDeletePageActionPerformed + int response = JOptionPane.showConfirmDialog(this, "Soll die Seite wirklich entfernt werden?", "Bestätigung", JOptionPane.YES_NO_OPTION); + if (response == JOptionPane.YES_OPTION) { + this.documentContainer.removePages(new int[]{this.pageIndex}); + } + }//GEN-LAST:event_cmdDeletePageActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cmdDeletePage; private javax.swing.JButton cmdRotateLeft; private javax.swing.JButton cmdRotateRight; private javax.swing.JLabel lblPage;