Skip to content

Commit

Permalink
Fixed IO Exception. #2475
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Aug 12, 2023
1 parent 9a8d71f commit f58fb99
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ public String generatePdf(Tag tag) throws FileNotFoundException {
return dest;
} catch (ParseException | CerberusException | JSONException ex) {
LOG.error(ex, ex);
} catch (Exception ex) {
LOG.error(ex, ex);
}
return null;
}
Expand All @@ -395,11 +397,11 @@ private Text getTextFromString(String text, int fontSize, boolean isBold) {
}
}

private Table getImageTable(List<TestCaseExecutionFile> controlFileList, String mediaPath) {
private Table getImageTable(List<TestCaseExecutionFile> fileList, String mediaPath) {
Table tableTmp = null;
// We count the nb of images in the file list.
int nbImages = 0;
for (TestCaseExecutionFile controlFile : controlFileList) {
for (TestCaseExecutionFile controlFile : fileList) {
if (controlFile.isImage()) {
nbImages++;
}
Expand All @@ -408,18 +410,28 @@ private Table getImageTable(List<TestCaseExecutionFile> controlFileList, String
if (nbImages > 0) {
tableTmp = new Table(new float[]{150, 500});

for (TestCaseExecutionFile controlFile : controlFileList) {
for (TestCaseExecutionFile controlFile : fileList) {
if (controlFile.isImage()) {
// Load screenshots to pdf.
ImageData imageData;
try {
imageData = ImageDataFactory.create(mediaPath + controlFile.getFileName());
Image image = new Image(imageData).scaleToFit(500, 200);
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));
File f = new File(mediaPath + controlFile.getFileName());
if (f.exists()) {
imageData = ImageDataFactory.create(mediaPath + controlFile.getFileName());
Image image = new Image(imageData).scaleToFit(500, 200);
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(image.setBorder(Border.NO_BORDER).setHorizontalAlignment(HorizontalAlignment.RIGHT)).setBorder(Border.NO_BORDER));

}else{
tableTmp.addCell(new Cell().add(new Paragraph().add(getTextFromString(controlFile.getFileDesc(), 7, false)).setTextAlignment(TextAlignment.LEFT))
.setBorder(Border.NO_BORDER).setVerticalAlignment(VerticalAlignment.MIDDLE))
.addCell(new Cell().add(new Paragraph().add(getTextFromString("File no longuer exist !!!", 7, false)).setTextAlignment(TextAlignment.RIGHT)).setBorder(Border.NO_BORDER));
}
} catch (MalformedURLException ex) {
LOG.error(ex, ex);
} catch (Exception ex) {
LOG.error(ex, ex);
}
}

Expand Down

0 comments on commit f58fb99

Please sign in to comment.