本文整理汇总了Java中com.lowagie.text.Image.scalePercent方法的典型用法代码示例。如果您正苦于以下问题:Java Image.scalePercent方法的具体用法?Java Image.scalePercent怎么用?Java Image.scalePercent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.scalePercent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBarCode
import com.lowagie.text.Image; //导入方法依赖的package包/类
private Image generateBarCode()
{
try {
Barcode128 code128 = new Barcode128();
code128.setSize(12f);
code128.setBaseline(12f);
code128.setCode(barcode);
Image img = code128.createImageWithBarcode(writer.getDirectContent(), null, null);
img.scalePercent(50, 50);
//img.setAbsolutePosition(PageSize.A4.width() - img.width() - 10,10);
//document.add(img);
return img;
}catch (Exception ex){
ex.printStackTrace();
return null;
}
}
示例2: establecerBarCode
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* M�todo que permite introducir un c�digo de barras code128 que represente el texto
* que se pasa como par�metro. Se debe indicar la p�gina del PDF donde se debe introducir
* el c�digo (normlamente la p�gina 1) y la posici�n absoluta X e Y dentro de la p�gina.
*/
public void establecerBarCode (int Pagina, String texto, int XPos, int YPos) throws Exception
{
Barcode128 code128 = new Barcode128();
code128.setSize(12f);
code128.setBaseline(12f);
code128.setCode(texto);
Image img = code128.createImageWithBarcode(pdfs.getOverContent(Pagina), null, null);
img.setAbsolutePosition(XPos, YPos);
//Se hace un poco mas peque�o en la escala X para que no ocupe tanto
img.scalePercent(75, 100);
pdfs.getOverContent(Pagina).addImage(img);
}
示例3: printImage
import com.lowagie.text.Image; //导入方法依赖的package包/类
/** Print an iText image */
private void printImage(Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws DocumentException {
if(image!=null) {
float boxWidth = Math.abs(x2-x1)+1;
float boxHeight = Math.abs(y2-y1)+1;
log.debug("Print Image (Size w="+image.getPlainWidth()+",h="+image.getPlainHeight()+") wthin BOX (w="+boxWidth+",h="+boxHeight+") FitMethod = "+fitMethod);
// Clip the image based on the bounding box
if(fitMethod==FIT_METHOD_CLIP) {
if( (boxWidth < image.getPlainWidth()) || (boxHeight < image.getPlainHeight()) ) {
// @TODO - Clip image
log.warn("IMAGE CLIPPING REQUIRED, but not implemented - default to 'SCALE'...");
fitMethod=FIT_METHOD_SCALE;
}
}
// Stretch/shrink both the X/Y to fit the bounding box
if(fitMethod==FIT_METHOD_FILL) {
log.debug("Scale image to fill box");
image.scaleToFit(x2-x1, y2-y1);
}
// Stretch/shrink preserving the aspect ratio to fit the bounding box
if(fitMethod==FIT_METHOD_SCALE) {
float multipler = Math.min(boxWidth / image.getPlainWidth(), boxHeight /image.getPlainHeight());
log.debug("Need to scale image by " + (Math.floor(multipler*10000)/100) + "%");
image.scalePercent(multipler*100);
}
log.debug("Print image at (" + x1 + "," + y1 +")");
image.setAbsolutePosition(x1,y1);
image.setRotationDegrees(rotate);
cb.addImage(image);
//Phrase text = new Phrase(new Chunk(image, 0, 0));
//ColumnText ct = new ColumnText(cb);
//ct.setSimpleColumn(text, x1, y1, x2, y2, 10, alignment);
//ct.go();
}
}
示例4: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Scaling an image.
*/
@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("scaling.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image jpg1 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg1.scaleAbsolute(160, 120);
document.add(new Paragraph("scaleAbsolute(160, 120)"));
document.add(jpg1);
Image jpg2 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg2.scalePercent(50);
document.add(new Paragraph("scalePercent(50)"));
document.add(jpg2);
Image jpg3 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg3.scaleAbsolute(320, 120);
document.add(new Paragraph("scaleAbsolute(320, 120)"));
document.add(jpg3);
Image jpg4 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg4.scalePercent(100, 50);
document.add(new Paragraph("scalePercent(100, 50)"));
document.add(jpg4);
// step 5: we close the document
document.close();
}
示例5: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Example Barcode PDF417.
*/
@Test
public void main() throws Exception {
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "It was the best of times, it was the worst of times, " +
"it was the age of wisdom, it was the age of foolishness, " +
"it was the epoch of belief, it was the epoch of incredulity, " +
"it was the season of Light, it was the season of Darkness, " +
"it was the spring of hope, it was the winter of despair, " +
"we had everything before us, we had nothing before us, " +
"we were all going direct to Heaven, we were all going direct " +
"the other way - in short, the period was so far like the present " +
"period, that some of its noisiest authorities insisted on its " +
"being received, for good or for evil, in the superlative degree " +
"of comparison only.";
pdf417.setText(text);
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "pdf417.pdf"));
document.open();
Image img = pdf417.getImage();
img.scalePercent(50, 50 * pdf417.getYHeight());
document.add(img);
document.close();
}
示例6: establecerBarCodeNP
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* M�todo que permite introducir un c�digo de barras de nube de puntos que represente el texto
* que se pasa como par�metro. Se debe indicar la p�gina del PDF donde se debe introducir
* el c�digo (normlamente la p�gina 1) y la posici�n absoluta X e Y dentro de la p�gina.
*/
public void establecerBarCodeNP (int Pagina, String texto, int XPos, int YPos) throws Exception
{
BarcodePDF417 code417 = new BarcodePDF417();
code417.setText(texto);
Image img = code417.getImage();
img.setAbsolutePosition(XPos, YPos);
//Inicialmente lo dejamos a la misma escala. Falta comprobar si es necesario aumentarla o
//disminuirla.
img.scalePercent(100, 100);
pdfs.getOverContent(Pagina).addImage(img);
}
示例7: 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);
}
示例8: generateBarcode
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Generate barcode in the form
*
* @param pdfStamper
* @throws DocumentException
*/
private void generateBarcode(PdfStamper pdfStamper, String userId) throws DocumentException {
// add barcode on the first page
PdfContentByte cb = pdfStamper.getOverContent(BARCODE_PAGE);
// barcode format 128C
Barcode128 code128 = new Barcode128();
// barcode format e.g. *1502A1234567890
// asterisk - * [constant]
// WebPOS Transaction - 1502 [constant]
// Form Version - A [constant for MyPost 1.5]
// 10-digit APCN
code128.setCode(ASTERISK + WEBPOS_TRANSACTIION + MYPOST_FORM_VERSION + userId);
code128.setCodeType(Barcode128.CODE128);
// convert barcode into image
Image code128Image = code128.createImageWithBarcode(cb, null, null);
// set barcode position x pixel, y pixel
code128Image.setAbsolutePosition(BARCODE_POSITION_X, BARCODE_POSITION_Y);
code128Image.scalePercent(BARCODE_SCALE_PERCENTAGE);
// add barcode image into PDF template
cb.addImage(code128Image);
}
示例9: generateQRCode
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Generate a QR code including URL on the page
*
* @param pdfStamper
* @throws DocumentException
*/
private void generateQRCode(PdfStamper pdfStamper) throws DocumentException {
// add barcode on the first page
PdfContentByte pdfContentByte = pdfStamper.getOverContent(APPENDED_PAGE);
BarcodeQRCode qrcode = new BarcodeQRCode("http://www.vendian.org/mncharity/dir3/paper_rulers/", 200, 200, null);
Image qrcodeImage = qrcode.getImage();
qrcodeImage.setAbsolutePosition(360,500);
qrcodeImage.scalePercent(100);
pdfContentByte.addImage(qrcodeImage);
}
示例10: getMaxHeight
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Returns the height of the cell.
* @return the height of the cell
* @since 3.0.0
*/
public float getMaxHeight() {
boolean pivoted = (getRotation() == 90 || getRotation() == 270);
Image img = getImage();
if (img != null) {
img.scalePercent(100);
float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth();
float scale = (getRight() - getEffectivePaddingRight()
- getEffectivePaddingLeft() - getLeft()) / refWidth;
img.scalePercent(scale * 100);
float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight();
setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight);
}
else {
if ((pivoted && hasFixedHeight()) || getColumn() == null)
setBottom(getTop() - getFixedHeight());
else {
ColumnText ct = ColumnText.duplicate(getColumn());
float right, top, left, bottom;
if (pivoted) {
right = PdfPRow.RIGHT_LIMIT;
top = getRight() - getEffectivePaddingRight();
left = 0;
bottom = getLeft() + getEffectivePaddingLeft();
}
else {
right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight();
top = getTop() - getEffectivePaddingTop();
left = getLeft() + getEffectivePaddingLeft();
bottom = hasFixedHeight() ? getTop() + getEffectivePaddingBottom() - getFixedHeight() : PdfPRow.BOTTOM_LIMIT;
}
PdfPRow.setColumn(ct, left, bottom, right, top);
try {
ct.go(true);
} catch (DocumentException e) {
throw new ExceptionConverter(e);
}
if (pivoted)
setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth());
else {
float yLine = ct.getYLine();
if (isUseDescender())
yLine += ct.getDescender();
setBottom(yLine - getEffectivePaddingBottom());
}
}
}
float height = getHeight();
if (hasFixedHeight())
height = getFixedHeight();
else if (height < getMinimumHeight())
height = getMinimumHeight();
return height;
}
示例11: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* PdfTemplates can be wrapped in an Image.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle rect = new Rectangle(PageSize.A4);
rect.setBackgroundColor(new Color(238, 221, 88));
Document document = new Document(rect, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
// step 3: we open the document
document.open();
// step 4:
PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.NOT_EMBEDDED);
String text = "Vertical";
float size = 16;
float width = bf.getWidthPoint(text, size);
template.beginText();
template.setRGBColorFillF(1, 1, 1);
template.setFontAndSize(bf, size);
template.setTextMatrix(0, 2);
template.showText(text);
template.endText();
template.setWidth(width);
template.setHeight(size + 2);
template.sanityCheck();
Image img = Image.getInstance(template);
img.setRotationDegrees(90);
Chunk ck = new Chunk(img, 0, 0);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
PdfPCell cell = new PdfPCell(img);
cell.setPadding(4);
cell.setBackgroundColor(new Color(0, 0, 255));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
table.addCell(cell);
table.addCell("I see a template everywhere");
table.addCell(cell);
table.addCell("I see a template on my right");
table.addCell(cell);
table.addCell("I see a template on my left");
Paragraph p1 = new Paragraph("This is a template ");
p1.add(ck);
p1.add(" just here.");
p1.setLeading(img.getScaledHeight() * 1.1f);
document.add(p1);
document.add(table);
Paragraph p2 = new Paragraph("More templates ");
p2.setLeading(img.getScaledHeight() * 1.1f);
p2.setAlignment(Element.ALIGN_JUSTIFIED);
img.scalePercent(70);
for (int k = 0; k < 20; ++k)
p2.add(ck);
document.add(p2);
// step 5: we close the document
document.close();
}
示例12: main
import com.lowagie.text.Image; //导入方法依赖的package包/类
/**
* Images wrapped in a Chunk.
*/
@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("imageChunks.pdf"));
// step 3: we open the document
document.open();
// step 4: we create a table and add it to the document
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
img.scalePercent(70);
Chunk ck = new Chunk(img, 0, -5);
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell();
cell.addElement(new Chunk(img, 5, -5));
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell("I see an image\non my right");
table.addCell(cell);
table.addCell("I see an image\non my left");
table.addCell(cell);
table.addCell("I see images\neverywhere");
table.addCell(cell);
table.addCell("I see an image\non my right");
table.addCell(cell);
table.addCell("I see an image\non my left");
Phrase p1 = new Phrase("This is an image ");
p1.add(ck);
p1.add(" just here.");
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(p1);
document.add(table);
// step 5: we close the document
document.close();
}