[email protected] 4 settimane fa
parent
commit
41619481d3
3 ha cambiato i file con 289 aggiunte e 311 eliminazioni
  1. +3
    -0
      build.gradle
  2. +241
    -215
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfMergeService.java
  3. +45
    -96
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java

+ 3
- 0
build.gradle Vedi File

@@ -57,6 +57,9 @@ dependencies {

implementation 'com.itextpdf:itext7-core:7.2.5' // Changed from 7.x.x to a specific version
implementation 'com.itextpdf:layout:7.2.5' // Match the core version
implementation 'com.itextpdf:forms:7.2.5'
implementation 'com.itextpdf:kernel:7.2.5'
implementation 'com.itextpdf:io:7.2.5'

runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.unboundid:unboundid-ldapsdk:6.0.9'


+ 241
- 215
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfMergeService.java Vedi File

@@ -10,6 +10,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.springframework.stereotype.Service;

import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
@@ -18,8 +19,23 @@ import com.itextpdf.kernel.utils.PdfMerger;
@Service
public class PdfMergeService {

// --- ACROFORM REMOVAL HELPER METHOD ---
/**
* Flattens form fields, preserving their appearance (text/checkmarks)
* but making the PDF plain and non-interactive.
*/
private void flattenPdf(PdfDocument doc) {
// Get the AcroForm instance for the document. 'true' creates it if none exists.
PdfAcroForm acroForm = PdfAcroForm.getAcroForm(doc, true);

// This method automatically converts all field values into static content
// and removes the form dictionary (making the PDF plain).
acroForm.flattenFields();
}
public void mergePdfs() throws IOException {
// Load PDF A and PDF B
// This method uses PDFBox and is left unchanged as the focus was iText 7
String filePathA = "C:\\dev\\pdf\\pdfA.pdf";
File fileA = new File(filePathA);

@@ -39,11 +55,6 @@ public class PdfMergeService {
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));
}
}
@@ -65,146 +76,146 @@ public class PdfMergeService {
final int SLAPP_REP_PAGE = 16;
final int SLGII_REP_PAGE = 13;

// Use java.io.ByteArrayOutputStream
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
PdfWriter writer = new PdfWriter(baos);
PdfDocument mergedPdf = new PdfDocument(writer);
// --- STEP 1: Flatten PDF A and get the modified bytes ---
byte[] pdfAFlattenedBytes;
try (PdfReader readerA = new PdfReader(new ByteArrayInputStream(pdfABytes));
ByteArrayOutputStream tempBaosA = new ByteArrayOutputStream();
PdfWriter tempWriterA = new PdfWriter(tempBaosA);
PdfDocument docA_mod = new PdfDocument(readerA, tempWriterA)) {
PdfMerger merger = new PdfMerger(mergedPdf);
flattenPdf(docA_mod);
docA_mod.close(); // IMPORTANT: Close to finalize writing to tempBaosA
pdfAFlattenedBytes = tempBaosA.toByteArray();
}

// 1. Process PDF A (The primary document)
try (PdfReader readerA = new PdfReader(new ByteArrayInputStream(pdfABytes));
PdfDocument docA = new PdfDocument(readerA)) {
int totalPagesA = docA.getNumberOfPages();
// --- STEP 2: Flatten PDF B and get the modified bytes (if needed) ---
byte[] pdfBFlattenedBytes = null;
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
ByteArrayOutputStream tempBaosB = new ByteArrayOutputStream();
PdfWriter tempWriterB = new PdfWriter(tempBaosB);
PdfDocument docB_mod = new PdfDocument(readerB, tempWriterB)) {
// --- Single Page Replacement Forms (New Logic) ---
int repPage = -1; // Page number to be replaced in docA

if ("MLB03S".equals(formCode)) {
repPage = MLB03S_REP_PAGE;
} else if ("MLFNA_EN".equals(formCode) || "MLFNA_CHI".equals(formCode)) {
repPage = MLFNA_REP_PAGE;
} else if ("SLFNA_EN".equals(formCode) || "SLFNA_CHI".equals(formCode)) {
repPage = SLFNA_REP_PAGE;
} else if ("SLAPP".equals(formCode)) {
repPage = SLAPP_REP_PAGE;
} else if ("SLGII".equals(formCode)) {
repPage = SLGII_REP_PAGE;
}
if (repPage != -1 && totalPagesA >= repPage) {
// This block handles all single-page replacements (repPage in docA replaced by docB page 1)
// A. Copy pages 1 up to (repPage - 1)
if (repPage > 1) {
merger.merge(docA, 1, repPage - 1);
}
// B. Insert replacement page (page 1) from PDF B (if available)
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
// Copy ONLY page 1 from docB
merger.merge(docB, 1, 1);
}
}
// C. Copy pages (repPage + 1) through the end
if (totalPagesA > repPage) {
merger.merge(docA, repPage + 1, totalPagesA);
}

// --- Existing Logic (Skip/Multi-page Replace) ---
} else if ("IDA".equals(formCode) && totalPagesA >= IDA_SIG_PAGE) {
// --- IDA: SKIP page 11, then merge rest of A ---
// Copy pages 1 through 10 (IDA_SIG_PAGE - 1)
if (IDA_SIG_PAGE > 1) {
merger.merge(docA, 1, IDA_SIG_PAGE - 1);
}
// Copy pages 12 through the end (IDA_SIG_PAGE + 1)
if (totalPagesA > IDA_SIG_PAGE) {
merger.merge(docA, IDA_SIG_PAGE + 1, totalPagesA);
}
} else if ("FNA".equals(formCode) && totalPagesA >= FNA_SIG_PAGE) {
// --- FNA: SKIP page 7, then merge rest of A ---
// Copy pages 1 through 6 (FNA_SIG_PAGE - 1)
if (FNA_SIG_PAGE > 1) {
merger.merge(docA, 1, FNA_SIG_PAGE - 1);
}
// Copy pages 8 through the end (FNA_SIG_PAGE + 1)
if (totalPagesA > FNA_SIG_PAGE) {
merger.merge(docA, FNA_SIG_PAGE + 1, totalPagesA);
}
} else if ("HSBCFIN".equals(formCode) && totalPagesA >= HSBC_REP_PAGE) {
// --- HSBCFIN: REPLACE page 11 with PDF B page 1 (Similar to new logic, but kept separate for history) ---
// A. Copy pages 1 up to 10 (HSBC_REP_PAGE - 1)
if (HSBC_REP_PAGE > 1) {
merger.merge(docA, 1, HSBC_REP_PAGE - 1);
}
// B. Insert replacement page from PDF B (if available)
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
// Copy ONLY page 1 from docB
merger.merge(docB, 1, 1);
}
}
// C. Copy pages 12 through the end (HSBC_REP_PAGE + 1)
if (totalPagesA > HSBC_REP_PAGE) {
merger.merge(docA, HSBC_REP_PAGE + 1, totalPagesA);
}
flattenPdf(docB_mod);
docB_mod.close(); // IMPORTANT: Close to finalize writing to tempBaosB
pdfBFlattenedBytes = tempBaosB.toByteArray();
}
}

} else if ("HSBCA31".equals(formCode) && totalPagesA >= HSBCA31_REP_END) {
// --- HSBCA31: REPLACE pages 28-29 with PDF B pages 1-2 ---
// --- STEP 3: Perform the merge using the flattened bytes ---
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(baos);
PdfDocument mergedPdf = new PdfDocument(writer);
PdfReader readerA_merge = new PdfReader(new ByteArrayInputStream(pdfAFlattenedBytes));
PdfDocument docA = new PdfDocument(readerA_merge)) {

// A. Copy pages 1 up to 27 (HSBCA31_REP_START - 1)
if (HSBCA31_REP_START > 1) {
merger.merge(docA, 1, HSBCA31_REP_START - 1);
}
// ⭐️ FIX: PdfMerger is NOT AutoCloseable, so we instantiate it here.
PdfMerger merger = new PdfMerger(mergedPdf);
int totalPagesA = docA.getNumberOfPages();
// --- Multi/Single Page Replacement Logic ---
int repPage = -1;
int repStartA = -1;
int repEndA = -1;
int repCountB = -1;
boolean isMultiPageReplace = false;

// Single Page Replacements
if ("MLB03S".equals(formCode)) {
repPage = MLB03S_REP_PAGE;
} else if ("MLFNA_EN".equals(formCode) || "MLFNA_CHI".equals(formCode)) {
repPage = MLFNA_REP_PAGE;
} else if ("SLFNA_EN".equals(formCode) || "SLFNA_CHI".equals(formCode)) {
repPage = SLFNA_REP_PAGE;
} else if ("SLAPP".equals(formCode)) {
repPage = SLAPP_REP_PAGE;
} else if ("SLGII".equals(formCode)) {
repPage = SLGII_REP_PAGE;
}
// Multi-Page Replacement HSBCA31
else if ("HSBCA31".equals(formCode) && totalPagesA >= HSBCA31_REP_END) {
isMultiPageReplace = true;
repStartA = HSBCA31_REP_START;
repEndA = HSBCA31_REP_END;
repCountB = HSBCA31_REP_COUNT;
}

// B. Insert replacement pages (1 and 2) from PDF B (if available)
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
// Copy ONLY pages 1 and 2 from docB
if (docB.getNumberOfPages() >= HSBCA31_REP_COUNT) {
merger.merge(docB, 1, HSBCA31_REP_COUNT);
} else {
// Optionally log or throw error if pdfB is too short
}
if ((repPage != -1 && totalPagesA >= repPage) || isMultiPageReplace) {
// Determine start/end pages for copy segments
int firstSegmentEnd = isMultiPageReplace ? repStartA - 1 : repPage - 1;
int secondSegmentStart = isMultiPageReplace ? repEndA + 1 : repPage + 1;
int pagesToInsertB = isMultiPageReplace ? repCountB : 1;

// A. Copy pages 1 up to the start of replacement
if (firstSegmentEnd >= 1) {
merger.merge(docA, 1, firstSegmentEnd);
}
// B. Insert replacement pages from PDF B (if available)
if (pdfBFlattenedBytes != null) {
try (PdfReader readerB_merge = new PdfReader(new ByteArrayInputStream(pdfBFlattenedBytes));
PdfDocument docB = new PdfDocument(readerB_merge)) {
if (docB.getNumberOfPages() >= pagesToInsertB) {
merger.merge(docB, 1, pagesToInsertB);
}
}
}
// C. Copy pages after replacement through the end
if (totalPagesA >= secondSegmentStart) {
merger.merge(docA, secondSegmentStart, totalPagesA);
}

// C. Copy pages 30 through the end (HSBCA31_REP_END + 1)
if (totalPagesA > HSBCA31_REP_END) {
merger.merge(docA, HSBCA31_REP_END + 1, totalPagesA);
// --- Existing Logic (Skip Pages) ---
} else if ("IDA".equals(formCode) && totalPagesA >= IDA_SIG_PAGE) {
// IDA: SKIP page 15
if (IDA_SIG_PAGE > 1) {
merger.merge(docA, 1, IDA_SIG_PAGE - 1);
}
if (totalPagesA > IDA_SIG_PAGE) {
merger.merge(docA, IDA_SIG_PAGE + 1, totalPagesA);
}
} else if ("FNA".equals(formCode) && totalPagesA >= FNA_SIG_PAGE) {
// FNA: SKIP page 7
if (FNA_SIG_PAGE > 1) {
merger.merge(docA, 1, FNA_SIG_PAGE - 1);
}
if (totalPagesA > FNA_SIG_PAGE) {
merger.merge(docA, FNA_SIG_PAGE + 1, totalPagesA);
}
} else if ("HSBCFIN".equals(formCode) && totalPagesA >= HSBC_REP_PAGE) {
// HSBCFIN: REPLACE page 11 with PDF B page 1
if (HSBC_REP_PAGE > 1) {
merger.merge(docA, 1, HSBC_REP_PAGE - 1);
}
if (pdfBFlattenedBytes != null) {
try (PdfReader readerB_merge = new PdfReader(new ByteArrayInputStream(pdfBFlattenedBytes));
PdfDocument docB = new PdfDocument(readerB_merge)) {
merger.merge(docB, 1, 1);
}

} else {
// Default: Copy all pages from docA
merger.merge(docA, 1, totalPagesA);
}
}
if (totalPagesA > HSBC_REP_PAGE) {
merger.merge(docA, HSBC_REP_PAGE + 1, totalPagesA);
}

} else {
// Default: Copy all pages from docA
merger.merge(docA, 1, totalPagesA);
}
// 2. Process PDF B (Only appended if IDA or FNA)
// Note: Single-page replacement forms (MLB03S, MLFNA, etc.) are NOT appending pdfB,
// as pdfB page 1 was used for replacement and the requirement did not specify appending.
if (pdfBBytes != null && pdfBBytes.length > 0) {
// 4. Process PDF B (Only appended if IDA or FNA)
if (pdfBFlattenedBytes != null) {
if ("IDA".equals(formCode) || "FNA".equals(formCode)){
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
try (PdfReader readerB_merge = new PdfReader(new ByteArrayInputStream(pdfBFlattenedBytes));
PdfDocument docB = new PdfDocument(readerB_merge)) {
// Copy ONLY page 1 from docB to append as the last page
merger.merge(docB, 1, 1);
@@ -212,13 +223,9 @@ public class PdfMergeService {
}
}

// 3. Close the merged PDF document
mergedPdf.close();
// 4. Return the resulting byte array
return baos.toByteArray();

} // baos is closed here
}
}

public byte[] mergePdf2sItext7(String formCode, byte[] pdfABytes, byte[] pdfBBytes) throws IOException {
@@ -232,99 +239,118 @@ public class PdfMergeService {
final int SLGII_REP_END_A = 16;
final int SLGII_REP_COUNT_B = 2;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
// --- STEP 1: Flatten PDF A and get the modified bytes ---
byte[] pdfAFlattenedBytes;
try (PdfReader readerA = new PdfReader(new ByteArrayInputStream(pdfABytes));
ByteArrayOutputStream tempBaosA = new ByteArrayOutputStream();
PdfWriter tempWriterA = new PdfWriter(tempBaosA);
PdfDocument docA_mod = new PdfDocument(readerA, tempWriterA)) {
PdfWriter writer = new PdfWriter(baos);
PdfDocument mergedPdf = new PdfDocument(writer);
flattenPdf(docA_mod);
docA_mod.close(); // IMPORTANT: Close to finalize writing to tempBaosA
pdfAFlattenedBytes = tempBaosA.toByteArray();
}

// --- STEP 2: Flatten PDF B and get the modified bytes (if needed) ---
byte[] pdfBFlattenedBytes = null;
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
ByteArrayOutputStream tempBaosB = new ByteArrayOutputStream();
PdfWriter tempWriterB = new PdfWriter(tempBaosB);
PdfDocument docB_mod = new PdfDocument(readerB, tempWriterB)) {
flattenPdf(docB_mod);
docB_mod.close(); // IMPORTANT: Close to finalize writing to tempBaosB
pdfBFlattenedBytes = tempBaosB.toByteArray();
}
}
// --- STEP 3: Perform the merge using the flattened bytes ---
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = new PdfWriter(baos);
PdfDocument mergedPdf = new PdfDocument(writer);
PdfReader readerA_merge = new PdfReader(new ByteArrayInputStream(pdfAFlattenedBytes));
PdfDocument docA = new PdfDocument(readerA_merge)) {

// ⭐️ FIX: PdfMerger is NOT AutoCloseable, so we instantiate it here.
PdfMerger merger = new PdfMerger(mergedPdf);

// 1. Process PDF A (The primary document)
try (PdfReader readerA = new PdfReader(new ByteArrayInputStream(pdfABytes));
PdfDocument docA = new PdfDocument(readerA)) {
int totalPagesA = docA.getNumberOfPages();
int totalPagesA = docA.getNumberOfPages();
// --- Multi-page Replacement Forms (SLAPP, SLGII) ---
int repStartA = -1;
int repEndA = -1;
int repCountB = -1;

if ("SLAPP".equals(formCode)) {
repStartA = SLAPP_REP_START_A;
repEndA = SLAPP_REP_END_A;
repCountB = SLAPP_REP_COUNT_B;
} else if ("SLGII".equals(formCode)) {
repStartA = SLGII_REP_START_A;
repEndA = SLGII_REP_END_A;
repCountB = SLGII_REP_COUNT_B;
}

if (repStartA != -1 && totalPagesA >= repEndA) {
// --- Multi-page Replacement Forms (New/Existing Logic) ---
int repStartA = -1; // Start page in docA to replace
int repEndA = -1; // End page in docA to replace
int repCountB = -1; // Number of pages from docB to insert

if ("SLAPP".equals(formCode)) {
repStartA = SLAPP_REP_START_A;
repEndA = SLAPP_REP_END_A;
repCountB = SLAPP_REP_COUNT_B;
} else if ("SLGII".equals(formCode)) {
repStartA = SLGII_REP_START_A;
repEndA = SLGII_REP_END_A;
repCountB = SLGII_REP_COUNT_B;
// A. Copy pages 1 up to (repStartA - 1)
if (repStartA > 1) {
merger.merge(docA, 1, repStartA - 1);
}

if (repStartA != -1 && totalPagesA >= repEndA) {
// This block handles all multi-page replacements
// A. Copy pages 1 up to (repStartA - 1)
if (repStartA > 1) {
merger.merge(docA, 1, repStartA - 1);
}

// B. Insert replacement pages from PDF B (if available)
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
// Copy the required number of pages from docB starting from page 1
if (docB.getNumberOfPages() >= repCountB) {
merger.merge(docB, 1, repCountB);
} else {
// Log or handle case where pdfB is too short
System.err.println("PDF B too short for " + formCode + " replacement.");
}
// B. Insert replacement pages from PDF B (if available)
if (pdfBFlattenedBytes != null) {
try (PdfReader readerB_merge = new PdfReader(new ByteArrayInputStream(pdfBFlattenedBytes));
PdfDocument docB = new PdfDocument(readerB_merge)) {
// Copy the required number of pages from docB starting from page 1
if (docB.getNumberOfPages() >= repCountB) {
merger.merge(docB, 1, repCountB);
} else {
System.err.println("PDF B too short for " + formCode + " replacement.");
}
}
}

// C. Copy pages (repEndA + 1) through the end
if (totalPagesA > repEndA) {
merger.merge(docA, repEndA + 1, totalPagesA);
}
// C. Copy pages (repEndA + 1) through the end
if (totalPagesA > repEndA) {
merger.merge(docA, repEndA + 1, totalPagesA);
}
// --- Single Page Replacement Forms (MLB03S) ---
} else if ("MLB03S".equals(formCode) && totalPagesA >= MLB03S_REP_PAGE_A) {
// --- Single Page Replacement Forms (New/Existing Logic) ---
} else if ("MLB03S".equals(formCode) && totalPagesA >= MLB03S_REP_PAGE_A) {
// MLB03S: REPLACE page 12 with PDF B page 1 (New Requirement)
// A. Copy pages 1 up to 11 (MLB03S_REP_PAGE_A - 1)
if (MLB03S_REP_PAGE_A > 1) {
merger.merge(docA, 1, MLB03S_REP_PAGE_A - 1);
}
// B. Insert replacement page from PDF B (if available)
if (pdfBBytes != null && pdfBBytes.length > 0) {
try (PdfReader readerB = new PdfReader(new ByteArrayInputStream(pdfBBytes));
PdfDocument docB = new PdfDocument(readerB)) {
// Copy ONLY page 1 from docB
if (docB.getNumberOfPages() >= 1) {
merger.merge(docB, 1, 1);
}
// A. Copy pages 1 up to 11 (MLB03S_REP_PAGE_A - 1)
if (MLB03S_REP_PAGE_A > 1) {
merger.merge(docA, 1, MLB03S_REP_PAGE_A - 1);
}
// B. Insert replacement page from PDF B (if available)
if (pdfBFlattenedBytes != null) {
try (PdfReader readerB_merge = new PdfReader(new ByteArrayInputStream(pdfBFlattenedBytes));
PdfDocument docB = new PdfDocument(readerB_merge)) {
// Copy ONLY page 1 from docB
if (docB.getNumberOfPages() >= 1) {
merger.merge(docB, 1, 1);
}
}
// C. Copy pages 13 through the end (MLB03S_REP_PAGE_A + 1)
if (totalPagesA > MLB03S_REP_PAGE_A) {
merger.merge(docA, MLB03S_REP_PAGE_A + 1, totalPagesA);
}

} else {
// Default: Copy all pages from docA
merger.merge(docA, 1, totalPagesA);
}
}
// C. Copy pages 13 through the end (MLB03S_REP_PAGE_A + 1)
if (totalPagesA > MLB03S_REP_PAGE_A) {
merger.merge(docA, MLB03S_REP_PAGE_A + 1, totalPagesA);
}

} else {
// Default: Copy all pages from docA
merger.merge(docA, 1, totalPagesA);
}
// 3. Close the merged PDF document
mergedPdf.close();
// 4. Return the resulting byte array
return baos.toByteArray();

} // baos is closed here
}
}
}

+ 45
- 96
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java Vedi File

@@ -6,10 +6,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -53,8 +49,6 @@ import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;

import liquibase.util.StringUtil;

@Service
public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfRepository> {

@@ -847,30 +841,18 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "fna_d_b1_6", commonField.getOthers().get("recObj6"));

setValueIfPresent(form, "fna_d_name_1", commonField.getOthers().get("recProd1_1"));
setValueIfPresent(form, "fna_d_name_1_2", commonField.getOthers().get("recProd1_2"));
setValueIfPresent(form, "fna_d_name_2", commonField.getOthers().get("recProd2_1"));
setValueIfPresent(form, "fna_d_name_2_2", commonField.getOthers().get("recProd2_2"));
setValueIfPresent(form, "fna_d_name_3", commonField.getOthers().get("recProd3_1"));
setValueIfPresent(form, "fna_d_name_3_2", commonField.getOthers().get("recProd3_2"));
setValueIfPresent(form, "fna_d_name_4", commonField.getOthers().get("recProd4_1"));
setValueIfPresent(form, "fna_d_name_4_2", commonField.getOthers().get("recProd4_2"));
setValueIfPresent(form, "fna_d_name_5", commonField.getOthers().get("recProd5_1"));
setValueIfPresent(form, "fna_d_name_5_2", commonField.getOthers().get("recProd5_2"));
setValueIfPresent(form, "fna_d_name_6", commonField.getOthers().get("recProd6_1"));
setValueIfPresent(form, "fna_d_name_6_2", commonField.getOthers().get("recProd6_2"));

setValueIfPresent(form, "fna_d_product_1", commonField.getOthers().get("recSelect1_1"));
setValueIfPresent(form, "fna_d_product_1_2", commonField.getOthers().get("recSelect1_2"));
setValueIfPresent(form, "fna_d_product_2", commonField.getOthers().get("recSelect2_1"));
setValueIfPresent(form, "fna_d_product_2_2", commonField.getOthers().get("recSelect2_2"));
setValueIfPresent(form, "fna_d_product_3", commonField.getOthers().get("recSelect3_1"));
setValueIfPresent(form, "fna_d_product_3_2", commonField.getOthers().get("recSelect3_2"));
setValueIfPresent(form, "fna_d_product_4", commonField.getOthers().get("recSelect4_1"));
setValueIfPresent(form, "fna_d_product_4_2", commonField.getOthers().get("recSelect4_2"));
setValueIfPresent(form, "fna_d_product_5", commonField.getOthers().get("recSelect5_1"));
setValueIfPresent(form, "fna_d_product_5_2", commonField.getOthers().get("recSelect5_2"));
setValueIfPresent(form, "fna_d_product_6", commonField.getOthers().get("recSelect6_1"));
setValueIfPresent(form, "fna_d_product_6_2", commonField.getOthers().get("recSelect6_2"));
/* Page6 End */

@@ -1202,6 +1184,15 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "email", commonField.getEmail());
setValueIfPresent(form, "occupation", commonField.getOccupationTitle());
*/

