| 21974 |
ashik.ali |
1 |
package in.shop2020.dtrapi.utils;
|
|
|
2 |
|
|
|
3 |
import java.io.OutputStream;
|
|
|
4 |
import java.lang.reflect.Type;
|
|
|
5 |
import java.util.HashMap;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
|
|
|
8 |
import com.google.gson.Gson;
|
|
|
9 |
import com.google.gson.reflect.TypeToken;
|
|
|
10 |
import com.itextpdf.text.Document;
|
|
|
11 |
import com.itextpdf.text.Element;
|
|
|
12 |
import com.itextpdf.text.Font;
|
|
|
13 |
import com.itextpdf.text.Image;
|
|
|
14 |
import com.itextpdf.text.Paragraph;
|
|
|
15 |
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
16 |
|
|
|
17 |
import in.shop2020.dtrapi.Storage.Mongo;
|
|
|
18 |
|
|
|
19 |
public class PdfGenerator {
|
|
|
20 |
private static final Map<String, String> titles = new HashMap<String, String>();
|
|
|
21 |
static{
|
|
|
22 |
titles.put("bEntityDoc", "bEntityDoc");
|
|
|
23 |
titles.put("gstDoc", "gstDoc");
|
|
|
24 |
titles.put("panDoc", "panDoc");
|
|
|
25 |
titles.put("itrDoc", "itrDoc");
|
|
|
26 |
titles.put("angleDoc1", "angleDoc1");
|
|
|
27 |
titles.put("angleDoc2", "angleDoc2");
|
|
|
28 |
titles.put("angleDoc3", "angleDoc3");
|
|
|
29 |
titles.put("angleDoc4", "angleDoc4");
|
|
|
30 |
titles.put("angleDoc5", "angleDoc5");
|
|
|
31 |
titles.put("ownershipDoc", "ownershipDoc");
|
|
|
32 |
titles.put("chequeCopy", "chequeCopy");
|
|
|
33 |
}
|
|
|
34 |
private static final Font FONT_TITLE = new Font(Font.FontFamily.HELVETICA , 18, Font.BOLD);
|
|
|
35 |
private static Font FONT_BOLD = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
|
|
|
36 |
public static void generateAndWrite(OutputStream outputStream, int fofoId) throws Exception{
|
|
|
37 |
//String responseString = HttpClientUtil.doGet("localhost:8080", fofoId);
|
|
|
38 |
Document document = new Document();
|
|
|
39 |
document.setMargins(0, 0, 25, 0);
|
|
|
40 |
PdfWriter.getInstance(document, outputStream);
|
|
|
41 |
document.open();
|
|
|
42 |
Paragraph paragraphTitle = new Paragraph("sdfsdfsdfsdf", FONT_TITLE);
|
|
|
43 |
paragraphTitle.setAlignment(Element.ALIGN_CENTER);
|
|
|
44 |
document.add(paragraphTitle);
|
|
|
45 |
|
|
|
46 |
String jsonString = Mongo.getFofoFormJsonStringByFofoId(fofoId);
|
|
|
47 |
Gson gson = new Gson();
|
|
|
48 |
Map<String, String> titlePathMap = new HashMap<String, String>();
|
|
|
49 |
Type stringStringMap = new TypeToken<Map<String, String>>(){}.getType();
|
|
|
50 |
Map<String, String> map = gson.fromJson(jsonString, stringStringMap);
|
|
|
51 |
System.out.println(map);
|
|
|
52 |
for(String key : map.keySet()){
|
|
|
53 |
String value = map.get(key).toString();
|
|
|
54 |
if(value.startsWith("/hsps-docs/")){
|
|
|
55 |
titlePathMap.put(titles.get(key), value);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
System.out.println(titlePathMap);
|
|
|
59 |
for(Map.Entry<String, String> entry : titlePathMap.entrySet()){
|
|
|
60 |
Paragraph title = new Paragraph(entry.getKey(), FONT_BOLD);
|
|
|
61 |
document.add(title);
|
|
|
62 |
try{
|
|
|
63 |
Image img = Image.getInstance(entry.getValue());
|
|
|
64 |
document.setPageSize(img);
|
|
|
65 |
document.newPage();
|
|
|
66 |
img.setAbsolutePosition(0, 0);
|
|
|
67 |
document.add(img);
|
|
|
68 |
}catch (Exception e) {
|
|
|
69 |
e.printStackTrace();
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/*PdfPTable table = new PdfPTable(1);
|
|
|
74 |
PdfPCell cell = new PdfPCell();
|
|
|
75 |
ElementList list = XMLWorkerHelper.parseToElementList(responseString, null);
|
|
|
76 |
for (Element element : list) {
|
|
|
77 |
cell.addElement(element);
|
|
|
78 |
}
|
|
|
79 |
table.addCell(cell);
|
|
|
80 |
document.add(table);*/
|
|
|
81 |
|
|
|
82 |
// step 5
|
|
|
83 |
document.close();
|
|
|
84 |
}
|
|
|
85 |
}
|