本文整理汇总了Java中com.itextpdf.text.Image.getScaledWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getScaledWidth方法的具体用法?Java Image.getScaledWidth怎么用?Java Image.getScaledWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.Image
的用法示例。
在下文中一共展示了Image.getScaledWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: savePageAsPdf
import com.itextpdf.text.Image; //导入方法依赖的package包/类
public String savePageAsPdf(boolean scaled) throws IOException, DocumentException
{
String pdfName = "";
// Define test screenshot root
String test = "";
if (TestNamingUtil.isTestNameRegistered()) {
test = TestNamingUtil.getTestNameByThread();
} else {
test = "undefined";
}
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.captureFailure(driver, ""));
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;
}
示例2: cropImageToMeetRatio
import com.itextpdf.text.Image; //导入方法依赖的package包/类
public static Image cropImageToMeetRatio(PdfWriter pdfWriter, Image image, float heightToWidthRatio) throws
DocumentException {
float imageWidth = image.getScaledWidth();
float imageHeight = image.getScaledHeight();
float imageDesiredWidth = imageHeight / heightToWidthRatio;
float widthToCut = imageWidth - imageDesiredWidth; //TODO: Sprawdzic czy liczba nie jest ujemna. Jeżeli tak to przycinać wysokość zamiast szerokości
return cropImage(pdfWriter, image, new CropRectangle(widthToCut / 2, widthToCut / 2, 0, 0));
}
示例3: cropImage
import com.itextpdf.text.Image; //导入方法依赖的package包/类
private static Image cropImage(PdfWriter pdfWriter, Image image, CropRectangle cropRectangle) throws
DocumentException {
float width = image.getScaledWidth();
float height = image.getScaledHeight();
PdfTemplate template = pdfWriter.getDirectContent().createTemplate(
width - cropRectangle.leftReduction - cropRectangle.rightReduction,
height - cropRectangle.topReduction - cropRectangle.bottomReduction);
template.addImage(image,
width, 0, 0,
height, -cropRectangle.leftReduction, -cropRectangle.bottomReduction);
return Image.getInstance(template);
}
示例4: cropMapImage
import com.itextpdf.text.Image; //导入方法依赖的package包/类
private Image cropMapImage(Image image) throws DocumentException {
float width = image.getScaledWidth();
float height = image.getScaledHeight();
float footerReductionPercentage = GOOGLE_MAPS_FOOTER_HEIGHT / height;
int widthReduction = (int) (width * footerReductionPercentage);
CropRectangle cropRectangle = new CropRectangle(0, widthReduction, 0, GOOGLE_MAPS_FOOTER_HEIGHT);
return ImageUtils.cropImageToRectangle(pdfWriter, image, cropRectangle);
}