This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pawc
committed
Oct 23, 2015
1 parent
c3587f2
commit 365632e
Showing
4 changed files
with
81 additions
and
54 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
client/src/main/java/com/kritsit/casetracker/client/domain/services/Export.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.kritsit.casetracker.client.domain.services; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.itextpdf.text.Chunk; | ||
import com.itextpdf.text.Document; | ||
import com.itextpdf.text.DocumentException; | ||
import com.itextpdf.text.Font; | ||
import com.itextpdf.text.Paragraph; | ||
import com.itextpdf.text.Phrase; | ||
import com.itextpdf.text.pdf.PdfPCell; | ||
import com.itextpdf.text.pdf.PdfPTable; | ||
import com.itextpdf.text.pdf.PdfWriter; | ||
|
||
public class Export implements IExportService{ | ||
|
||
private final Logger logger = LoggerFactory.getLogger(Export.class); | ||
|
||
private void exportToPDF(List<String> headers, List<String[]> cells, File file){ | ||
|
||
Document document = new Document(); | ||
|
||
try { | ||
logger.info("Creating file output"); | ||
PdfWriter.getInstance(document, | ||
new FileOutputStream(file)); | ||
document.open(); | ||
document.add(createTable(headers, cells)); | ||
document.close(); | ||
logger.info("export to PDF: success"); | ||
} catch (DocumentException e) { | ||
e.printStackTrace(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private PdfPTable createTable(List<String> headers, List<String[]> cells){ | ||
|
||
PdfPTable table = new PdfPTable(headers.size()); | ||
Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); | ||
logger.info("Filling in the table"); | ||
|
||
for(int i=0; i<headers.size(); i++){ | ||
PdfPCell cell = new PdfPCell(new Phrase(headers.get(i), boldFont)); | ||
table.addCell(cell); | ||
} | ||
|
||
for(int j=0; i<cells.size(); j++){ | ||
for(int k=0; k < cells.get(j).length; k++){ | ||
PdfPCell cell = new PdfPCell(new Phrase(cells.get(j)[k])); | ||
table.addCell(cell); | ||
} | ||
} | ||
return table; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
client/src/main/java/com/kritsit/casetracker/client/domain/services/IExportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.kritsit.casetracker.client.domain.services; | ||
|
||
import java.util.List; | ||
import java.io.File; | ||
|
||
public interface IExportService { | ||
void exportToPDF(List<String> headers, List<String[]> cells, File file); | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These should rather be logged than printed to the console