setValueIfPresent(form, "name", StringUtils.trimToEmpty(StringUtils.trimToEmpty(client.getLastname()) + " " + StringUtils.trimToEmpty(client.getFirstname())));
setValueIfPresent(form, "date_of_birth", commonField.getDateOfBirth());

setValueIfPresent(form, "contact", client.getPhone1Code() + " " + client.getPhone1());
setValueIfPresent(form, "email", client.getEmail());
setValueIfPresent(form, "occupation", commonField.getOthers().get("empPosition"));
setValueIfPresent(form, "address1", getCrAddress1(client));
setValueIfPresent(form, "address2", getCrAddress2(client));
setValueIfPresent(form, "1amount", commonField.getFna_b1_d_amount());
setValueIfPresent(form, "cb1f", commonField.getFna_b1_f_other());
@@ -1230,31 +1221,19 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "5obj6", commonField.getOthers().get("recObj6"));

setValueIfPresent(form, "5name1_1", commonField.getOthers().get("recProd1_1"));
setValueIfPresent(form, "5name1_2", commonField.getOthers().get("recProd1_2"));
setValueIfPresent(form, "5name2_1", commonField.getOthers().get("recProd2_1"));
setValueIfPresent(form, "5name2_2", commonField.getOthers().get("recProd2_2"));
setValueIfPresent(form, "5name3_1", commonField.getOthers().get("recProd3_1"));
setValueIfPresent(form, "5name3_2", commonField.getOthers().get("recProd3_2"));
setValueIfPresent(form, "5name4_1", commonField.getOthers().get("recProd4_1"));
setValueIfPresent(form, "5name4_2", commonField.getOthers().get("recProd4_2"));
setValueIfPresent(form, "5name5_1", commonField.getOthers().get("recProd5_1"));
setValueIfPresent(form, "5name5_2", commonField.getOthers().get("recProd5_2"));
setValueIfPresent(form, "5name6_1", commonField.getOthers().get("recProd6_1"));
setValueIfPresent(form, "5name6_2", commonField.getOthers().get("recProd6_2"));

