use of com.itextpdf.text.RectangleReadOnly in project carina by qaprosoft.
the class AbstractPage method savePageAsPdf.
public String savePageAsPdf(boolean scaled) throws IOException, DocumentException {
String pdfName = "";
// Define test screenshot root
String test = TestNamingService.getTestName();
File testRootDir = ReportContext.getTestDir();
File artifactsFolder = ReportContext.getArtifactsFolder();
String fileID = test.replaceAll("\\W+", "_") + "-" + System.currentTimeMillis();
pdfName = fileID + ".pdf";
String fullPdfPath = artifactsFolder.getAbsolutePath() + "/" + pdfName;
// TODO: test this implementation and change back to capture if necessary
Image image = Image.getInstance(testRootDir.getAbsolutePath() + "/" + Screenshot.capture(getDriver(), "", true));
Document document = null;
if (scaled) {
document = new Document(PageSize.A4, 10, 10, 10, 10);
if (image.getHeight() > (document.getPageSize().getHeight() - 20) || image.getScaledWidth() > (document.getPageSize().getWidth() - 20)) {
image.scaleToFit(document.getPageSize().getWidth() - 20, document.getPageSize().getHeight() - 20);
}
} else {
document = new Document(new RectangleReadOnly(image.getScaledWidth(), image.getScaledHeight()));
}
PdfWriter.getInstance(document, new FileOutputStream(fullPdfPath));
document.open();
document.add(image);
document.close();
return fullPdfPath;
}
Aggregations