當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。