- Code: Select all
grid = new PdfGrid();
rs = noteService.getNoteSection(noteSn);
doc = new PdfDocument();
page = doc.getPages().add(PdfPageSize.A4,new PdfMargins(40));
String htmlString = EgovWebUtil.resetXSSMinimum((String)rs.get("cn"));
String outputFile = "C:\\upload\\note\\HtmlToPdf2.pdf";
String pluginPath = "C:\\upload\\note\\plugins";
HtmlConverter.setPluginPath(pluginPath);
HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(592, 837), new PdfMargins(40), LoadHtmlType.Source_Code);
This code is how to save HTMLString straight to PDF. I want to save all my sources in grid and then save them as PDF. Here is my code.
- Code: Select all
list = noteService.noteMethodList(noteSn);
grid = new PdfGrid();
doc = new PdfDocument();
page = doc.getPages().add(PdfPageSize.A4,new PdfMargins(40));
//Set font for header and the rest cells
grid.getStyle().setFont(cjkFont);
data = new String[list.size()+1];
items1 = String.valueOf(list.get(0).get("item1Nm")) == "null"? "":list.get(0).get("item1Nm").toString();
items2 = String.valueOf(list.get(0).get("item2Nm")) == "null"? "":list.get(0).get("item2Nm").toString();
data[0] = "번호; 작성; 설명;"+items1+"; "+items2;
for(int j=0; j<list.size();j++) {
String expln = String.valueOf(list.get(j).get("expln")) == "null" ? "": list.get(j).get("expln").toString();
data[j+1] = j+1+"; "+list.get(j).get("wrt")+"; "+expln+"; "+list.get(j).get("item1")+"; "+list.get(j).get("item2");
}
dataSource = new String[data.length][];
for (int j = 0; j < data.length; j++) {
dataSource[j] = data[j].split("[;]", -1);
}
grid.setDataSource(dataSource);
for(int j=0; j<dataSource.length; j++) {
grid.getRows().get(0).getStyle().setBackgroundBrush(PdfBrushes.getGray());
}
//list = noteService.noteFnceList(noteSn);
grid.draw(page, new Point2D.Float(0, 380));
doc.saveToFile("C:\\upload\\note\\HtmlToPdf7.pdf")
This is a repeat statement. I want to save it to the grid like this and then save the pdf file at the end. But currently this code is 'grid.draw(page, new Point2D.Float(0, 380));' You need to arbitrarily specify the page and height in the part. My data is in flux. Therefore, height and page cannot be specified. Do you have code that splices height and pages rather than fix values?
If not, you need to save all pdf files and then merge them. However, when merging, the grid with small data has too many white backgrounds. Is it possible to connect pdf data naturally rather than merging pages?