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


Java Image.getInstance方法代碼示例

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


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

示例1: generatePage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
@Override
public PdfPTable generatePage() throws Exception {
    Image image = Image.getInstance(imageFile.toURL());
    float heightToWidthRatio = (210f / 297f);
    Image imageCropped = ImageUtils.cropImageToMeetRatio(pdfWriter, image, heightToWidthRatio);

    PdfPCell cell = new PdfPCell(imageCropped, true);
    cell.setBorder(0);
    cell.setPadding(COVER_MARGIN);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setExtraParagraphSpace(0);
    cell.setRightIndent(0);

    PdfPTable table = new PdfPTable(1);
    ;
    table.setWidthPercentage(100f);
    table.setWidths(new int[]{1});
    table.setExtendLastRow(true);
    table.addCell(cell);

    return table;
}
 
開發者ID:lenrok258,項目名稱:MountainQuest-PL,代碼行數:24,代碼來源:CoverPageGenerator.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: putSignature

import com.itextpdf.text.Image; //導入方法依賴的package包/類
private void putSignature(PdfPTable table, Context context) throws Exception {
	String uploadOid = (String)context.get("uploadSignatureOid");
	if ( StringUtils.isBlank(uploadOid) ) {
		return;
	}
	byte[] imageBytes = UploadSupportUtils.getDataBytes( uploadOid );
	if ( null == imageBytes ) {
		return;
	}
	Image signatureImgObj = Image.getInstance( imageBytes );
	signatureImgObj.setWidthPercentage(40f);
	PdfPCell cell = new PdfPCell();
	cell.setBorder( Rectangle.NO_BORDER );
	cell.addElement(signatureImgObj);
	table.addCell(cell);		
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:17,代碼來源:KpiReportPdfCommand.java

示例4: createPdf

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

		Document document = new Document(PageSize.LETTER);
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

		// TODO: force iText to respect the order in which content is added
		writer.setStrictImageSequence(true);

		document.open();

		// step 4 - add content into document
		String[] imageNames = { "35_Cal_Crutchlow.jpg", "38_Bradley_Smith.jpg", "46_Valentino_Rossi.jpg",
				"99_Jorge_Lorenzo.jpg" };
		for (int i = 0; i < 4; i++) {

			Image image = Image.getInstance("resources/img/" + imageNames[i]);

			// TODO: scale image
			image.scaleToFit(500, 500); // scale size

			document.add(image);
			document.add(new Paragraph(imageNames[i]));
		}

		document.close();
	}
 
開發者ID:kohmiho,項目名稱:iTextTutorial,代碼行數:27,代碼來源:T05_Image.java

示例5: addImage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
/**
 * adds an image to the document.
 * 
 * @param doc
 * @param iji
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws IOException
 * @throws DocumentException
 */
public Document addImage(Document doc, ImageJobDescription iji)
		throws InterruptedException, ExecutionException, IOException,
		DocumentException {
	// create image worker
	ImageWorker job = new ImageWorker(dlConfig, iji);
	// submit
	Future<DocuImage> jobTicket = imageJobCenter.submit(job);
	// wait for result
	DocuImage img = jobTicket.get();
	// scale the image
	Image pdfimg = Image.getInstance(img.getAwtImage(), null);
	float docW = PageSize.A4.getWidth() - 2 * PageSize.A4.getBorder();
	float docH = PageSize.A4.getHeight() - 2 * PageSize.A4.getBorder();
	// fit the image to the page
	pdfimg.scaleToFit(docW, docH);
	// add to PDF
	doc.add(pdfimg);
	return doc;
}
 
開發者ID:robcast,項目名稱:digilib,代碼行數:31,代碼來源:PDFStreamWorker.java

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

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

示例8: getImageByFile

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public ImageInstance getImageByFile( PdfContentByte cb , File file ) throws IOException, BadElementException{
	Image image = null;
	ImageInstance instance = null;
	if( file.getName().toLowerCase().endsWith( ".pdf")){	
		PdfReader reader = new PdfReader( file.getAbsolutePath() );
		PdfImportedPage p = cb.getPdfWriter().getImportedPage(reader, 1);
		image = Image.getInstance(p);
		instance = new ImageInstance(image, reader);
	}else{
		image = Image.getInstance( file.getAbsolutePath() );
		instance = new ImageInstance(image, null);
	}
	
	instances.add(instance);
	

	return instance;
}
 
開發者ID:Billes,項目名稱:pdf-renderer,代碼行數:19,代碼來源:ImageFactory.java

示例9: getPDF

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public Document getPDF() throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(FILE + problem.getPid() + ".pdf"));
    Image image = Image.getInstance(this.logo);
    document.open();
    document.add(image);
    document.addCreationDate();
    document.add(new Paragraph("Title: "+problem.getTitle()));
    document.add(new Paragraph("Code: "+problem.getPid()));
    document.add(new Paragraph(" "));
    document.add(addParagraph("Description",problem.getDescription(), true));
    document.add(addParagraph("Input",problem.getInput(), true));
    document.add(addParagraph("Output",problem.getOutput(), true));
    document.add(addParagraph("Input Example",problem.getInputex().replaceAll("<br/>", ""), true));
    document.add(addParagraph("Output Example",problem.getOutputex(), true));
    document.add(new Paragraph("Time(ms): "+problem.getTime()));
    document.add(new Paragraph("Memory(kb): "+problem.getMemory()));
    document.add(new Paragraph("Source(kb): "+problem.getFontsize()));
    document.addTitle("Challenger Online Judge");
    document.addAuthor("Chjudge");
    document.close();
    return document;
}
 
