我是靠谱客的博主 明理野狼,最近开发中收集的这篇文章主要介绍docmaker java_Java Image.scalePercent方法代碼示例,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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();

}

最后

以上就是明理野狼为你收集整理的docmaker java_Java Image.scalePercent方法代碼示例的全部内容,希望文章能够帮你解决docmaker java_Java Image.scalePercent方法代碼示例所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部