Hi Team,
My pdf file is generated using excel to pdf conversion. After that my code is trying to add Logo image, Report name and report generation time on the top of the first page of the generated pdf but it is not adding. FYI, The same code worked fine in 18.5 older aspose jar version. Below is the code snippet i am using to add the said details. Please check and suggest.
Java code to add Logo, Report Name and time.
public void addLogoAndFilters(String pdfFilePath, String title, String requestedDate, boolean showFilters,
Map<String, OutputFilter> reportFilters, Font font) {
setAsposePdfLicense();
Document pdfDocument = new Document(pdfFilePath);
Page page = pdfDocument.getPages().get_Item(1);
Table table = new Table();
table.setColumnWidths(“25 125”);
// Add an image to the header
Image image = new Image();
image.setImageStream(Thread.currentThread().getContextClassLoader()
.getResourceAsStream(“images/”.concat(PdfOutputConstants.SPLASH_ICON_IMAGE_FILE_NAME)));
image.setFixWidth(20); // Set the image width
image.setFixHeight(20); // Set the image height
Row imageRow = table.getRows().add();
Row hrRow = table.getRows().add();
Row executedOn = table.getRows().add();
Cell imageCell = imageRow.getCells().add();
imageCell.setRowSpan(3);
// imageCell.setAlignment(HorizontalAlignment.Right);
imageCell.getParagraphs().add(image);
imageCell.setWidth(50);
Cell titleCell = imageRow.getCells().add();
titleCell.getParagraphs().add(new TextFragment(replaceCharactersNotSupportedByFontFile(title, " ", font)));
// titleCell.setAlignment(HorizontalAlignment.Left);
titleCell.setWidth(300);
TextState tState = titleCell.getDefaultCellTextState();
tState.setForegroundColor(Color.getBlue());
// tState.setFont(font);
tState.setFontSize(6);
Cell hrCell = hrRow.getCells().add();
// hrCell.setAlignment(HorizontalAlignment.Left);
hrCell.setWidth(300);
hrCell.getParagraphs().add(new HtmlFragment("<HR>"));
Cell executedOncell = executedOn.getCells().add();
// executedOncell.setAlignment(HorizontalAlignment.Left);
executedOncell.getParagraphs().add(new TextFragment("Report Executed On : " + requestedDate));
executedOncell.setWidth(300);
tState = executedOncell.getDefaultCellTextState();
tState.setForegroundColor(Color.getGray());
// tState.setFont(font);
tState.setFontSize(6);
page.getParagraphs().add(table);
addFilters(page, showFilters, reportFilters);
savePdfDocument(pdfDocument, pdfFilePath);
}
Expected result - actual pdf gen file.pdf
Actual result - expected pdf gen file.pdf
test pdf gen files.zip (133.5 KB)