setValueIfPresent(form, "5slected1_1", commonField.getOthers().get("recSelect1_1"));
setValueIfPresent(form, "5slected1_2", commonField.getOthers().get("recSelect1_2"));
setValueIfPresent(form, "5slected2_1", commonField.getOthers().get("recSelect2_1"));
setValueIfPresent(form, "5slected2_2", commonField.getOthers().get("recSelect2_2"));
setValueIfPresent(form, "5slected3_1", commonField.getOthers().get("recSelect3_1"));
setValueIfPresent(form, "5slected3_2", commonField.getOthers().get("recSelect3_2"));
setValueIfPresent(form, "5slected4_1", commonField.getOthers().get("recSelect4_1"));
setValueIfPresent(form, "5slected4_2", commonField.getOthers().get("recSelect4_2"));
setValueIfPresent(form, "5slected5_1", commonField.getOthers().get("recSelect5_1"));
setValueIfPresent(form, "5slected5_2", commonField.getOthers().get("recSelect5_2"));
setValueIfPresent(form, "5slected6_1", commonField.getOthers().get("recSelect6_1"));
setValueIfPresent(form, "5slected6_2", commonField.getOthers().get("recSelect6_2"));

/* Page4 End */

if(client != null && client.getConsultantId() != null){
@@ -1353,6 +1332,10 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

private void SLAPP_textBox(PdfAcroForm form, CommonField commonField, Client client){
/* Page1 Start */
setValueIfPresent(form, "1_1_surname", client.getLastname());
setValueIfPresent(form, "1_1_given_name", client.getFirstname());

setValueIfPresent(form, "1_2_name_ch", commonField.getNameChi());

setValueIfPresent(form, "1_6_dd", commonField.getDdDateOfBirth());
@@ -1379,8 +1362,8 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

setValueIfPresent(form, "1_8", commonField.getCountryOfCitizenship());
setValueIfPresent(form, "1_12_1", commonField.getOccupation());
setValueIfPresent(form, "1_12_2", commonField.getOccupationTitle());
setValueIfPresent(form, "1_12_1", commonField.getOthers().get("empPosition"));
setValueIfPresent(form, "1_12_2", commonField.getOthers().get("empDuties"));
setValueIfPresent(form, "1_12_5", commonField.getTotalAnnualIncome());
if(commonField.getTotalAnnualIncome() != null && !commonField.getTotalAnnualIncome().isBlank()){
@@ -1493,13 +1476,17 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form2, "1_11_m", commonField.getOthers().get("maritalStatusMarried"));
setValueIfPresent(form2, "1_11_o", commonField.getOthers().get("maritalStatusOther"));

setValueIfPresent(form2, "1_10_1", commonField.getOthers().get("hkidPerm"));
setValueIfPresent(form2, "1_10_2", commonField.getOthers().get("hkidNon"));
setValueIfPresent(form2, "1_10_3", commonField.getOthers().get("prcId"));
if("yes".equals(commonField.getOthers().get("passportYes")) || "yes".equals(commonField.getOthers().get("travelDocYes"))){
setValueIfPresent(form2, "1_10_6", "Yes");
if("Yes".contentEquals(commonField.getOthers().get("hkidPerm")) || "Yes".contentEquals(commonField.getOthers().get("hkidNon"))){
setValueIfPresent(form2, "1_10_1", commonField.getOthers().get("hkidPerm"));
setValueIfPresent(form2, "1_10_2", commonField.getOthers().get("hkidNon"));
}else if("Yes".equals(commonField.getOthers().get("prcId"))){
setValueIfPresent(form2, "1_10_3", commonField.getOthers().get("prcId"));
}else if("Yes".equals(commonField.getOthers().get("passportYes")) || "Yes".equals(commonField.getOthers().get("travelDocYes")) ){
if("yes".equals(commonField.getOthers().get("passportYes")) || "yes".equals(commonField.getOthers().get("travelDocYes"))){
setValueIfPresent(form2, "1_10_6", "Yes");
}
}

//page 2
setValueIfPresent(form2, "ch1_12_yes", commonField.getOthers().get("workHighYes"));
setValueIfPresent(form2, "ch1_12_no", commonField.getOthers().get("workHighNo"));
@@ -2076,7 +2063,9 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "ch1_12_student", commonField.getStudent());
setValueIfPresent(form, "ch1_12_housewife", commonField.getPartTime());
setValueIfPresent(form, "ch1_12_part", commonField.getHomemaker());
setValueIfPresent(form, "ch1_12_retired", commonField.getBankruptNo());
setValueIfPresent(form, "ch1_12_retired", commonField.getRetired());
setValueIfPresent(form, "1_12_detail1", commonField.getOthers().get("workHighDesc"));

setValueIfPresent(form, "1_12_occupation", commonField.getOthers().get("empPosition"));
setValueIfPresent(form, "1_12_exact_duty", commonField.getOthers().get("empDuties"));
@@ -2084,12 +2073,14 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "1_12_employer_address_1", commonField.getOthers().get("empCompanyAddress"));
//setValueIfPresent(form, "1_12_employer_address_2", commonField.getOthers().get("companyAddress2"));

setValueIfPresent(form, "1_12_nature_1", commonField.getCompanyNature1());
setValueIfPresent(form, "1_12_nature_2", commonField.getCompanyNature2());
setValueIfPresent(form, "1_12_nature_1", commonField.getOthers().get("empNatureA"));
setValueIfPresent(form, "1_12_nature_2", commonField.getOthers().get("empNatureB"));

setValueIfPresent(form, "1_13a_rm", client.getCrAddressRoom());
setValueIfPresent(form, "1_13a_floor", client.getCrAddressFloor());
setValueIfPresent(form, "1_13a_block", client.getCrAddressBlock());
setValueIfPresent(form, "1_13a_building", client.getCrAddressBuilding());
setValueIfPresent(form, "1_13a_street", client.getCrAddressStreet());
setValueIfPresent(form, "1_13a_district", client.getCrAddressArea());
setValueIfPresent(form, "1_13a_zip", client.getCrAddressPostalCode());
if("HK".equals(client.getCrAddressArea()))
@@ -2102,7 +2093,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "1_13bc_rm", client.getCorAddressRoom());
setValueIfPresent(form, "1_13bc_floor", client.getCorAddressFloor());
setValueIfPresent(form, "1_13bc_block", client.getCorAddressBlock());
setValueIfPresent(form, "1_13bc_building", client.getCrAddressBuilding());
setValueIfPresent(form, "1_13bc_building", client.getCorAddressBuilding());
setValueIfPresent(form, "1_13bc_street", client.getCorAddressStreet());
setValueIfPresent(form, "1_13bc_district", client.getCorAddressArea());
@@ -2171,29 +2162,19 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "1_14d_explain3", commonField.getTaxReasonB3());
/* Page3 End */
/* Page6 Start */
/* Page6 Start */

