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


Java Image.scalePercent方法代码示例

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


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

示例1: writeSimplePdf

import com.itextpdf.text.Image; //导入方法依赖的package包/类
public static void writeSimplePdf() throws Exception{
			//1.新建document对象
			//第一个参数是页面大小。接下来的参数分别是左、右、上和下页边距。
			Document document = new Document(PageSize.A4, 50, 50, 50, 50);
			//2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
			//创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
			PdfWriter writer = PdfWriter.getInstance(document, 	new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
			//3.打开文档
			document.open();		
			//4.向文档中添加内容
			//通过 com.lowagie.text.Paragraph 来添加文本。可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落
			BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
			
			document.add(new Paragraph("sdfsdfsd全是中文显示了没.fsdfsfs",fontChinese));
			document.add(new Paragraph("Some more text on the 	first page with different color and font type.",
					FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
			Paragraph pragraph=new Paragraph("你这里有中亠好", fontChinese);
			document.add(pragraph);
			
			//图像支持格式 GIF, Jpeg, PNG, wmf
			Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
			gif.setBorder(5);
			gif.scaleAbsolute(30,30);
			gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
			document.add(gif);
			Paragraph pragraph11=new Paragraph("你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好", fontChinese);
			document.add(pragraph11);
			
			Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
//			gif15.setBorder(50);
			gif15.setBorder(Image.BOX);
			gif15.setBorderColor(BaseColor.RED);
//			gif15.setBorderColorBottom(borderColorBottom)
			gif15.setBorderWidth(1);
			gif15.scalePercent(50);
			document.add(gif15);
			//5.关闭文档
			document.close();
		}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:41,代码来源:ItextpdfTest.java

示例2: getPhotoCell

import com.itextpdf.text.Image; //导入方法依赖的package包/类
private static PdfPCell getPhotoCell(BufferedImage bufferedImage, float scalePercent, boolean isHorizontallyCentered) throws BadElementException, IOException {
	Image jpeg = Image.getInstance(bufferedImage, null);
	jpeg.scalePercent(scalePercent);
	jpeg.setAlignment(Image.MIDDLE);
	PdfPCell photoCell = new PdfPCell(jpeg);
	photoCell.setBorder(0);
	if (isHorizontallyCentered) {
		photoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	} else {
		photoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	}

	photoCell.setVerticalAlignment(Element.ALIGN_TOP);
	int height = (int) Math.ceil(bufferedImage.getHeight() * scalePercent / 100);
	photoCell.setFixedHeight(height);
	return photoCell;
}
 
开发者ID:NimbleGen,项目名称:bioinformatics,代码行数:18,代码来源:PdfReportUtil.java

示例3: 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

示例4: stampLayer

import com.itextpdf.text.Image; //导入方法依赖的package包/类
public static byte[] stampLayer(InputStream _pdfFile, Image iImage, int x, int y, String layername, boolean readLayers) throws IOException, DocumentException
{
    PdfReader reader = new PdfReader(_pdfFile);

    try (   ByteArrayOutputStream ms = new ByteArrayOutputStream()  )
    {
        PdfStamper stamper = new PdfStamper(reader, ms);
        //Don't delete otherwise the stamper flattens the layers
        if (readLayers)
            stamper.getPdfLayers();

        PdfLayer logoLayer = new PdfLayer(layername, stamper.getWriter());
        PdfContentByte cb = stamper.getUnderContent(1);
        cb.beginLayer(logoLayer);

        //300dpi
        iImage.scalePercent(24f);
        iImage.setAbsolutePosition(x, y);
        cb.addImage(iImage);

        cb.endLayer();
        stamper.close();

        return (ms.toByteArray());
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:27,代码来源:StampInLayer.java

示例5: addLogo

import com.itextpdf.text.Image; //导入方法依赖的package包/类
public void addLogo(PdfContentByte cb, String imagePath, float xPos, float yPos) throws MalformedURLException, IOException, DocumentException {
    URL imageUrl = getClass().getResource(imagePath + "/IPAT_logo_Relaunch2016_RZ_RGB.jpg");
    final Image logoImage = Image.getInstance(imageUrl);
    logoImage.setAbsolutePosition(xPos, yPos);
    logoImage.scalePercent(3f, 3f);
    cb.addImage(logoImage);
}
 
开发者ID:Dica-Developer,项目名称:weplantaforest,代码行数:8,代码来源:PdfHelper.java

示例6: scaleToFit

import com.itextpdf.text.Image; //导入方法依赖的package包/类
private static void scaleToFit(Document document, Image image) {
    float scale = ((document.getPageSize().getWidth() - document.leftMargin()
            - document.rightMargin()) / image.getWidth()) * 100;
    image.scalePercent(scale);
}
 
开发者ID:sewerk,项目名称:Bill-Calculator,代码行数:6,代码来源:BillExporter.java


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