Explorar el Código

no message

master
[email protected] hace 4 días
padre
commit
b0bd32416a
Se han modificado 2 ficheros con 45 adiciones y 3 borrados
  1. +35
    -3
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfMergeService.java
  2. +10
    -0
      src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java

+ 35
- 3
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfMergeService.java Ver fichero

@@ -33,6 +33,38 @@ public class PdfMergeService {
// and removes the form dictionary (making the PDF plain).
acroForm.flattenFields();
}

public void removePdfPassword() throws IOException {
// Load PDF A and PDF B
//String filePathA = "C:\\dev\\pdf\\pdfA.pdf";
//File fileA = new File(filePathA);

String filePathB = "C:\\dev\\pdf\\pdfB.pdf";
File fileB = new File(filePathB);

String outputPath = "C:\\dev\\pdf\\pdfOut.pdf";

try (
//PDDocument pdfA = Loader.loadPDF(fileA);
PDDocument pdfB = Loader.loadPDF(fileB);
PDDocument mergedPdf = new PDDocument()) {

for (int i = 0; i < pdfB.getNumberOfPages(); i++) {
PDPage page = pdfB.getPage(i);
mergedPdf.addPage(page);
}

//this is for remove the password and copy the whole pdf
pdfB.setAllSecurityToBeRemoved(true);
pdfB.save(new File(outputPath));
// Save the merged PDF
mergedPdf.save(new File(outputPath));
mergedPdf.close();
}
}

public void mergePdfs() throws IOException {
// This method uses PDFBox and is left unchanged as the focus was iText 7
@@ -63,7 +95,7 @@ public class PdfMergeService {

// Defined constants for clarity
final int IDA_SIG_PAGE = 15; // Page to skip for IDA
final int FNA_SIG_PAGE = 7; // Page to skip for FNA
final int FNA_SIG_PAGE = 10; // Page to skip for FNA
final int HSBC_REP_PAGE = 11; // Page to replace for HSBCFIN
final int HSBCA31_REP_START = 28; // Start page to replace for HSBCA31 (Page 28)
final int HSBCA31_REP_END = 29; // End page to replace for HSBCA31 (Page 29)
@@ -180,7 +212,7 @@ public class PdfMergeService {
}
} else if ("FNA".equals(formCode) && totalPagesA >= FNA_SIG_PAGE) {
// FNA: SKIP page 7
// FNA: SKIP page 10
if (FNA_SIG_PAGE > 1) {
merger.merge(docA, 1, FNA_SIG_PAGE - 1);
}
@@ -231,7 +263,7 @@ public class PdfMergeService {
public byte[] mergePdf2sItext7(String formCode, byte[] pdfABytes, byte[] pdfBBytes) throws IOException {

// UPDATED CONSTANTS FOR NEW REQUIREMENTS
final int MLB03S_REP_PAGE_A = 12;
final int MLB03S_REP_PAGE_A = 13;
final int SLAPP_REP_START_A = 18;
final int SLAPP_REP_END_A = 19;
final int SLAPP_REP_COUNT_B = 2;


+ 10
- 0
src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java Ver fichero

@@ -153,6 +153,16 @@ public class PdfController {
}
}

@GetMapping("/remove-pdf-password")
public String removePdfPassword() {
try {
pdfMergeService.removePdfPassword();
return "PDFs removePdfPassword successfully";
} catch (IOException e) {
return "Error removePdfPassword PDF: " + e.getMessage();
}
}

//this if for upload signiture 1 for PDF form merging later
@PostMapping("/upload1")
public ResponseEntity<Map<String, String>> upload1(@RequestParam("file") MultipartFile file, @RequestParam Long refId, @RequestParam String refType) {


Cargando…
Cancelar
Guardar