setValueIfPresent(form, "4_1_name1_1", commonField.getInsuranceCompany1_1());
setValueIfPresent(form, "4_1_name1_2", commonField.getInsuranceCompany1_2());
//setValueIfPresent(form, "4_1_name1_3", commonField.getInsuranceCompany1_3());
setValueIfPresent(form, "4_1_name2_1", commonField.getInsuranceCompany2_1());
setValueIfPresent(form, "4_1_name2_2", commonField.getInsuranceCompany2_2());
//setValueIfPresent(form, "4_1_name2_3", commonField.getInsuranceCompany2_3());
setValueIfPresent(form, "4_1_name3_1", commonField.getInsuranceCompany3_1());
setValueIfPresent(form, "4_1_name3_2", commonField.getInsuranceCompany3_2());
//setValueIfPresent(form, "4_1_name3_3", commonField.getInsuranceCompany3_3());

setValueIfPresent(form, "4_1_year1", commonField.getInsuranceYear1());
setValueIfPresent(form, "4_1_year2", commonField.getInsuranceYear2());
setValueIfPresent(form, "4_1_year3", commonField.getInsuranceYear3());

setValueIfPresent(form, "4_1_sum1_1", commonField.getOthers().get("insuranceSumInsured1_1"));
setValueIfPresent(form, "4_1_sum1_2", commonField.getOthers().get("insuranceSumInsured1_2"));
setValueIfPresent(form, "4_1_sum1_3", commonField.getOthers().get("insuranceSumInsured1_3"));
setValueIfPresent(form, "4_1_sum2_1", commonField.getOthers().get("insuranceSumInsured2_1"));
setValueIfPresent(form, "4_1_sum2_2", commonField.getOthers().get("insuranceSumInsured2_2"));
setValueIfPresent(form, "4_1_sum2_3", commonField.getOthers().get("insuranceSumInsured2_3"));
setValueIfPresent(form, "4_1_sum3_1", commonField.getOthers().get("insuranceSumInsured3_1"));
setValueIfPresent(form, "4_1_sum3_2", commonField.getOthers().get("insuranceSumInsured3_2"));
setValueIfPresent(form, "4_1_sum3_3", commonField.getOthers().get("insuranceSumInsured3_3"));
//if(commonField.getInsuranceSumInsured1() != null && !commonField.getInsuranceSumInsured1().isBlank()){
setValueIfPresent(form, "ch4_1_life", "On");
@@ -2384,6 +2365,9 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
/* Page1 End */
/* Page2 Start */
setValueIfPresent(form2, "ch1_12_yes", commonField.getOthers().get("workHighYes"));
setValueIfPresent(form2, "ch1_12_no", commonField.getOthers().get("workHighNo"));

