本文整理匯總了Java中com.lowagie.text.Image.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.getInstance方法的具體用法?Java Image.getInstance怎麽用?Java Image.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertWriteToPdf
import com.lowagie.text.Image; //導入方法依賴的package包/類
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
try {
//Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
Image img = Image.getInstance(bufeBufferedImage, null);
Document document = new Document(img);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
//--
document.open();
img.setAbsolutePosition(0, 0);
//--
document.add(img);
//--
document.close();
} catch (DocumentException | IOException e) {
System.out.println("Intern Log : " + e.getMessage());
}
}
示例2: printImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
/** Print a java image */
private void printImage(java.awt.Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws BadElementException, IOException, DocumentException {
if(image!=null) {
// Convert to an iText Image
Image img = Image.getInstance(image, null);
printImage(img,cb,x1,y1,x2,y2,alignment,fitMethod,rotate);
}
}
示例3: establecerFondo
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Establece una imagen de fondo para todas las paginas
*
* @param nPagina Indica el n�mero de p�gina donde se inertar� la imagen de fondo
* @param a_pathImagen Indica el fichero imagen a insertar (Path absoluto)
* @param a_posX Indica la posici�n X absoluta dentro del PDF donde se colocar� la imagen
* @param a_pathImagen Indica la posici�n Y absoluta dentro del PDF donde se colocar� la imagen
*/
public void establecerFondo (String a_pathImagen, float a_posX, float a_posY) throws Exception
{
int n = pdfr.getNumberOfPages();
Image imagen = Image.getInstance(a_pathImagen);
imagen.setAbsolutePosition(a_posX, a_posY);
imagen.setTransparency(new int[] {255, 255,255, 255, 255, 255});
for (int i=1;i<=n;i++){
pdfs.getUnderContent(i).addImage(imagen);
}
}
示例4: createImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
/** Gets an <CODE>Image</CODE> with the barcode. A successful call to the method <CODE>generate()</CODE>
* before calling this method is required.
* @return the barcode <CODE>Image</CODE>
* @throws BadElementException on error
*/
public Image createImage() throws BadElementException {
if (image == null)
return null;
byte g4[] = CCITTG4Encoder.compress(image, width + 2 * ws, height + 2 * ws);
return Image.getInstance(width + 2 * ws, height + 2 * ws, false, Image.CCITTG4, 0, g4, null);
}
示例5: addImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Adds an image to this Cell.
*
* @param i the image to add
* @param left the left border
* @param right the right border
* @param extraHeight extra height to add above image
* @param alignment horizontal alignment (constant from Element class)
* @return the height of the image
*/
private float addImage(Image i, float left, float right, float extraHeight, int alignment) {
Image image = Image.getInstance(i);
if (image.getScaledWidth() > right - left) {
image.scaleToFit(right - left, Float.MAX_VALUE);
}
flushCurrentLine();
if (line == null) {
line = new PdfLine(left, right, alignment, leading);
}
PdfLine imageLine = line;
// left and right in chunk is relative to the start of the line
right = right - left;
left = 0f;
if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
left = right - image.getScaledWidth();
} else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
left = left + ((right - left - image.getScaledWidth()) / 2f);
}
Chunk imageChunk = new Chunk(image, left, 0);
imageLine.add(new PdfChunk(imageChunk, null));
addLine(imageLine);
return imageLine.height();
}
示例6: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* General example using cell events.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
// step3
document.open();
// step4
CellEventsTest event = new CellEventsTest();
Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
im.setRotationDegrees(30);
PdfPTable table = new PdfPTable(4);
table.addCell("text 1");
PdfPCell cell = new PdfPCell(im, true);
cell.setCellEvent(event);
table.addCell(cell);
table.addCell("text 3");
im.setRotationDegrees(0);
table.addCell(im);
table.setTotalWidth(300);
PdfContentByte cb = writer.getDirectContent();
table.writeSelectedRows(0, -1, 50, 600, cb);
table.setHeaderRows(3);
document.add(table);
// step5
document.close();
}
示例7: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Add an image using different transformation matrices.
*/
@Test
public void main() throws Exception {
Document.compress = false;
// step 1: creation of a document-object
Document document = new Document(PageSize.A4);
try {
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "transformimage.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
cb.addImage(img, 271, -50, -30, 550, 100, 100);
cb.sanityCheck();
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例8: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* General Images example
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Images.pdf"));
// step 3: we open the document
document.open();
// step 4:
document.add(new Paragraph("A picture of my dog: otsoe.jpg"));
Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
document.add(jpg);
document.add(new Paragraph("getacro.gif"));
Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "getacro.gif");
document.add(gif);
document.add(new Paragraph("pngnow.png"));
Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
document.add(png);
document.add(new Paragraph("iText.bmp"));
Image bmp = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.bmp");
document.add(bmp);
document.add(new Paragraph("iText.wmf"));
Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
document.add(wmf);
document.add(new Paragraph("iText.tif"));
Image tiff = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.tif");
document.add(tiff);
// step 5: we close the document
document.close();
}
示例9: addBarcode
import com.lowagie.text.Image; //導入方法依賴的package包/類
public void addBarcode(String barcode, int x, int y) throws ParserException {
try {
Barcode128 code128 = new Barcode128();
code128.setCode(barcode);
PdfContentByte cb = stamp.getOverContent(1);
Image image128 = Image.getInstance(code128.createImageWithBarcode(cb, null, null));
cb.addImage(image128, image128.width(), 0, 0, image128.height(), x, y);
cb.moveTo(0, 0);
} catch (DocumentException e) {
throw new ParserException("Could not add barcode", e);
}
}
示例10: establecerImagen
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Establece una imagen en una posici�n indic�ndole un porcentaje de ampliaci�n/reducci�n
*
* @param nPagina Indica el n�mero de p�gina donde se inertar� la imagen
* @param a_Imagen Indica el byte[] de la imagen a insertar
* @param a_posX Indica la posici�n X absoluta dentro del PDF donde se colocar� la imagen
* @param a_posY Indica la posici�n Y absoluta dentro del PDF donde se colocar� la imagen
*/
public void establecerImagen (int nPagina, byte[] a_Imagen, float a_posX, float a_posY, float af_porcentaje) throws Exception
{
Image imagen = Image.getInstance(a_Imagen);
imagen.scalePercent(af_porcentaje);
imagen.setAbsolutePosition(a_posX, a_posY);
imagen.setTransparency(new int[] {255, 255,255, 255, 255, 255});
pdfs.getOverContent(nPagina).addImage(imagen);
}
示例11: getImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Gets an <CODE>Image</CODE> with the barcode.
*
* @return the barcode <CODE>Image</CODE>
* @throws BadElementException on error
*/
public Image getImage() throws BadElementException {
byte[] b = getBitMatrix();
byte g4[] = CCITTG4Encoder.compress(b, bm.getWidth(), bm.getHeight());
return Image.getInstance(bm.getWidth(), bm.getHeight(), false, Image.CCITTG4, Image.CCITT_BLACKIS1, g4, null);
}
示例12: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Generates 2 documents: one that respects the order of Images added,
* another that has the default behaviour: only show the images if they fit
* on the page, if they don't fit, wait until the next page.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("notInSequence.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("inSequence.pdf"));
writer.setStrictImageSequence(true);
// step 3: we open the document
document.open();
// step 4:
document.add(new Paragraph("1st image"));
Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
document.add(jpg);
document.add(new Paragraph("2nd image"));
Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "getacro.gif");
document.add(gif);
document.add(new Paragraph("3rd image"));
document.add(jpg);
document.add(new Paragraph("4th image"));
document.add(gif);
document.add(new Paragraph("5th image"));
document.add(jpg);
document.add(new Paragraph("6th image"));
document.add(gif);
document.add(new Paragraph("7th image"));
document.add(jpg);
// step 5: we close the document
document.close();
}
示例13: addTextVertical
import com.lowagie.text.Image; //導入方法依賴的package包/類
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception {
if (text==null) return;
if (text.indexOf("<span")>=0)
text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
Font font = PdfFont.getFont(bold);
BaseFont bf = font.getBaseFont();
float width = bf.getWidthPoint(text, font.getSize());
PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
template.beginText();
template.setColorFill(Color.BLACK);
template.setFontAndSize(bf, font.getSize());
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(font.getSize() + 2);
//make an Image object from the template
Image img = Image.getInstance(template);
img.setRotationDegrees(270);
//embed the image in a Chunk
Chunk ck = new Chunk(img, 0, 0);
if (cell.getPhrase()==null) {
cell.setPhrase(new Paragraph(ck));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
} else {
cell.getPhrase().add(ck);
}
}
示例14: addImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
private float addImage(PdfPCell cell, String name) {
try {
java.awt.Image awtImage = (java.awt.Image)iImages.get(name);
if (awtImage==null) return 0;
Image img = Image.getInstance(awtImage, Color.WHITE);
Chunk ck = new Chunk(img, 0, 0);
if (cell.getPhrase()==null) {
cell.setPhrase(new Paragraph(ck));
cell.setVerticalAlignment(Element.ALIGN_TOP);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
} else {
cell.getPhrase().add(ck);
}
return awtImage.getWidth(null);
} catch (Exception e) {
return 0;
}
}
示例15: A
import com.lowagie.text.Image; //導入方法依賴的package包/類
public A(java.awt.Image image) {
try {
iImage = Image.getInstance(image, Color.WHITE);
} catch (Exception e) {}
}