amsun.util;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import BadElementException;
手机流量怎么查询
import Document;
import Image;
import Rectangle;
import pdf.PdfContentByte;
import pdf.PdfGState;
import pdf.PdfReader;
import pdf.PdfStamper;
import pdf.PdfWriter;
/**
*
*
*
* @author zjx
* @since 2012-1-11
* @version 1.0
*/
@Service
public class PdfUtil {
/**
* 将图片批量转换成PDF,本方法目前只支持图片格式文件
* @param imgList
受戒读后感
* @return
*/
public ByteBuffer getImgToPDF(List<Image> imgList){
Document doc = new Document();
ByteArrayOutputStream bout=new ByteArrayOutputStream();
try {
if(imgList.size()>0){
//将图片转成pdf并写到本地
Instance(doc, bout);
doc.open();
logger.info("======================>>开始将图片批量转换成PDF!!!!!!");
for(Image jpg1:imgList){
//将整批图片压缩到一张PDF中
doc.add(jpg1);
}
doc.clo();
logger.info("======================>>转换结束!!!!!!!!!!");
}
ByteBuffer buff = ByteArray());
return buff;
} catch (Exception e) {
logger.info("======================>>图片批量转换成PDF失败,原因如下:"+e.getMessage());
if(e instanceof NullPointerException){
return null;
}
return null;
}finally{
}
}
/**
* PDF中添加水映
* @param byt
* @return
*/
private ByteBuffer getByte(byte [] byt) {
try {
ByteArrayOutputStream bout=new ByteArrayOutputStream();
枫叶的作文 PdfReader Read_PDF_To_Watermark = new PdfReader(byt);
int number_of_pages = Read_PDF_NumberOfPages();
PdfStamper stamp = new PdfStamper(Read_PDF_To_Watermark,bout);
int i = 0;
Image watermark_image = WaterMarkImgPath());
watermark_image.tAbsolutePosition(350, 50);
PdfContentByte add_watermark;
PdfGState gs = new PdfGState();
gs.tFillOpacity(100.00f);//设置透明度为0.2
while (i < number_of_pages) {
i++;
add_watermark = OverContent(i);
add_watermark.addImage(watermark_image);
add_watermark.tGState(gs);
}
stamp.clo();
ByteBuffer buff = ByteBuffer.ByteArray());
return buff;
}
catch (Exception i1) {
i1.printStackTrace();
return null;
}
}
/**
* 将ByteBuffer转换成image对象
*
* @param buffer
*
* @return
*/
public Image getImgObj(ByteBuffer buffer){
Image imageRight = null;
BufferedImage bufferImage=null;
try {
byte[] by=new aining()];
(by);
山东潍坊风筝节
try {
imageRight = Instance(by);
float Height();
float Width();
当归有什么功效 int percent=getPercent2(heigth, width);
//设置图片居中显示
imageRight.tAlignment(Image.MIDDLE);
//直接设置图片的大小~~~~~~~第三种解决方案,按固定比例压缩
// jpg1.scaleAbsolute(210.0f, 297.0f);
//按百分比显示图片的比例
imageRight.scalePercent(percent);//表示是原来图像的比例;
} catch (BadElementException e) {
e.printStackTrace();
logger.info("ByteBuffer转换成image对象失败,原因如下:"+e.getMessage());
("",e);
}
//图片在PDF中居中显示
// imageRight.tAlignment(Image.ALIGN_CENTER);
return imageRight;
} catch (IOException e) {
e.printStackTrace();
logger.info("ByteBuffer转换成itextpdf包的Image对象失败,原因如下:"+e.getMessage());
return null;
} finally{
word显示目录
if(bufferImage!=null){
bufferImage.flush();
毕生难忘
}
}
}
public int getPercent2(float h,float w)
{
int per=0;
蘑菇的蘑怎么写
Document doc=new Document();
Rectangle rect = PageSize();
if (w > Width()-20){
float indexCount=w>1100?(w-1100):0;
per = (int) ((((w-indexCount) - Width()) / w) * 100);
}
return (int) per;
}
}