setValueIfPresent(form2, "ch1_11_s", commonField.getOthers().get("maritalStatusSingle"));
setValueIfPresent(form2, "ch1_11_m", commonField.getOthers().get("maritalStatusMarried"));
setValueIfPresent(form2, "ch1_11_o", commonField.getOthers().get("maritalStatusOther"));
@@ -3122,30 +3106,18 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
case "fna_d_b1_6" -> commonField.getOthers().put("recObj6", fieldValue);

case "fna_d_name_1" -> commonField.getOthers().put("recProd1_1", fieldValue);
case "fna_d_name_1_2" -> commonField.getOthers().put("recProd1_2", fieldValue);
case "fna_d_name_2" -> commonField.getOthers().put("recProd2_1", fieldValue);
case "fna_d_name_2_2" -> commonField.getOthers().put("recProd2_2", fieldValue);
case "fna_d_name_3" -> commonField.getOthers().put("recProd3_1", fieldValue);
case "fna_d_name_3_2" -> commonField.getOthers().put("recProd3_2", fieldValue);
case "fna_d_name_4" -> commonField.getOthers().put("recProd4_1", fieldValue);
case "fna_d_name_4_2" -> commonField.getOthers().put("recProd4_2", fieldValue);
case "fna_d_name_5" -> commonField.getOthers().put("recProd5_1", fieldValue);
case "fna_d_name_5_2" -> commonField.getOthers().put("recProd5_2", fieldValue);
case "fna_d_name_6" -> commonField.getOthers().put("recProd6_1", fieldValue);
case "fna_d_name_6_2" -> commonField.getOthers().put("recProd6_2", fieldValue);
case "fna_d_product_1" -> commonField.getOthers().put("recSelect1_1", fieldValue);
case "fna_d_product_1_2" -> commonField.getOthers().put("recSelect1_2", fieldValue);
case "fna_d_product_2" -> commonField.getOthers().put("recSelect2_1", fieldValue);
case "fna_d_product_2_2" -> commonField.getOthers().put("recSelect2_2", fieldValue);
case "fna_d_product_3" -> commonField.getOthers().put("recSelect3_1", fieldValue);
case "fna_d_product_3_2" -> commonField.getOthers().put("recSelect3_2", fieldValue);
case "fna_d_product_4" -> commonField.getOthers().put("recSelect4_1", fieldValue);
case "fna_d_product_4_2" -> commonField.getOthers().put("recSelect4_2", fieldValue);
case "fna_d_product_5" -> commonField.getOthers().put("recSelect5_1", fieldValue);
case "fna_d_product_5_2" -> commonField.getOthers().put("recSelect5_2", fieldValue);
case "fna_d_product_6" -> commonField.getOthers().put("recSelect6_1", fieldValue);
case "fna_d_product_6_2" -> commonField.getOthers().put("recSelect6_2", fieldValue);
/* Page6 End */
}
}
@@ -3416,6 +3388,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

