当前位置: 首页>>代码示例>>Java>>正文


Java Image.getHeight方法代码示例

本文整理汇总了Java中com.itextpdf.text.Image.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getHeight方法的具体用法?Java Image.getHeight怎么用?Java Image.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.itextpdf.text.Image的用法示例。


在下文中一共展示了Image.getHeight方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reshapeImage

import com.itextpdf.text.Image; //导入方法依赖的package包/类
private float reshapeImage(Image image, float imagewidthmax, float imageheightmax){

		float imageheight = image.getHeight();
		float imagewidth = image.getWidth();
		float scaler;
		if((imageheightmax>imageheight)&&(imageheightmax>imagewidth)) return 1;
		if(imageheight < imagewidth){
			
			scaler = imagewidthmax/image.getWidth()*100;	
			image.scalePercent(scaler);
		}
		else {
			scaler = imageheightmax/image.getHeight()*100;
			image.scalePercent(scaler);
		}
		return scaler/100;
	}
 
开发者ID:AlexandrePechereau,项目名称:FabDocMaker,代码行数:18,代码来源:CreatePDF_3DPrinter.java

示例2: 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;
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:41,代码来源:AbstractPage.java

示例3: getAutoZoonImageHtmlByMaxDimen

import com.itextpdf.text.Image; //导入方法依赖的package包/类
public static String getAutoZoonImageHtmlByMaxDimen(String imgUrl, int imageMaxDimen, int border)
{
    String ret = null;
    Image img = getImageFromUrl(imgUrl);
    if (img == null)
    {
        return null;
    }
    else
    {
        float w = img.getWidth();
        float h = img.getHeight();
        if (w >= h)
        {
            //宽度较大,以宽度作为基准来自动缩放
            ret = String.format("<p align=\"left\"><img width=\"%s\" height=\"%s\" border=\"%s\" src=\"%s\"></p>",
                imageMaxDimen,
                (int)(h * imageMaxDimen / w),
                border,
                imgUrl);
        }
        else
        {
            //高度较大
            ret = String.format("<p align=\"left\"><img width=\"%s\" height=\"%s\" border=\"%s\" src=\"%s\"></p>",
                (int)(w * imageMaxDimen / h),
                imageMaxDimen,
                border,
                imgUrl);
        }
    }
    return ret;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:34,代码来源:ImageUtil.java

示例4: getAutoZoomWidthByHeight

import com.itextpdf.text.Image; //导入方法依赖的package包/类
/**
 * 获取自动缩放后的宽度
 * @author Administrator
 * @param url
 * @param height
 * @return
 */
public static int getAutoZoomWidthByHeight(String url, int height)
{
    Image image = getImageFromUrl(url);
    if (image == null)
    {
        return 0;
    }
    else
    {
        float w = image.getWidth();
        float h = image.getHeight();
        return (int)(w * height / h);
    }
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:22,代码来源:ImageUtil.java

示例5: getAutoZoomHeightByWidth

import com.itextpdf.text.Image; //导入方法依赖的package包/类
/**
 * 获取自动缩放后的高度
 * @author Administrator
 * @param url
 * @param width
 * @return
 */
public static int getAutoZoomHeightByWidth(String url, int width)
{
    Image image = getImageFromUrl(url);
    if (image == null)
    {
        return 0;
    }
    else
    {
        float w = image.getWidth();
        float h = image.getHeight();
        return (int)(h * width / w);
    }
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:22,代码来源:ImageUtil.java

示例6: addImageToPdf

import com.itextpdf.text.Image; //导入方法依赖的package包/类
/**
 * The <code>addImageToPdf</code> method is used to add image to pdf and make it searchable by adding image text in invisible mode
 * w.r.t parameter 'isPdfSearchable' passed.
 * 
 * @param pdfWriter {@link PdfWriter} writer of pdf in which image has to be added
 * @param htmlUrl {@link HocrPage} corresponding html file for fetching text and coordinates
 * @param imageUrl {@link String} url of image to be added in pdf
 * @param isPdfSearchable true for searchable pdf else otherwise
 * @param widthOfLine
 */
private void addImageToPdf(PdfWriter pdfWriter, HocrPage hocrPage, String imageUrl, boolean isPdfSearchable, final int widthOfLine) {
	if (null != pdfWriter && null != imageUrl && imageUrl.length() > 0) {
		try {
			LOGGER.info("Adding image" + imageUrl + " to pdf using iText");
			Image pageImage = Image.getInstance(imageUrl);
			float dotsPerPointX = pageImage.getDpiX() / PDF_RESOLUTION;
			float dotsPerPointY = pageImage.getDpiY() / PDF_RESOLUTION;
			PdfContentByte pdfContentByte = pdfWriter.getDirectContent();

			pageImage.scaleToFit(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY);

			pageImage.setAbsolutePosition(0, 0);

			// Add image to pdf
			pdfWriter.getDirectContentUnder().addImage(pageImage);
			pdfWriter.getDirectContentUnder().add(pdfContentByte);

			// If pdf is to be made searchable
			if (isPdfSearchable) {
				LOGGER.info("Adding invisible text for image: " + imageUrl);
				float pageImagePixelHeight = pageImage.getHeight();
				Font defaultFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD, CMYKColor.BLACK);

				// Fetch text and coordinates for image to be added
				Map<String, int[]> textCoordinatesMap = getTextWithCoordinatesMap(hocrPage, widthOfLine);
				Set<String> ketSet = textCoordinatesMap.keySet();

				// Add text at specific location
				for (String key : ketSet) {
					int[] coordinates = textCoordinatesMap.get(key);
					float bboxWidthPt = (coordinates[2] - coordinates[0]) / dotsPerPointX;
					float bboxHeightPt = (coordinates[3] - coordinates[1]) / dotsPerPointY;
					pdfContentByte.beginText();

					// To make text added as invisible
					pdfContentByte.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
					pdfContentByte.setLineWidth(Math.round(bboxWidthPt));

					// Ceil is used so that minimum font of any text is 1
					// For exception of unbalanced beginText() and endText()
					if (bboxHeightPt > 0.0) {
						pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), (float) Math.ceil(bboxHeightPt));
					} else {
						pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), 1);
					}
					float xCoordinate = (float) (coordinates[0] / dotsPerPointX);
					float yCoordinate = (float) ((pageImagePixelHeight - coordinates[3]) / dotsPerPointY);
					pdfContentByte.moveText(xCoordinate, yCoordinate);
					pdfContentByte.showText(key);
					pdfContentByte.endText();
				}
			}
			pdfContentByte.closePath();
		} catch (BadElementException badElementException) {
			LOGGER
					.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: "
							+ badElementException.toString());
		} catch (DocumentException documentException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + documentException.toString());
		} catch (MalformedURLException malformedURLException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: "
					+ malformedURLException.toString());
		} catch (IOException ioException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + ioException.toString());
		}
	}
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:78,代码来源:MultiPageExecutor.java

