本文整理匯總了Java中com.lowagie.text.Image.scaleAbsolute方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.scaleAbsolute方法的具體用法?Java Image.scaleAbsolute怎麽用?Java Image.scaleAbsolute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.Image
的用法示例。
在下文中一共展示了Image.scaleAbsolute方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processImageFillFrame
import com.lowagie.text.Image; //導入方法依賴的package包/類
private InternalImageProcessorResult processImageFillFrame(String rendererId, DataRenderable renderer) throws JRException
{
Image image = null;
if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId))
{
image = loadedImagesMap.get(rendererId);
}
else
{
try
{
image = Image.getInstance(renderer.getData(jasperReportsContext));
imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
}
catch (Exception e)
{
throw new JRException(e);
}
if (printImage.isUsingCache())
{
loadedImagesMap.put(rendererId, image);
}
}
image.scaleAbsolute(availableImageWidth, availableImageHeight);
return
new InternalImageProcessorResult(
new Chunk(image, 0, 0),
image.getScaledWidth(),
image.getScaledHeight(),
0,
0
);
}
示例2: 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();
}
示例3: establecerImagen
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* Establece una imagen en una posici�n indic�ndole el tama�o que ha de tener
*
* @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 a_width, float a_height) throws Exception
{
Image imagen = Image.getInstance(a_Imagen);
imagen.scaleAbsolute(a_width, a_height);
imagen.setAbsolutePosition(a_posX, a_posY);
imagen.setTransparency(new int[] {255, 255,255, 255, 255, 255});
pdfs.getOverContent(nPagina).addImage(imagen);
}
示例4: addFooterAndWater
import com.lowagie.text.Image; //導入方法依賴的package包/類
/**
* 添加水印、頁眉、頁腳
* @param fileName 源文件路徑
* @param savepath 目標文件路徑
* @param waterMarkName 文字水印
* @param pageHeade 頁眉
* @param foot 頁腳
* @return
*/
public static int addFooterAndWater(String fileName, String savepath, String waterMarkName, String pageHeade, String foot) {
// 文檔總頁數
int num = 0;
Document document = new Document();
try {
PdfReader reader = new PdfReader(fileName);
//BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
BaseFont base = BaseFont.createFont(BaseFont.COURIER, "utf-8", BaseFont.EMBEDDED);
num = reader.getNumberOfPages();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(savepath));
document.open();
for (int i = 0; i < num;) {
PdfImportedPage page = copy.getImportedPage(reader, ++i);
PageStamp stamp = copy.createPageStamp(page);
Font f = new Font(base);
// 添加頁腳,左側文字,右側頁碼
ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(String.format("第 %d 頁/共 %d 頁", i, num),
f), 550f, 28, 0);
ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_LEFT, new Phrase(foot, f), 50f, 28, 0);
// 添加頁眉 (文字頁眉,居中)
ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(pageHeade, f), 150f, 800, 0);
// 頁眉添加logo (圖片頁眉,居右)
Image img = Image.getInstance("F:\\Tools\\pdf2swf工具\\resource/watermark.png");//"template/logo.png");// 選擇圖片
img.setAlignment(1);
img.scaleAbsolute(436 / 5, 96 / 5);// 控製圖片大小
img.setAbsolutePosition(450f, 800);// 控製圖片位置
stamp.getUnderContent().addImage(img);
// 添加水印
PdfContentByte under = stamp.getUnderContent();
under.beginText();
under.setColorFill(Color.LIGHT_GRAY);
// 字符越長,字體越小,設置字體
int fontSize = getFontSize(waterMarkName);
under.setFontAndSize(base, fontSize);
// 設置水印文字字體傾斜 開始
float pageWidth = reader.getPageSize(i).getWidth();
float pageHeight = reader.getPageSize(i).getHeight();
// 水印文字成60度角傾斜,且頁麵居中展示
//under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, pageWidth / 2, pageHeight / 2, 60);
img.setAlignment(1);
img.scaleAbsolute(636 / 5, 126 / 5);// 控製圖片大小
img.setAbsolutePosition(pageWidth / 2, pageHeight / 2);// 控製圖片位置
img.setRotation(60);
stamp.getUnderContent().addImage(img);
// 字體設置結束
under.endText();
stamp.alterContents();
copy.addPage(page);
}
} catch (Exception e) {
e.printStackTrace();
return -1;
} finally {
if (null != document) {
document.close();
}
}
System.out.println("pdf totalpages:" + num);
return num;
}