/* Page2 End */
/* Page3 Start */
/*
case "part3_4_4_1a" -> commonField.setFna_c3a_2_5(fieldValue);
case "part3_4_4_1b" -> commonField.setFna_c3a_6_10(fieldValue);
case "part3_4_4_1c" -> commonField.setFna_c3a_11_15(fieldValue);
@@ -3424,7 +3397,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
case "part3_4_4_1f" -> commonField.setFna_c3a_life(fieldValue);
case "part3_4_single_pay" -> commonField.setFna_c3a_single_pay(fieldValue);
*/
/* Page3 End */

}
@@ -3529,30 +3502,18 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
case "5obj6" -> commonField.getOthers().put("recObj6", fieldValue);

case "5name1_1" -> commonField.getOthers().put("recProd1_1", fieldValue);
case "5name1_2" -> commonField.getOthers().put("recProd1_2", fieldValue);
case "5name2_1" -> commonField.getOthers().put("recProd2_1", fieldValue);
case "5name2_2" -> commonField.getOthers().put("recProd2_2", fieldValue);
case "5name3_1" -> commonField.getOthers().put("recProd3_2", fieldValue);
case "5name3_2" -> commonField.getOthers().put("recProd3_2", fieldValue);
case "5name4_1" -> commonField.getOthers().put("recProd4_1", fieldValue);
case "5name4_2" -> commonField.getOthers().put("recProd4_2", fieldValue);
case "5name5_1" -> commonField.getOthers().put("recProd5_1", fieldValue);
case "5name5_2" -> commonField.getOthers().put("recProd5_2", fieldValue);
case "5name6_1" -> commonField.getOthers().put("recProd6_1", fieldValue);
case "5name6_2" -> commonField.getOthers().put("recProd6_2", fieldValue);
case "5slected1_1" -> commonField.getOthers().put("recSelect1_1", fieldValue);
case "5slected1_2" -> commonField.getOthers().put("recSelect1_2", fieldValue);
case "5slected2_1" -> commonField.getOthers().put("recSelect2_1", fieldValue);
case "5slected2_2" -> commonField.getOthers().put("recSelect2_2", fieldValue);
case "5slected3_1" -> commonField.getOthers().put("recSelect3_1", fieldValue);
case "5slected3_2" -> commonField.getOthers().put("recSelect3_2", fieldValue);
case "5slected4_1" -> commonField.getOthers().put("recSelect4_1", fieldValue);
case "5slected4_2" -> commonField.getOthers().put("recSelect4_2", fieldValue);
case "5slected5_1" -> commonField.getOthers().put("recSelect5_1", fieldValue);
case "5slected5_2" -> commonField.getOthers().put("recSelect5_2", fieldValue);
case "5slected6_1" -> commonField.getOthers().put("recSelect6_1", fieldValue);
case "5slected6_2" -> commonField.getOthers().put("recSelect6_2", fieldValue);
/* Page4 End */

}
@@ -4057,27 +4018,15 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
/* Page3 End */
/* Page6 Start */
case "4_1_name1_1" -> commonField.setInsuranceCompany1_1(fieldValue);
case "4_1_name1_2" -> commonField.setInsuranceCompany1_2(fieldValue);
//case "4_1_name1_3" -> commonField.setInsuranceCompany1_3(fieldValue);
case "4_1_name2_1" -> commonField.setInsuranceCompany2_1(fieldValue);
case "4_1_name2_2" -> commonField.setInsuranceCompany2_2(fieldValue);
//case "4_1_name2_3" -> commonField.setInsuranceCompany2_3(fieldValue);
case "4_1_name3_1" -> commonField.setInsuranceCompany3_1(fieldValue);
case "4_1_name3_2" -> commonField.setInsuranceCompany3_2(fieldValue);
//case "4_1_name3_3" -> commonField.setInsuranceCompany3_3(fieldValue);
case "4_1_year1" -> commonField.setInsuranceYear1(fieldValue);
case "4_1_year2" -> commonField.setInsuranceYear2(fieldValue);
case "4_1_year3" -> commonField.setInsuranceYear3(fieldValue);

