|
|
|
@@ -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; |
|
|
|
|