本文整理汇总了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;
}
示例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: 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);
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}