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
exporting single case to pdf #46
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
|
@@ -14,11 +13,13 @@ | |
import com.itextpdf.text.Document; | ||
import com.itextpdf.text.DocumentException; | ||
import com.itextpdf.text.Font; | ||
import com.itextpdf.text.ListItem; | ||
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; | ||
import com.kritsit.casetracker.shared.domain.model.Case; | ||
|
||
public class Export implements IExportService{ | ||
|
||
|
@@ -29,12 +30,12 @@ public void exportToPDF(List<String> headers, List<String[]> cells, File file){ | |
Document document = new Document(); | ||
|
||
try { | ||
logger.info("Creating file output"); | ||
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"); | ||
logger.info("export to PDF: success"); | ||
} catch (DocumentException e) { | ||
logger.error("Error while exporting to PDF"); | ||
logger.error(e.toString()); | ||
|
@@ -46,7 +47,7 @@ public void exportToPDF(List<String> headers, List<String[]> cells, File file){ | |
|
||
private PdfPTable createTable(List<String> headers, List<String[]> cells){ | ||
|
||
PdfPTable table = new PdfPTable(headers.size()); | ||
PdfPTable table = new PdfPTable(headers.size()); | ||
Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); | ||
logger.info("Filling in the table"); | ||
|
||
|
@@ -63,4 +64,34 @@ private PdfPTable createTable(List<String> headers, List<String[]> cells){ | |
} | ||
return table; | ||
} | ||
|
||
public void exportCaseToPDF(Case c, File file) { | ||
Document document = new Document(); | ||
|
||
try { | ||
logger.info("Creating file output"); | ||
PdfWriter.getInstance(document, new FileOutputStream(file)); | ||
document.open(); | ||
Font titleFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); | ||
Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); | ||
|
||
document.add(new Paragraph("Case no. "+c.getNumber(), titleFont)); | ||
document.add(new Paragraph("Investigating officer: "+c.getInvestigatingOfficer().getLastName()+" "+c.getInvestigatingOfficer().getFirstName(), normalFont)); | ||
document.add(new Paragraph("Incident date: "+c.getIncident().getDate(), normalFont)); | ||
document.add(new Paragraph(c.getDescription(), normalFont)); | ||
document.add(new Paragraph("Evidence: ", normalFont)); | ||
com.itextpdf.text.List list = new com.itextpdf.text.List(); | ||
for(int i=0; i < c.getEvidence().size(); i++){ | ||
list.add(new ListItem(c.getEvidence().get(i).getDescription())); | ||
} | ||
document.close(); | ||
logger.info("export to PDF: success"); | ||
} catch (DocumentException e) { | ||
logger.error("Error while exporting to PDF"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logger.error() can take the Exception as a parameter. It then prints out the stack trace nicely. So these logging lines can be merged into one |
||
logger.error(e.toString()); | ||
} catch (FileNotFoundException e) { | ||
logger.error("Error while exporting to PDF"); | ||
logger.error(e.toString()); | ||
} | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can call
.getName()
which combines the name