| Line 29... |
Line 29... |
| 29 |
document.close();
|
29 |
document.close();
|
| 30 |
} catch (Exception e) {
|
30 |
} catch (Exception e) {
|
| 31 |
e.printStackTrace();
|
31 |
e.printStackTrace();
|
| 32 |
}
|
32 |
}
|
| 33 |
}
|
33 |
}
|
| - |
|
34 |
// Compact fonts matching invoice style
|
| - |
|
35 |
private static final BaseColor EWB_BORDER = new BaseColor(204, 204, 204);
|
| - |
|
36 |
private static final BaseColor EWB_HEADER_BG = new BaseColor(242, 242, 242);
|
| - |
|
37 |
private static final Font EWB_TITLE = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
|
| 34 |
public static void generateDocument(Document document, PdfWriter writer, EWayBillPdfModel eWayBillPdfModel) {
|
38 |
private static final Font EWB_SECTION = new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD);
|
| - |
|
39 |
private static final Font EWB_NORMAL = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
|
| - |
|
40 |
private static final Font EWB_BOLD = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
|
| 35 |
|
41 |
|
| - |
|
42 |
public static void generateDocument(Document document, PdfWriter writer, EWayBillPdfModel eWayBillPdfModel) {
|
| 36 |
try {
|
43 |
try {
|
| 37 |
// Set up document and writer
|
- |
|
| 38 |
/*PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("EWayBill.pdf"));
|
- |
|
| 39 |
document.open();*/
|
- |
|
| 40 |
|
- |
|
| 41 |
// Load custom font (replace with the path to your specific font if you have it)
|
- |
|
| 42 |
BaseFont customFontBase = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
|
- |
|
| 43 |
Font customFont = new Font(customFontBase, 12);
|
- |
|
| 44 |
Font customBoldFont = new Font(customFontBase, 12, Font.BOLD);
|
- |
|
| 45 |
|
- |
|
| 46 |
// Title
|
44 |
// Title
|
| 47 |
Paragraph titleParagraph = new Paragraph("E-Way Bill System", new Font(customFontBase, 16, Font.BOLD));
|
45 |
Paragraph titleParagraph = new Paragraph("E-Way Bill System", EWB_TITLE);
|
| 48 |
titleParagraph.setAlignment(Element.ALIGN_CENTER);
|
46 |
titleParagraph.setAlignment(Element.ALIGN_CENTER);
|
| - |
|
47 |
titleParagraph.setSpacingAfter(6f);
|
| 49 |
document.add(titleParagraph);
|
48 |
document.add(titleParagraph);
|
| 50 |
|
49 |
|
| 51 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
- |
|
| 52 |
|
- |
|
| 53 |
// E-Way Bill Info
|
50 |
// E-Way Bill Info
|
| 54 |
PdfPTable table = new PdfPTable(2);
|
51 |
PdfPTable table = new PdfPTable(2);
|
| 55 |
table.setWidths(new float[]{1, 2});
|
52 |
table.setWidths(new float[]{1.2f, 2.8f});
|
| 56 |
table.setWidthPercentage(90);
|
53 |
table.setWidthPercentage(80);
|
| 57 |
|
- |
|
| 58 |
table.addCell(getCell("E-Way Bill No:", customBoldFont));
|
54 |
table.setSpacingAfter(6f);
|
| 59 |
table.addCell(getCell(eWayBillPdfModel.getEwbNumber(), customFont));
|
- |
|
| 60 |
|
55 |
|
| 61 |
table.addCell(getCell("E-Way Bill Date:", customBoldFont));
|
56 |
ewbRow(table, "E-Way Bill No:", eWayBillPdfModel.getEwbNumber());
|
| 62 |
table.addCell(getCell(eWayBillPdfModel.getEwbDate(), customFont));
|
57 |
ewbRow(table, "E-Way Bill Date:", eWayBillPdfModel.getEwbDate());
|
| 63 |
|
- |
|
| 64 |
table.addCell(getCell("Generated By:", customBoldFont));
|
- |
|
| 65 |
table.addCell(getCell(eWayBillPdfModel.getGeneratedBy(), customFont));
|
58 |
ewbRow(table, "Generated By:", eWayBillPdfModel.getGeneratedBy());
|
| 66 |
|
- |
|
| 67 |
table.addCell(getCell("Valid From:", customBoldFont));
|
- |
|
| 68 |
table.addCell(getCell(eWayBillPdfModel.getValidFrom(), customFont));
|
59 |
ewbRow(table, "Valid From:", eWayBillPdfModel.getValidFrom());
|
| 69 |
|
- |
|
| 70 |
table.addCell(getCell("Valid Until:", customBoldFont));
|
- |
|
| 71 |
table.addCell(getCell(eWayBillPdfModel.getValidUntil(), customFont));
|
60 |
ewbRow(table, "Valid Until:", eWayBillPdfModel.getValidUntil());
|
| 72 |
|
61 |
|
| 73 |
document.add(table);
|
62 |
document.add(table);
|
| 74 |
|
63 |
|
| 75 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
- |
|
| 76 |
|
- |
|
| 77 |
// Part A
|
64 |
// Part A
|
| 78 |
PdfPTable partATable = new PdfPTable(2);
|
- |
|
| 79 |
partATable.setWidths(new float[]{1, 2});
|
- |
|
| 80 |
partATable.setWidthPercentage(90);
|
- |
|
| 81 |
partATable.setSpacingBefore(5);
|
- |
|
| 82 |
EWBPartAModel partAModel = eWayBillPdfModel.getEwbPartAModel();
|
65 |
EWBPartAModel partAModel = eWayBillPdfModel.getEwbPartAModel();
|
| 83 |
PdfPCell partACell = getCell("Part A", new Font(customFontBase, 14, Font.BOLD));
|
66 |
PdfPTable partATable = new PdfPTable(2);
|
| 84 |
partACell.setColspan(2);
|
67 |
partATable.setWidths(new float[]{1.2f, 2.8f});
|
| 85 |
partATable.addCell(partACell);
|
68 |
partATable.setWidthPercentage(80);
|
| 86 |
partATable.addCell(getCell("GSTIN of Supplier:", customBoldFont));
|
69 |
partATable.setSpacingAfter(6f);
|
| 87 |
partATable.addCell(getCell(partAModel.getSupplierGstin(), customFont));
|
- |
|
| 88 |
|
70 |
|
| 89 |
partATable.addCell(getCell("Place of Dispatch:", customBoldFont));
|
71 |
PdfPCell partAHeader = new PdfPCell(new Phrase("Part A", EWB_SECTION));
|
| 90 |
partATable.addCell(getCell(partAModel.getPlaceOfDispatch(), customFont));
|
- |
|
| 91 |
|
- |
|
| 92 |
partATable.addCell(getCell("GSTIN of Recipient:", customBoldFont));
|
72 |
partAHeader.setColspan(2);
|
| 93 |
partATable.addCell(getCell(partAModel.getRecipientGstin(), customFont));
|
73 |
partAHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 94 |
|
- |
|
| 95 |
partATable.addCell(getCell("Place of Delivery:", customBoldFont));
|
74 |
partAHeader.setBackgroundColor(EWB_HEADER_BG);
|
| 96 |
partATable.addCell(getCell(partAModel.getPlaceOfDelivery(), customFont));
|
75 |
partAHeader.setBorderColor(EWB_BORDER);
|
| 97 |
|
- |
|
| 98 |
partATable.addCell(getCell("Document No:", customBoldFont));
|
76 |
partAHeader.setPadding(3f);
|
| 99 |
partATable.addCell(getCell(partAModel.getDocumentNumber(), customFont));
|
77 |
partATable.addCell(partAHeader);
|
| 100 |
|
78 |
|
| 101 |
partATable.addCell(getCell("Document Date:", customBoldFont));
|
79 |
ewbRow(partATable, "GSTIN of Supplier:", partAModel.getSupplierGstin());
|
| 102 |
partATable.addCell(getCell(partAModel.getDocumentDate(), customFont));
|
80 |
ewbRow(partATable, "Place of Dispatch:", partAModel.getPlaceOfDispatch());
|
| 103 |
|
- |
|
| 104 |
partATable.addCell(getCell("Transaction Type:", customBoldFont));
|
81 |
ewbRow(partATable, "GSTIN of Recipient:", partAModel.getRecipientGstin());
|
| 105 |
partATable.addCell(getCell(partAModel.getTransactType(), customFont));
|
82 |
ewbRow(partATable, "Place of Delivery:", partAModel.getPlaceOfDelivery());
|
| 106 |
|
- |
|
| 107 |
partATable.addCell(getCell("Value of Goods:", customBoldFont));
|
83 |
ewbRow(partATable, "Document No:", partAModel.getDocumentNumber());
|
| 108 |
partATable.addCell(getCell(partAModel.getValueOfGoods(), customFont));
|
84 |
ewbRow(partATable, "Document Date:", partAModel.getDocumentDate());
|
| 109 |
|
- |
|
| 110 |
partATable.addCell(getCell("HSN Code(s):", customBoldFont));
|
85 |
ewbRow(partATable, "Transaction Type:", partAModel.getTransactType());
|
| 111 |
partATable.addCell(getCell(partAModel.getHsnCode(), customFont));
|
86 |
ewbRow(partATable, "Value of Goods:", partAModel.getValueOfGoods());
|
| 112 |
|
- |
|
| 113 |
partATable.addCell(getCell("Reason for Transportation:", customBoldFont));
|
87 |
ewbRow(partATable, "HSN Code(s):", partAModel.getHsnCode());
|
| 114 |
partATable.addCell(getCell(partAModel.getReasonForTransportation(), customFont));
|
88 |
ewbRow(partATable, "Reason for Transportation:", partAModel.getReasonForTransportation());
|
| 115 |
|
- |
|
| 116 |
if(partAModel.getTransporter() != null ){
|
89 |
if (partAModel.getTransporter() != null) {
|
| 117 |
partATable.addCell(getCell("Transporter", customBoldFont));
|
- |
|
| 118 |
partATable.addCell(getCell(partAModel.getTransporter(), customFont));
|
90 |
ewbRow(partATable, "Transporter:", partAModel.getTransporter());
|
| 119 |
|
- |
|
| 120 |
}
|
91 |
}
|
| 121 |
|
92 |
|
| 122 |
document.add(partATable);
|
93 |
document.add(partATable);
|
| 123 |
|
94 |
|
| 124 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
- |
|
| 125 |
|
- |
|
| 126 |
// Part B
|
95 |
// Part B
|
| 127 |
if (eWayBillPdfModel.getEwbPartBModel() != null) {
|
96 |
if (eWayBillPdfModel.getEwbPartBModel() != null) {
|
| 128 |
// Part B Table
|
- |
|
| 129 |
PdfPCell partBCell = getCell("Part B", new Font(customFontBase, 14, Font.BOLD));
|
- |
|
| 130 |
partBCell.setColspan(7);
|
- |
|
| 131 |
PdfPTable partBTable = new PdfPTable(7); // 7 columns
|
97 |
PdfPTable partBTable = new PdfPTable(7);
|
| 132 |
partBTable.setWidths(new float[]{2, 3, 3, 4, 4, 2, 2});
|
98 |
partBTable.setWidths(new float[]{2, 3, 3, 4, 4, 2, 2});
|
| 133 |
partBTable.setWidthPercentage(90);
|
99 |
partBTable.setWidthPercentage(80);
|
| 134 |
partBTable.setSpacingBefore(5f);
|
- |
|
| 135 |
partBTable.setSpacingAfter(10f);
|
100 |
partBTable.setSpacingAfter(6f);
|
| 136 |
|
101 |
|
| 137 |
// Header Row
|
102 |
PdfPCell partBHeader = new PdfPCell(new Phrase("Part B", EWB_SECTION));
|
| 138 |
partBTable.addCell(partBCell);
|
103 |
partBHeader.setColspan(7);
|
| 139 |
Font fontNew = new Font(customFontBase, 10, Font.NORMAL);
|
104 |
partBHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 140 |
Font fontNewBold = new Font(customFontBase, 10, Font.BOLD);
|
105 |
partBHeader.setBackgroundColor(EWB_HEADER_BG);
|
| 141 |
partBTable.addCell(getCell("Mode", fontNewBold));
|
106 |
partBHeader.setBorderColor(EWB_BORDER);
|
| 142 |
partBTable.addCell(getCell("Vehicle No.", fontNewBold));
|
107 |
partBHeader.setPadding(3f);
|
| 143 |
partBTable.addCell(getCell("From", fontNewBold));
|
108 |
partBTable.addCell(partBHeader);
|
| - |
|
109 |
|
| - |
|
110 |
String[] headers = {"Mode", "Vehicle No.", "From", "Entered Date", "Entered By", "CEWB No.", "Multi Veh."};
|
| - |
|
111 |
for (String h : headers) {
|
| 144 |
partBTable.addCell(getCell("Entered Date", fontNewBold));
|
112 |
PdfPCell hc = new PdfPCell(new Phrase(h, EWB_BOLD));
|
| 145 |
partBTable.addCell(getCell("Entered By", fontNewBold));
|
113 |
hc.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| - |
|
114 |
hc.setBorderColor(EWB_BORDER);
|
| 146 |
partBTable.addCell(getCell("CEWB No.", fontNewBold));
|
115 |
hc.setBackgroundColor(EWB_HEADER_BG);
|
| - |
|
116 |
hc.setPadding(2f);
|
| 147 |
partBTable.addCell(getCell("Multi Veh.Info", fontNewBold));
|
117 |
partBTable.addCell(hc);
|
| - |
|
118 |
}
|
| 148 |
|
119 |
|
| 149 |
// Data Row
|
- |
|
| 150 |
EWBPartBModel partBModel = eWayBillPdfModel.getEwbPartBModel();
|
120 |
EWBPartBModel partBModel = eWayBillPdfModel.getEwbPartBModel();
|
| 151 |
partBTable.addCell(getCell(partBModel.getMode(), fontNew));
|
121 |
String[] data = {partBModel.getMode(), partBModel.getVehicleNumber(), partBModel.getFrom(),
|
| 152 |
partBTable.addCell(getCell(partBModel.getVehicleNumber(), fontNew));
|
122 |
partBModel.getEnteredDate(), partBModel.getEnteredBy(), "-", "-"};
|
| - |
|
123 |
for (String d : data) {
|
| 153 |
partBTable.addCell(getCell(partBModel.getFrom(), fontNew));
|
124 |
PdfPCell dc = new PdfPCell(new Phrase(d != null ? d : "-", EWB_NORMAL));
|
| 154 |
partBTable.addCell(getCell(partBModel.getEnteredDate(), fontNew));
|
125 |
dc.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 155 |
partBTable.addCell(getCell(partBModel.getEnteredBy(), fontNew));
|
126 |
dc.setBorderColor(EWB_BORDER);
|
| 156 |
partBTable.addCell(getCell("-", fontNew));
|
127 |
dc.setPadding(2f);
|
| 157 |
partBTable.addCell(getCell("-", fontNew)); // Assuming Multi Veh.Info is not provided
|
128 |
partBTable.addCell(dc);
|
| - |
|
129 |
}
|
| 158 |
|
130 |
|
| 159 |
document.add(partBTable);
|
131 |
document.add(partBTable);
|
| 160 |
|
- |
|
| 161 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
- |
|
| 162 |
}
|
132 |
}
|
| 163 |
|
133 |
|
| 164 |
// Add Barcode
|
134 |
// Barcode
|
| 165 |
Barcode128 barcode = new Barcode128();
|
135 |
Barcode128 barcode = new Barcode128();
|
| 166 |
barcode.setCode(eWayBillPdfModel.getEwbNumber());
|
136 |
barcode.setCode(eWayBillPdfModel.getEwbNumber());
|
| 167 |
barcode.setCodeType(Barcode.CODE128);
|
137 |
barcode.setCodeType(Barcode.CODE128);
|
| 168 |
Image barcodeImage = barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.BLACK);
|
138 |
Image barcodeImage = barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.BLACK);
|
| 169 |
barcodeImage.setAlignment(Element.ALIGN_CENTER);
|
139 |
barcodeImage.setAlignment(Element.ALIGN_CENTER);
|
| 170 |
barcodeImage.scalePercent(150);
|
140 |
barcodeImage.scalePercent(120);
|
| 171 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
- |
|
| 172 |
document.add(barcodeImage);
|
141 |
document.add(barcodeImage);
|
| 173 |
|
142 |
|
| 174 |
|
- |
|
| 175 |
//document.add(new Paragraph("Note*: If any discrepancy in information please try after sometime.", customFont));
|
- |
|
| 176 |
|
- |
|
| 177 |
|
- |
|
| 178 |
} catch (Exception e) {
|
143 |
} catch (Exception e) {
|
| 179 |
e.printStackTrace();
|
144 |
e.printStackTrace();
|
| 180 |
}
|
145 |
}
|
| 181 |
}
|
146 |
}
|
| 182 |
|
147 |
|
| - |
|
148 |
private static void ewbRow(PdfPTable table, String label, String value) {
|
| - |
|
149 |
PdfPCell lc = new PdfPCell(new Phrase(label, EWB_BOLD));
|
| - |
|
150 |
lc.setHorizontalAlignment(Element.ALIGN_RIGHT);
|
| - |
|
151 |
lc.setBorderColor(EWB_BORDER);
|
| - |
|
152 |
lc.setPadding(3f);
|
| - |
|
153 |
table.addCell(lc);
|
| - |
|
154 |
PdfPCell vc = new PdfPCell(new Phrase(value != null ? value : "", EWB_NORMAL));
|
| - |
|
155 |
vc.setBorderColor(EWB_BORDER);
|
| - |
|
156 |
vc.setPadding(3f);
|
| - |
|
157 |
table.addCell(vc);
|
| - |
|
158 |
}
|
| - |
|
159 |
|
| 183 |
private static PdfPCell getCell(String text, Font font) {
|
160 |
private static PdfPCell getCell(String text, Font font) {
|
| 184 |
PdfPCell cell = new PdfPCell(new Phrase(text, font));
|
161 |
PdfPCell cell = new PdfPCell(new Phrase(text, font));
|
| 185 |
cell.setPadding(5);
|
162 |
cell.setPadding(5);
|
| 186 |
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
163 |
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
| 187 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
164 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|