-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateInvoice.java
186 lines (133 loc) · 6.26 KB
/
GenerateInvoice.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.hammad.jfx1;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import java.io.IOException;
public class GenerateInvoice {
String invoiceFullname;
String invoiceLicense ;
String invoicePlateNum ;
public GenerateInvoice(String invoiceFullname, String invoiceLicense, String invoicePlateNum, String invoiceCarMake, String invoiceCarModel,String invoiceRentedDays, String invoiceTotalCost) {
this.invoiceFullname = invoiceFullname;
this.invoiceLicense = invoiceLicense;
this.invoicePlateNum = invoicePlateNum;
this.invoiceCarMake = invoiceCarMake;
this.invoiceRentedDays = invoiceRentedDays;
this.invoiceTotalCost = invoiceTotalCost;
this.invoiceCarModel = invoiceCarModel;
}
String invoiceCarMake ;
String invoiceRentedDays;
String invoiceTotalCost;
String invoiceCarModel;
public void generateBill() throws IOException {
int fontSize8 = 8;
int xCoordinate = 200;
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A6);
document.addPage( page );
PDImageXObject pdImage = PDImageXObject.createFromFile("C:\\Users\\Hammad\\Desktop\\JAVAFX\\jfx-1\\src\\main\\resources\\com\\hammad\\jfx1\\car next-logos_black.png", document);
// Create a new font object selecting one of the PDF base fonts
PDFont font = PDType1Font.COURIER;
PDFont font1 = PDType1Font.COURIER_BOLD;
// Start a new content stream which will "hold" the to be created content
PDPageContentStream contentStream = new PDPageContentStream(document, page);
// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
contentStream.drawImage(pdImage, 100, 330, 100,100);
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 125, 330 );
contentStream.drawString( "Invoice" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,280);
contentStream.drawString( "Full Name:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,280);
contentStream.drawString( invoiceFullname );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,260);
contentStream.drawString( "License Number:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,260);
contentStream.drawString( invoiceLicense);
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,240);
contentStream.drawString( "Car Make:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,240);
contentStream.drawString( invoiceCarMake);
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,220);
contentStream.drawString( "Car Model:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,220);
contentStream.drawString( invoiceCarModel);
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,200);
contentStream.drawString( "Car Plate Number:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,200);
contentStream.drawString( invoicePlateNum);
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,180);
contentStream.drawString( "Days Rented:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,180);
contentStream.drawString( invoiceRentedDays);
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,160);
contentStream.drawString( "-------------------------------------------------" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,140);
contentStream.drawString( "Total Cost:" );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font1,fontSize8);
contentStream.moveTextPositionByAmount(xCoordinate,140);
contentStream.drawString( "$ "+invoiceTotalCost );
contentStream.endText();
contentStream.beginText();
contentStream.setFont(font,fontSize8);
contentStream.moveTextPositionByAmount(30,120);
contentStream.drawString( "-------------------------------------------------" );
contentStream.endText();
// Make sure that the content stream is closed:
contentStream.close();
// Save the results and ensure that the document is properly closed:
document.save("C:\\Users\\Hammad\\Desktop\\CAT201 PROJECT\\invoice.pdf");
document.close();
}
}