case "4_1_sum1_1" -> commonField.getOthers().put("insuranceSumInsured1_1", fieldValue);
case "4_1_sum1_2" -> commonField.getOthers().put("insuranceSumInsured1_2", fieldValue);
case "4_1_sum1_3" -> commonField.getOthers().put("insuranceSumInsured1_3", fieldValue);
case "4_1_sum2_1" -> commonField.getOthers().put("insuranceSumInsured2_1", fieldValue);
case "4_1_sum2_2" -> commonField.getOthers().put("insuranceSumInsured2_2", fieldValue);
case "4_1_sum2_3" -> commonField.getOthers().put("insuranceSumInsured2_3", fieldValue);
case "4_1_sum3_1" -> commonField.getOthers().put("insuranceSumInsured3_1", fieldValue);
case "4_1_sum3_2" -> commonField.getOthers().put("insuranceSumInsured3_2", fieldValue);
case "4_1_sum3_3" -> commonField.getOthers().put("insuranceSumInsured3_3", fieldValue);
case "ch4_1_life" -> {
if(acroForm.getField("4_1_sum1") != null && acroForm.getField("4_1_sum1").getValueAsString() != null ){
if("Off".equals(fieldValue) && !acroForm.getField("4_1_sum1").getValueAsString().isBlank())


Caricamento…
Annulla
Salva