當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.scaleAbsolute方法代碼示例

本文整理匯總了Java中com.itextpdf.text.Image.scaleAbsolute方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.scaleAbsolute方法的具體用法?Java Image.scaleAbsolute怎麽用?Java Image.scaleAbsolute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.itextpdf.text.Image的用法示例。


在下文中一共展示了Image.scaleAbsolute方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: onEndPage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 頁   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("頁",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:35,代碼來源:PdfReportPageNumber.java

示例3: createNDAImage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
/**
 * Create itextPdf image object with visitor signature.
 * 
 * @param file 
 * @param imgHeight
 * @param imgWidth
 * @return com.itextpdf.text.Image
 */
public static Image createNDAImage(File file, int imgHeight, int imgWidth) {
	try {
		Image image = Image.getInstance(file.getAbsolutePath());
		if (imgHeight!=0 && imgWidth!=0) {
			image.scaleAbsolute(imgWidth, imgHeight);
		} else {
			image.scaleAbsolute(230, 140);
		} image.setAbsolutePosition(70, 450);
		return image;
	} catch (BadElementException | IOException e) {
		logger.error("Exception while creating image for NDA file. ",e);
		return null;
	}
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:23,代碼來源:NdaBuilder.java

示例4: getPiccell

import com.itextpdf.text.Image; //導入方法依賴的package包/類
PdfPCell getPiccell(int w, int h)
{
    try
    {
        Image image = Image.getInstance("src/test/resources/mkl/testarea/itext5/content/2x2colored.png");
        image.scaleAbsolute(w, h);
        return new PdfPCell(image);
    }
    catch (BadElementException | IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:14,代碼來源:TableWithSpan.java

示例5: savePDFReport

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public void savePDFReport(String filename) {

	Document document = new Document();
	try
	{
		
		// if you want to save a pdf file using bigbuffer do it here
		PdfWriter.getInstance(document, new FileOutputStream(filename));
		document.open();
		document.add(new Paragraph(para1.get(0)));
		printTableAct.get(0).setWidthPercentage(90);
		printTableAct.get(0).setSpacingBefore(20f);
		printTableAct.get(0).setSpacingAfter(20f);
		document.add(printTableAct.get(0));
		// document.newPage();
		document.add(new Paragraph(para2.get(0)));
		printTableSim.get(0).setWidthPercentage(90);
		printTableSim.get(0).setSpacingBefore(20f);
		printTableSim.get(0).setSpacingAfter(20f);
		document.add(printTableSim.get(0));
		
		// the charts are being saved from an array list to the files
		for (int i = 0; i < chartList.size(); i++)
		{
			try
			{
				
				File f2 = File.createTempFile("chart" + i, ".png");
				ChartUtilities.saveChartAsPNG(f2, chartList.get(i).getChart(), 800, 500);
				Image image = Image.getInstance(f2.getAbsolutePath());
				float fWidth = 0.6f * 800;
				float fHeight = 0.6f * 500;
				image.scaleAbsolute(fWidth, fHeight);
				document.add(image);
				f2.delete();
				
			}
			catch (IOException ex)
			{
				System.err.println(ex.getLocalizedMessage());
			}
		}
	}
	catch (Exception e)
	{
		
	}
	
	document.close();
	
}
 
開發者ID:petebrew,項目名稱:fhaes,代碼行數:52,代碼來源:JSEAStatsFunctions.java

示例6: convertTiff

import com.itextpdf.text.Image; //導入方法依賴的package包/類
private void convertTiff(ByteArrayOutputStream outputStream, ByteArrayInputStream inStream) throws IOException, DocumentException, BadElementException, MalformedURLException 
{
	TIFFDecodeParam param = null;
	ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", inStream, param);	
	System.out.println("Convert TIFF file: Found " + decoder.getNumPages() + " pages");
	
	ArrayList<ByteArrayOutputStream> imagesStream = new ArrayList<ByteArrayOutputStream>();
	
	int pages = decoder.getNumPages();
	for (int i = 0; i < pages; i++) 
	{
		RenderedImage render = decoder.decodeAsRenderedImage(i);
		PlanarImage op = new NullOpImage(render, null, null, OpImage.OP_IO_BOUND);
		BufferedImage imageBuffer = op.getAsBufferedImage();
		
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(imageBuffer, "jpg", os);
		
		imagesStream.add(os);
	}
	
	if (imagesStream.size() > 0)
	{						
		Document document = new Document(PageSize.A4.rotate());
		PdfWriter writer = PdfWriter.getInstance(document, outputStream);
		
		document.open();
		
		Iterator<ByteArrayOutputStream> iterator = imagesStream.iterator();
		while (iterator.hasNext()) 
	    {
			document.newPage();
			Image jpg = Image.getInstance(iterator.next().toByteArray());
			jpg.scaleAbsolute(document.getPageSize().getWidth(), document.getPageSize().getHeight());
			document.add(jpg);
			
		}
		
		document.close();
		writer.flush();
		writer.close();
	}
}
 
開發者ID:IMS-MAXIMS,項目名稱:openMAXIMS,代碼行數:44,代碼來源:ConversionHelper.java

示例7: createImages

import com.itextpdf.text.Image; //導入方法依賴的package包/類
private void createImages(Document document) throws MalformedURLException, IOException, DocumentException{
		ImageManager manager=new ImageManager(context);
		Image frontImage=Image.getInstance(manager.getFilepathFromUrl(frontImageName));
//		Image frontImage=Image.getInstance(front);
		
		frontImage.scaleAbsolute(pageWidth, pageHeight);
		
		document.add(frontImage);
        
		document.newPage();
		
//		Image backImage=Image.getInstance(back);
        
		Image backImage=Image.getInstance(manager.getFilepathFromUrl(backImageName));
//		
//		Log.e("Print", manager.getFilepathFromUrl(backImageName));
		backImage.scaleAbsolute(pageWidth, pageHeight);
		
		document.add(backImage);	

	}
 
開發者ID:Defuera,項目名稱:cards-app,代碼行數:22,代碼來源:PdfConverter.java


注:本文中的com.itextpdf.text.Image.scaleAbsolute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。