示例7: getCenterY

import com.itextpdf.text.Image; //导入方法依赖的package包/类
/**
 * Gets the Y value for centering the watermark image
 * 
 * @param r
 * @param img
 * @return
 */
protected float getCenterY(Rectangle r, Image img)
{
    float y = 0;
    float pdfheight = r.getHeight();
    float imgheight = img.getHeight();

    y = (pdfheight - imgheight) / 2;

    return y;
}
 
开发者ID:teqnology,项目名称:alfresco-pdf-toolkit,代码行数:18,代码来源:BasePDFStampActionExecuter.java

示例8: addHeaderImage

import com.itextpdf.text.Image; //导入方法依赖的package包/类
private void addHeaderImage() {
	try {
		URL imageURL = getClass().getResource("/images/logo.png");
		Image logo = Image.getInstance(imageURL);
		float x = logo.getWidth();
		float y = logo.getHeight();

		System.out.println("IMAGE HEIGHT: " + y + "IMAGE WIDTH: " + x);
		PDFBuilderForCDA.this.document.add(logo);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:14,代码来源:PDFBuilderForCDA.java

示例9: getCenterY

import com.itextpdf.text.Image; //导入方法依赖的package包/类
/**
 * Gets the Y value for centering the signature stamp
 * 
 * @param r
 * @param img
 * @return
 */
protected float getCenterY(Rectangle r, Image img)
{
    float y = 0;
    float pdfheight = r.getHeight();
    float imgheight = img.getHeight();

    y = (pdfheight - imgheight) / 2;

    return y;
}
 
开发者ID:ntmcminn,项目名称:CounterSign,代码行数:18,代码来源:AbstractSignatureActionExecuter.java


注:本文中的com.itextpdf.text.Image.getHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。