Corrected code for page number in pdf
This commit is contained in:
@@ -36,6 +36,8 @@ import com.itextpdf.layout.element.Cell;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -66,10 +68,10 @@ public class PdfDao {
|
||||
|
||||
Document document = new Document(PageSize.A4, leftMargin, 36f, 50f, 35);
|
||||
PdfWriter writer = PdfWriter.getInstance(document, out);
|
||||
CustomPageEvent pageEvent = new CustomPageEvent(call.getName(), 0);
|
||||
writer.setPageEvent(pageEvent);
|
||||
// CustomPageEvent pageEvent = new CustomPageEvent(call.getName(), 0);
|
||||
// writer.setPageEvent(pageEvent);
|
||||
document.open();
|
||||
pageEvent.setTotalPages(writer.getPageNumber());
|
||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||
addLogo(document, "https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/logo.jpg"); // Add your image path here
|
||||
|
||||
|
||||
@@ -91,7 +93,7 @@ public class PdfDao {
|
||||
document.add(new Paragraph(" "));
|
||||
|
||||
// Application ID section (Centered)
|
||||
pageEvent.setTotalPages(writer.getPageNumber());
|
||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||
Paragraph appId = new Paragraph("ID domanda :" +"XX00");
|
||||
appId.setAlignment(Element.ALIGN_RIGHT);
|
||||
document.add(appId);
|
||||
@@ -138,7 +140,7 @@ public class PdfDao {
|
||||
Integer pages=0;
|
||||
pages=addLabelValuePair(writer,document, label, value, labelFont,valueFont,call.getName(),pages);
|
||||
if(pages !=0 ){
|
||||
pageEvent.setTotalPages(writer.getPageNumber());
|
||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||
}
|
||||
}
|
||||
addColoredLines(writer,document,greenColor);
|
||||
@@ -150,8 +152,9 @@ public class PdfDao {
|
||||
// Adding the "Documenti Allegati" section title
|
||||
document.add(new Paragraph(" "));
|
||||
|
||||
pageEvent.setTotalPages(writer.getPageNumber());
|
||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||
document.newPage();
|
||||
// pageEvent.setTotalPages(writer.getPageNumber());
|
||||
document.add(new Paragraph("Documenti Allegati", sectionFont));
|
||||
document.add(new Paragraph(" "));
|
||||
|
||||
@@ -215,11 +218,20 @@ public class PdfDao {
|
||||
|
||||
addColoredLines(writer,document,greenColor);
|
||||
|
||||
// System.out.println(writer.getPageSize());
|
||||
// System.out.println(document.getPageSize());
|
||||
// System.out.println(document.getPageNumber());
|
||||
// System.out.println(writer.getPageNumber());
|
||||
// document.setPageCount(100);
|
||||
// document.setPageCount(writer.getPageNumber());
|
||||
// System.out.println(document.getPageNumber());
|
||||
|
||||
// Close the document
|
||||
document.close();
|
||||
|
||||
// Convert to byte array for response
|
||||
byte[] pdfBytes = out.toByteArray();
|
||||
byte[] pdfBytes =PdfPageNumberInserter.addPageNumbers(out.toByteArray());
|
||||
|
||||
return pdfBytes;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -308,7 +320,7 @@ public class PdfDao {
|
||||
String description = (String) entry.get(keys.get(1)); // Second key's value
|
||||
|
||||
// Store the combined result as a value in the map, with a suitable key
|
||||
String combinedValue = number + ", " + description + ", " + amount; // Concatenate them as a single value
|
||||
String combinedValue = number + "; " + description + "; " + amount; // Concatenate them as a single value
|
||||
extractedMap.put("combined", combinedValue); // Store as a single entry, key as "combined"
|
||||
}
|
||||
|
||||
@@ -380,14 +392,14 @@ public class PdfDao {
|
||||
}
|
||||
|
||||
// Split the value for "combined" into separate parts
|
||||
String[] combinedValues = value.split(", ");
|
||||
String[] combinedValues = value.split("; ");
|
||||
|
||||
// Check if we have 3 parts (number, description, amount)
|
||||
String number = combinedValues[0].trim(); // 1st part (number)
|
||||
String description = combinedValues[1].trim(); // 2nd part (description)
|
||||
String number = combinedValues[0]; // 1st part (number)
|
||||
String description = combinedValues[1]; // 2nd part (description)
|
||||
String amount = "";
|
||||
if (combinedValues.length == 3) {
|
||||
amount = combinedValues[2].trim(); // 3rd part (amount)
|
||||
amount = combinedValues[2]; // 3rd part (amount)
|
||||
}
|
||||
|
||||
// Create PDF cells using the split values
|
||||
@@ -401,9 +413,14 @@ public class PdfDao {
|
||||
cellAmount.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||
|
||||
// Set cell height and add rounded borders
|
||||
cellNumber.setFixedHeight(rowHeight);
|
||||
cellDescription.setFixedHeight(rowHeight);
|
||||
cellAmount.setFixedHeight(rowHeight);
|
||||
// cellNumber.setFixedHeight(rowHeight);
|
||||
// cellDescription.setFixedHeight(rowHeight);
|
||||
// cellAmount.setFixedHeight(rowHeight);
|
||||
|
||||
cellNumber.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||
cellDescription.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||
cellAmount.setMinimumHeight(20f); // Set minimum height for better appearance
|
||||
|
||||
cellNumber.setPadding(7f);
|
||||
cellDescription.setPadding(7f);
|
||||
cellAmount.setPadding(7f);
|
||||
@@ -441,6 +458,8 @@ public class PdfDao {
|
||||
cellKey.setBackgroundColor(new BaseColor(239, 243, 248)); // Light blue for other rows
|
||||
cellValue.setBackgroundColor(new BaseColor(239, 243, 248));
|
||||
|
||||
cellKey.setPadding(7f);
|
||||
cellValue.setPadding(7f);
|
||||
// Set cell height and add rounded borders
|
||||
cellKey.setFixedHeight(rowHeight);
|
||||
cellValue.setFixedHeight(rowHeight);
|
||||
|
||||
Reference in New Issue
Block a user