本文整理汇总了Java中com.itextpdf.text.Image类的典型用法代码示例。如果您正苦于以下问题:Java Image类的具体用法?Java Image怎么用?Java Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Image类属于com.itextpdf.text包,在下文中一共展示了Image类的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;
}
示例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;
}
示例3: build
import com.itextpdf.text.Image; //导入依赖的package包/类
/**
* Update NDA file with visitor name and visitor signature.
*
* @param destFile
* @param signatureImage signature file
* @param visitorName
* @return File
*/
public static File build(Path destFile, File signatureImage, String visitorName) {
try {
PdfReader pdfReader = new PdfReader(ndaUrl);
PdfStamper pdfStamper = new PdfStamper(pdfReader,
new FileOutputStream(destFile.toString()));
Image image = createNDAImage(signatureImage, 0, 0);
PdfContentByte over = pdfStamper.getOverContent(5);
over.addImage(image);
PdfContentByte pdfContentByte = pdfStamper.getOverContent(5);
pdfContentByte.beginText();
pdfContentByte.setFontAndSize(BaseFont.createFont
(BaseFont.HELVETICA,
BaseFont.CP1257,
BaseFont.EMBEDDED
)
, 10);
pdfContentByte.setTextMatrix(112, 428);
pdfContentByte.showText(visitorName);
pdfContentByte.setTextMatrix(89, 406);
pdfContentByte.showText(new SimpleDateFormat("E, dd MMM yyyy").format(new Date()));
pdfContentByte.endText();
pdfStamper.close();
return destFile.toFile();
} catch (IOException | DocumentException | NumberFormatException e) {
logger.error("Exception while generating NDA file. ",e);
return null;
}
}
示例4: 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);
}
示例5: generate128
import com.itextpdf.text.Image; //导入依赖的package包/类
private static Image generate128(PdfContentByte cb, String sku){
Barcode128 code128 = new Barcode128();
code128.setCodeType(Barcode128.CODE_A);
code128.setGuardBars(true);
code128.setCode(sku);
code128.setSize(7);
code128.setBaseline(6f);
code128.setBarHeight(27f);
code128.setX(.70f);
return code128.createImageWithBarcode(cb, null, null);
}
示例6: 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();
}
示例7: 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;
}
示例8: 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();
}
示例9: 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);
}
}
示例10: 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;
}
示例11: main
import com.itextpdf.text.Image; //导入依赖的package包/类
public static void main(String[] args)
{
Image img = getImageFromUrl("http://oimagea6.ydstatic.com/image?url=http://en.wikipedia.org/wiki/File:WhiteCat.jpg&product=PICDICT_EDIT");
System.out.println("img.width=" + img.getWidth() + " img.hight=" + img.getHeight());
System.out.println(
getAutoZoomHeightByWidth("http://oimagea6.ydstatic.com/image?url=http://en.wikipedia.org/wiki/File:WhiteCat.jpg&product=PICDICT_EDIT", 120));
System.out.println(
getAutoZoomHeightByWidth("http://oimagea6.ydstatic.com/image?url=http://en.wikipedia.org/wiki/File:WhiteCat.jpg&product=PICDICT_EDIT", 200));
System.out.println(
getAutoZoomWidthByHeight("http://oimagea6.ydstatic.com/image?url=http://en.wikipedia.org/wiki/File:WhiteCat.jpg&product=PICDICT_EDIT", 80));
System.out.println(
getAutoZoonImageHtmlByWidth("http://oimagea6.ydstatic.com/image?url=http://en.wikipedia.org/wiki/File:WhiteCat.jpg&product=PICDICT_EDIT", 120));
System.out.println(getAutoZoonImageHtmlByWidth(
"http://oimageb1.ydstatic.com/image?url=http://mydrupalsite.co.uk/JJLJ/sites/default/files/images/computer_pig_logo-cartoon-pig.jpg&product=PICDICT_EDIT",
120));
}
示例12: 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;
}
示例13: 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;
}
示例14: buildComponent
import com.itextpdf.text.Image; //导入依赖的package包/类
@Override
public void buildComponent(SerialisationContext pSerialisationContext, PDFSerialiser pSerialiser, EvaluatedHtmlPresentationNode pEvalNode) {
Map<String, StringAttributeResult> lNodeAttributes = pEvalNode.getAttributeMap(false);
String lSourceURI = Optional.ofNullable(lNodeAttributes.get(IMAGE_SOURCE_ATTRIBUTE))
.map(StringAttributeResult::getString)
.flatMap(Optional::ofNullable)
.orElseThrow(() -> new ExInternal("Could not find '" + IMAGE_SOURCE_ATTRIBUTE + "' attribute on HTML image"));
Image lImage = getImage(pSerialisationContext, lSourceURI);
// Set the image dimensions if specified in the node attributes, using the current element attributes if dimensions
// are specified in relative units e.g. ems
setImageDimensions(lImage, lNodeAttributes, pSerialiser.getElementAttributes());
// Add the image within a chunk so it appears inline and changes the line leading to fit the image
pSerialiser.add(new Chunk(lImage, IMAGE_X_OFFSET, IMAGE_Y_OFFSET, true));
}
示例15: addRotatedImage
import com.itextpdf.text.Image; //导入依赖的package包/类
void addRotatedImage(PdfContentByte contentByte, Image image, float x, float y, float width, float height, float rotation) throws DocumentException
{
// Draw image at x,y without rotation
contentByte.addImage(image, width, 0, 0, height, x, y);
// Draw image as if the previous image was rotated around its center
// Image starts out being 1x1 with origin in lower left
// Move origin to center of image
AffineTransform A = AffineTransform.getTranslateInstance(-0.5, -0.5);
// Stretch it to its dimensions
AffineTransform B = AffineTransform.getScaleInstance(width, height);
// Rotate it
AffineTransform C = AffineTransform.getRotateInstance(rotation);
// Move it to have the same center as above
AffineTransform D = AffineTransform.getTranslateInstance(x + width/2, y + height/2);
// Concatenate
AffineTransform M = (AffineTransform) A.clone();
M.preConcatenate(B);
M.preConcatenate(C);
M.preConcatenate(D);
//Draw
contentByte.addImage(image, M);
}