android开发 创建pdf文件夹,如何从android中的图像文件创建多页的pdf文件

如何在

Android中从图像文件创建包含多个页面的PDF文件?我从图像创建了一个PDF文件.该PDF文件有一页.这是该图像的一半.在右侧搜索部分被剪切为PDF文件.

我使用itext-5.3.4.jar来创建PDF.

wbviewnews.loadUrl("http://developer.android.com/about/index.html");

// button for create wbpage to image than image to PDF file

Button btnclick =(Button)findViewById(R.id.btnclick);

btnclick.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Picture p = wbviewnews.capturePicture();

bitmap=null;

PictureDrawable pictureDrawable = new PictureDrawable(p);

bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);

//Bitmap bitmap = Bitmap.createBitmap(200,200, Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);

canvas.drawPicture(pictureDrawable.getPicture());

ImageView imgdata=(ImageView)findViewById(R.id.imgdata);

imgdata.setImageBitmap(bitmap);

String filename = "pippo.png";

File sd = Environment.getExternalStorageDirectory();

File dest = new File(sd, filename);

String pdffilename = "pippo.pdf";

File pdffilepath = new File(sd, pdffilename);

try {

FileOutputStream out = new FileOutputStream(dest);

bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

out.flush();

out.close();

} catch (Exception e) {

e.printStackTrace();

Log.e("Exception", e.toString());

}

Document document=new Document();

try {

Log.e("pdffilepath", pdffilepath.toString());

PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(pdffilepath));

document.open();

// URL url = new URL (Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+filename);

// Log.e("url", url.toString());

Image image = Image.getInstance(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+filename) ;

document.add(image);

document.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Log.e("FileNotFoundException", e.toString());

} catch (DocumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Log.e("DocumentException", e.toString());

} catch (MalformedURLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Log.e("MalformedURLException", e.toString());

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Log.e("IOException", e.toString());

}

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值