開發者ID:dovier,項目名稱:coj-web,代碼行數:24,代碼來源:PDFExportProblem.java

示例10: IMGToPDF

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public  void IMGToPDF(String RESOURCES, String result) throws DocumentException, FileNotFoundException, BadElementException, IOException{
     
     ProgressBar progrsbar=new ProgressBar();
   
     progrsbar.showProgress();
     Document document = new Document();
     // step 2
     PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result));
     // step 3
     document.open();
     // step 4
     Image img;
         img = Image.getInstance(RESOURCES);
         Image.getInstance(img);
         document.add(img);
progrsbar.updatePercent(100);
 document.close();    
 }
 
開發者ID:DJVUpp,項目名稱:Desktop,代碼行數:19,代碼來源:ImagesToPDF.java

示例11: createSimpleImagePdf

import com.itextpdf.text.Image; //導入方法依賴的package包/類
static byte[] createSimpleImagePdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    BufferedImage bim = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bim.createGraphics();
    g2d.setColor(Color.BLUE);
    g2d.fillRect(0, 0, 500, 500);
    g2d.dispose();

    Image image = Image.getInstance(bim, null);
    document.add(image);

    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:22,代碼來源:SimpleRedactionTest.java

示例12: createRotatedImagePdf

import com.itextpdf.text.Image; //導入方法依賴的package包/類
static byte[] createRotatedImagePdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();

    PdfContentByte directContent = writer.getDirectContent();

    BufferedImage bim = new BufferedImage(1000, 250, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bim.createGraphics();
    g2d.setColor(Color.BLUE);
    g2d.fillRect(0, 0, 500, 500);
    g2d.dispose();

    Image image = Image.getInstance(bim, null);
    directContent.addImage(image, 0, 500, -500, 0, 550, 50);

    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:SimpleRedactionTest.java

示例13: createMultiUseImagePdf

import com.itextpdf.text.Image; //導入方法依賴的package包/類
static byte[] createMultiUseImagePdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    BufferedImage bim = new BufferedImage(500, 250, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bim.createGraphics();
    g2d.setColor(Color.BLUE);
    g2d.fillRect(0, 0, 250, 250);
    g2d.dispose();

    Image image = Image.getInstance(bim, null);
    document.add(image);
    document.add(image);
    document.add(image);

    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:SimpleRedactionTest.java

示例14: addStructureTreeToDocument

import com.itextpdf.text.Image; //導入方法依賴的package包/類
public void addStructureTreeToDocument(String inputFile, String outputFile, TEIDocument teiDocument) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(inputFile);
    Document document = new Document(reader.getPageSize(1), 0f, 0f, 0f, 0f);
    document.setRole(PdfName.ARTIFACT);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
    writer.setTagged();
    writer.setUserProperties(true);
    document.open();
    int n = reader.getNumberOfPages();
    for (int i = 1; i <= n; i++) {
        PdfImportedPage importedPage = writer.getImportedPage(reader, i);
        importedPage.setRole(PdfName.ARTIFACT);
        Image image = Image.getInstance(importedPage);
        image.setRole(PdfName.ARTIFACT);
        document.add(image);
    }

    final PdfStructureTreeRoot root = writer.getStructureTreeRoot();
    List<TEIElement> teiElementList = teiDocument.getBody();
    for (TEIElement teiElement : teiElementList) {
        teiElement.toPdfStructureElement(root);
    }
    document.close();
    reader.close();
    writer.close();
}
 
開發者ID:mrniket,項目名稱:pdftagger,代碼行數:27,代碼來源:StructureTreeInserter.java

示例15: onEndPage

import com.itextpdf.text.Image; //導入方法依賴的package包/類
@Override
   public void onEndPage(PdfWriter writer, Document document) {
       try {
       	footer = buildPdfTable(PRINT_PAGE_FOOTER);   
       	if (footer != null) {
       		printPageFooterBand();
       		Rectangle page = document.getPageSize();        		            		            		
       		footer.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());            		
       		footer.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent());
       		
       		String image = bean.getReportLayout().getBackgroundImage();
if (image != null) {						
	byte[] imageBytes = getImage(image);
	Image pdfImage = Image.getInstance(imageBytes);
	pdfImage.setAbsolutePosition(0, 0);
	writer.getDirectContentUnder().addImage(pdfImage);
}
       	}
       } catch (Exception e) {
           throw new ExceptionConverter(e);
       } finally {
       	pageNo = writer.getPageNumber();
       }
   }
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:25,代碼來源:PdfExporter.java


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