当前位置: 首页>>代码示例>>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;未经允许,请勿转载。