| 33741 |
amit.gupta |
1 |
package com.spice.profitmandi.common.util;
|
|
|
2 |
|
|
|
3 |
import com.itextpdf.text.*;
|
|
|
4 |
import com.itextpdf.text.pdf.*;
|
|
|
5 |
import com.spice.profitmandi.common.model.EWBPartAModel;
|
|
|
6 |
import com.spice.profitmandi.common.model.EWBPartBModel;
|
|
|
7 |
import com.spice.profitmandi.common.model.EWayBillPdfModel;
|
|
|
8 |
|
|
|
9 |
import java.io.FileOutputStream;
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
public class EWayBillPDF {
|
|
|
13 |
|
|
|
14 |
public static void main(String[] args) {
|
|
|
15 |
EWayBillPDF eWayBillPDF = new EWayBillPDF();
|
|
|
16 |
EWayBillPdfModel eWayBillPdfModel = new EWayBillPdfModel();
|
|
|
17 |
EWBPartAModel partAModel = new EWBPartAModel();
|
|
|
18 |
eWayBillPdfModel.setEwbPartAModel(partAModel);
|
|
|
19 |
eWayBillPDF.generateDocument(eWayBillPdfModel);
|
|
|
20 |
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public static void generateDocument(EWayBillPdfModel eWayBillPdfModel) {
|
|
|
24 |
Document document = new Document();
|
|
|
25 |
try {
|
|
|
26 |
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("EWayBill.pdf"));
|
|
|
27 |
document.open();
|
|
|
28 |
EWayBillPDF.generateDocument(document, writer, eWayBillPdfModel);
|
|
|
29 |
document.close();
|
|
|
30 |
} catch (Exception e) {
|
|
|
31 |
e.printStackTrace();
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
public static void generateDocument(Document document, PdfWriter writer, EWayBillPdfModel eWayBillPdfModel) {
|
|
|
35 |
|
|
|
36 |
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
|
|
|
47 |
Paragraph titleParagraph = new Paragraph("E-Way Bill System", new Font(customFontBase, 16, Font.BOLD));
|
|
|
48 |
titleParagraph.setAlignment(Element.ALIGN_CENTER);
|
|
|
49 |
document.add(titleParagraph);
|
|
|
50 |
|
|
|
51 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
|
|
52 |
|
|
|
53 |
// E-Way Bill Info
|
|
|
54 |
PdfPTable table = new PdfPTable(2);
|
|
|
55 |
table.setWidths(new float[]{1, 2});
|
|
|
56 |
table.setWidthPercentage(90);
|
|
|
57 |
|
|
|
58 |
table.addCell(getCell("E-Way Bill No:", customBoldFont));
|
|
|
59 |
table.addCell(getCell(eWayBillPdfModel.getEwbNumber(), customFont));
|
|
|
60 |
|
|
|
61 |
table.addCell(getCell("E-Way Bill Date:", customBoldFont));
|
|
|
62 |
table.addCell(getCell(eWayBillPdfModel.getEwbDate(), customFont));
|
|
|
63 |
|
|
|
64 |
table.addCell(getCell("Generated By:", customBoldFont));
|
|
|
65 |
table.addCell(getCell(eWayBillPdfModel.getGeneratedBy(), customFont));
|
|
|
66 |
|
|
|
67 |
table.addCell(getCell("Valid From:", customBoldFont));
|
|
|
68 |
table.addCell(getCell(eWayBillPdfModel.getValidFrom(), customFont));
|
|
|
69 |
|
|
|
70 |
table.addCell(getCell("Valid Until:", customBoldFont));
|
|
|
71 |
table.addCell(getCell(eWayBillPdfModel.getValidUntil(), customFont));
|
|
|
72 |
|
|
|
73 |
document.add(table);
|
|
|
74 |
|
|
|
75 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
|
|
76 |
|
|
|
77 |
// 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();
|
|
|
83 |
PdfPCell partACell = getCell("Part A", new Font(customFontBase, 14, Font.BOLD));
|
|
|
84 |
partACell.setColspan(2);
|
|
|
85 |
partATable.addCell(partACell);
|
|
|
86 |
partATable.addCell(getCell("GSTIN of Supplier:", customBoldFont));
|
|
|
87 |
partATable.addCell(getCell(partAModel.getSupplierGstin(), customFont));
|
|
|
88 |
|
|
|
89 |
partATable.addCell(getCell("Place of Dispatch:", customBoldFont));
|
|
|
90 |
partATable.addCell(getCell(partAModel.getPlaceOfDispatch(), customFont));
|
|
|
91 |
|
|
|
92 |
partATable.addCell(getCell("GSTIN of Recipient:", customBoldFont));
|
|
|
93 |
partATable.addCell(getCell(partAModel.getRecipientGstin(), customFont));
|
|
|
94 |
|
|
|
95 |
partATable.addCell(getCell("Place of Delivery:", customBoldFont));
|
|
|
96 |
partATable.addCell(getCell(partAModel.getPlaceOfDelivery(), customFont));
|
|
|
97 |
|
|
|
98 |
partATable.addCell(getCell("Document No:", customBoldFont));
|
|
|
99 |
partATable.addCell(getCell(partAModel.getDocumentNumber(), customFont));
|
|
|
100 |
|
|
|
101 |
partATable.addCell(getCell("Document Date:", customBoldFont));
|
|
|
102 |
partATable.addCell(getCell(partAModel.getDocumentDate(), customFont));
|
|
|
103 |
|
|
|
104 |
partATable.addCell(getCell("Transaction Type:", customBoldFont));
|
|
|
105 |
partATable.addCell(getCell(partAModel.getTransactType(), customFont));
|
|
|
106 |
|
|
|
107 |
partATable.addCell(getCell("Value of Goods:", customBoldFont));
|
|
|
108 |
partATable.addCell(getCell(partAModel.getValueOfGoods(), customFont));
|
|
|
109 |
|
|
|
110 |
partATable.addCell(getCell("HSN Code(s):", customBoldFont));
|
|
|
111 |
partATable.addCell(getCell(partAModel.getHsnCode(), customFont));
|
|
|
112 |
|
|
|
113 |
partATable.addCell(getCell("Reason for Transportation:", customBoldFont));
|
|
|
114 |
partATable.addCell(getCell(partAModel.getReasonForTransportation(), customFont));
|
|
|
115 |
|
| 33742 |
amit.gupta |
116 |
if(partAModel.getTransporter() != null ){
|
|
|
117 |
partATable.addCell(getCell("Transporter", customBoldFont));
|
|
|
118 |
partATable.addCell(getCell(partAModel.getTransporter(), customFont));
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
|
| 33741 |
amit.gupta |
122 |
document.add(partATable);
|
|
|
123 |
|
|
|
124 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
|
|
125 |
|
|
|
126 |
// Part B
|
|
|
127 |
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
|
|
|
132 |
partBTable.setWidths(new float[]{2, 3, 3, 4, 4, 2, 2});
|
|
|
133 |
partBTable.setWidthPercentage(90);
|
|
|
134 |
partBTable.setSpacingBefore(5f);
|
|
|
135 |
partBTable.setSpacingAfter(10f);
|
|
|
136 |
|
|
|
137 |
// Header Row
|
|
|
138 |
partBTable.addCell(partBCell);
|
|
|
139 |
Font fontNew = new Font(customFontBase, 10, Font.NORMAL);
|
|
|
140 |
Font fontNewBold = new Font(customFontBase, 10, Font.BOLD);
|
|
|
141 |
partBTable.addCell(getCell("Mode", fontNewBold));
|
|
|
142 |
partBTable.addCell(getCell("Vehicle No.", fontNewBold));
|
|
|
143 |
partBTable.addCell(getCell("From", fontNewBold));
|
|
|
144 |
partBTable.addCell(getCell("Entered Date", fontNewBold));
|
|
|
145 |
partBTable.addCell(getCell("Entered By", fontNewBold));
|
|
|
146 |
partBTable.addCell(getCell("CEWB No.", fontNewBold));
|
|
|
147 |
partBTable.addCell(getCell("Multi Veh.Info", fontNewBold));
|
|
|
148 |
|
|
|
149 |
// Data Row
|
|
|
150 |
EWBPartBModel partBModel = eWayBillPdfModel.getEwbPartBModel();
|
|
|
151 |
partBTable.addCell(getCell(partBModel.getMode(), fontNew));
|
|
|
152 |
partBTable.addCell(getCell(partBModel.getVehicleNumber(), fontNew));
|
|
|
153 |
partBTable.addCell(getCell(partBModel.getFrom(), fontNew));
|
|
|
154 |
partBTable.addCell(getCell(partBModel.getEnteredDate(), fontNew));
|
|
|
155 |
partBTable.addCell(getCell(partBModel.getEnteredBy(), fontNew));
|
|
|
156 |
partBTable.addCell(getCell("-", fontNew));
|
|
|
157 |
partBTable.addCell(getCell("-", fontNew)); // Assuming Multi Veh.Info is not provided
|
|
|
158 |
|
|
|
159 |
document.add(partBTable);
|
|
|
160 |
|
|
|
161 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
// Add Barcode
|
|
|
165 |
Barcode128 barcode = new Barcode128();
|
|
|
166 |
barcode.setCode(eWayBillPdfModel.getEwbNumber());
|
|
|
167 |
barcode.setCodeType(Barcode.CODE128);
|
|
|
168 |
Image barcodeImage = barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.BLACK);
|
|
|
169 |
barcodeImage.setAlignment(Element.ALIGN_CENTER);
|
|
|
170 |
barcodeImage.scalePercent(150);
|
|
|
171 |
document.add(new Paragraph(" ", customFont)); // Empty space
|
|
|
172 |
document.add(barcodeImage);
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
//document.add(new Paragraph("Note*: If any discrepancy in information please try after sometime.", customFont));
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
} catch (Exception e) {
|
|
|
179 |
e.printStackTrace();
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
private static PdfPCell getCell(String text, Font font) {
|
|
|
184 |
PdfPCell cell = new PdfPCell(new Phrase(text, font));
|
|
|
185 |
cell.setPadding(5);
|
|
|
186 |
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
|
|
187 |
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
|
|
|
188 |
cell.setBorder(PdfPCell.BOX);
|
|
|
189 |
return cell;
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|