本文整理匯總了Java中com.lowagie.text.Image.setAbsolutePosition方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.setAbsolutePosition方法的具體用法?Java Image.setAbsolutePosition怎麽用?Java Image.setAbsolutePosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.setAbsolutePosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Adds some annotated images to a PDF file.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2:
// we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("annotated_images.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpeg.setAnnotation(new Annotation("picture", "This is my dog", 0, 0, 0, 0));
jpeg.setAbsolutePosition(100f, 550f);
document.add(jpeg);
Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
wmf.setAnnotation(new Annotation(0, 0, 0, 0, "http://www.lowagie.com/iText"));
wmf.setAbsolutePosition(100f, 200f);
document.add(wmf);
// step 5: we close the document
document.close();
}
示例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: 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());
}
}
示例4: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Adds an Image at an absolute position.
*/
@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("absolutepositions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
png.setAbsolutePosition(171, 250);
document.add(png);
png.setAbsolutePosition(342, 500);
document.add(png);
// step 5: we close the document
document.close();
}
示例5: 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();
}
}
示例6: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Demonstrates the use of layers.
*
* @param args
* no arguments needed
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("optionalcontent.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3: opening the document
document.open();
// step 4: content
PdfContentByte cb = writer.getDirectContent();
Phrase explanation = new Phrase(
"Automatic layers, form fields, images, templates and actions",
new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
650, 0);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);
PdfLayer l3 = new PdfLayer("Layer 3", writer);
PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
PdfLayerMembership m1 = new PdfLayerMembership(writer);
m1.addMember(l2);
m1.addMember(l3);
Phrase p1 = new Phrase("Text in layer 1");
Phrase p2 = new Phrase("Text in layer 2 or layer 3");
Phrase p3 = new Phrase("Text in layer 3");
cb.beginLayer(l1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
cb.endLayer();
cb.beginLayer(m1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
cb.endLayer();
cb.beginLayer(l3);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
cb.endLayer();
TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
"field1");
ff.setBorderColor(Color.blue);
ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
ff.setText("I'm a form field");
PdfFormField form = ff.getTextField();
form.setLayer(l4);
writer.addAnnotation(form);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
+ "pngnow.png");
img.setLayer(l4);
img.setAbsolutePosition(200, 550);
cb.addImage(img);
PdfTemplate tp = cb.createTemplate(100, 20);
Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
Font.NORMAL, Color.magenta));
ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
tp.setLayer(l4);
tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
cb.addTemplate(tp, 200, 500);
ArrayList<Object> state = new ArrayList<Object>();
state.add("toggle");
state.add(l1);
state.add(l2);
state.add(l3);
state.add(l4);
PdfAction action = PdfAction.setOCGstate(state, true);
Chunk ck = new Chunk("Click here to toggle the layers", new Font(
Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
Color.blue).setAction(action);
ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
250, 400, 0);
cb.sanityCheck();
// step 5: closing the document
document.close();
}
示例7: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Uses a java.awt.Image object to construct a com.lowagie.text.Image
* object.
*/
@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 writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("awt_image.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content to the document
for (int i = 0; i < 300; i++) {
document.add(new Phrase("Who is this? "));
}
PdfContentByte cb = writer.getDirectContent();
java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(PdfTestBase.RESOURCES_DIR + "H.gif");
Image image = Image.getInstance(awtImage, null);
image.setAbsolutePosition(100, 500);
cb.addImage(image);
Image gif = Image.getInstance(awtImage, new Color(0x00, 0xFF, 0xFF), true);
gif.setAbsolutePosition(300, 500);
cb.addImage(gif);
Image img1 = Image.getInstance(awtImage, null, true);
img1.setAbsolutePosition(100, 200);
cb.addImage(img1);
Image img2 = Image.getInstance(awtImage, new Color(0xFF, 0xFF, 0x00), false);
img2.setAbsolutePosition(300, 200);
cb.addImage(img2);
// step 5: we close the document
document.close();
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
}
示例11: 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);
}
示例12: 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);
}
示例13: getImage
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Creates an Image object based on a list of properties.
* @param attributes
* @return an Image
*/
public static Image getImage(Properties attributes)
throws BadElementException, MalformedURLException, IOException {
String value;
value = attributes.getProperty(ElementTags.URL);
if (value == null)
throw new MalformedURLException("The URL of the image is missing.");
Image image = Image.getInstance(value);
value = attributes.getProperty(ElementTags.ALIGN);
int align = 0;
if (value != null) {
if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(value))
align |= Image.LEFT;
else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(value))
align |= Image.RIGHT;
else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(value))
align |= Image.MIDDLE;
}
if ("true".equalsIgnoreCase(attributes
.getProperty(ElementTags.UNDERLYING)))
align |= Image.UNDERLYING;
if ("true".equalsIgnoreCase(attributes
.getProperty(ElementTags.TEXTWRAP)))
align |= Image.TEXTWRAP;
image.setAlignment(align);
value = attributes.getProperty(ElementTags.ALT);
if (value != null) {
image.setAlt(value);
}
String x = attributes.getProperty(ElementTags.ABSOLUTEX);
String y = attributes.getProperty(ElementTags.ABSOLUTEY);
if ((x != null) && (y != null)) {
image.setAbsolutePosition(Float.parseFloat(x + "f"), Float
.parseFloat(y + "f"));
}
value = attributes.getProperty(ElementTags.PLAINWIDTH);
if (value != null) {
image.scaleAbsoluteWidth(Float.parseFloat(value + "f"));
}
value = attributes.getProperty(ElementTags.PLAINHEIGHT);
if (value != null) {
image.scaleAbsoluteHeight(Float.parseFloat(value + "f"));
}
value = attributes.getProperty(ElementTags.ROTATION);
if (value != null) {
image.setRotation(Float.parseFloat(value + "f"));
}
return image;
}
示例14: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
*/
@Test
public void main() throws Exception {
// we create a reader for a certain document
PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR +"ChapterSection.pdf");
int n = reader.getNumberOfPages();
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader,PdfTestBase.getOutputStream("watermark_pagenumbers.pdf"));
// adding some metadata
HashMap<String, String> moreInfo = new HashMap<String, String>();
moreInfo.put("Author", "Bruno Lowagie");
stamp.setMoreInfo(moreInfo);
// adding content to each page
int i = 0;
PdfContentByte under;
PdfContentByte over;
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR +"watermark.jpg");
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
// watermark under the existing page
under = stamp.getUnderContent(i);
under.addImage(img);
// text over the existing page
over = stamp.getOverContent(i);
over.beginText();
over.setFontAndSize(bf, 18);
over.setTextMatrix(30, 30);
over.showText("page " + i);
over.setFontAndSize(bf, 32);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE", 230, 430, 45);
over.endText();
}
// adding an extra page
stamp.insertPage(1, PageSize.A4);
over = stamp.getOverContent(1);
over.beginText();
over.setFontAndSize(bf, 18);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
over.endText();
// adding a page from another document
PdfReader reader2 = new PdfReader(PdfTestBase.RESOURCES_DIR +"SimpleAnnotations1.pdf");
under = stamp.getUnderContent(1);
under.addTemplate(stamp.getImportedPage(reader2, 3), 1, 0, 0, 1, 0, 0);
// closing PdfStamper will generate the new PDF file
stamp.close();
}
示例15: main
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Draws different things into different layers.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("layers.pdf"));
// step 3: we open the document
document.open();
// step 4:
// high level
Paragraph p = new Paragraph();
for (int i = 0; i < 100; i++)
p.add(new Chunk("Blah blah blah blah blah. "));
document.add(p);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
+ "hitchcock.png");
img.setAbsolutePosition(100, 500);
document.add(img);
// low level
PdfContentByte cb = writer.getDirectContent();
PdfContentByte cbu = writer.getDirectContentUnder();
cb.setRGBColorFill(0xFF, 0xFF, 0xFF);
cb.circle(250.0f, 500.0f, 50.0f);
cb.fill();
cb.sanityCheck();
cbu.setRGBColorFill(0xFF, 0x00, 0x00);
cbu.circle(250.0f, 500.0f, 100.0f);
cbu.fill();
cbu.sanityCheck();
// step 5: we close the document
document.close();
}