任何人都可以请示范我如何使用iText API在android中转换已经在图库中的图像并将其保存为pdf文档。尽快提供帮助。主要目标是创建android应用程序,从而可以从库中获取多个图像并将其保存为pdf格式。如何将图像转换为PDF使用iText
回答
要想从图库中的图片日子会把必须启动startActivityForResult和onActivityResultü可以存储在PDF文件中的图像: -
第一步拨打画廊意向为: -
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
然后在onActivityResult得到位图,并把它写在PDF
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch(requestCode){
case SELECT_PICTURE:
Uri selectedImageUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImageUri,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bmp = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Document document = new Document();
File f=new File(Environment.getExternalStorageDirectory(), "SimpleImages.pdf");
PdfWriter.getInstance(document,new FileOutputStream(f));
document.open();
document.add(new Paragraph("Simple Image"));
Image image = Image.getInstance(stream.toByteArray());
document.add(image);
document.close();
break;
}
}
}
希望这有助于..
谢谢你的解决方案。 bttw这行代码是干什么的? b.compress(Bitmap.CompressFormat.PNG,100,stream); 什么是b? – chai 2013-05-08 11:20:27
PDF image质量很差任何建议 – 2015-10-19 11:05:47
由于我无法对bakriOnFire的回答发表评论,因此我必须针对该主题撰写答案。
谢谢你的解决方案。 bttw是什么是这行代码做b.compress(Bitmap.CompressFormat.PNG,100,流);什么是B? - 柴5月8日在'13 11:20
代码林乐应该是:
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
位图是越来越使用PNG编码压缩并写入到一个ByteArrayOutputStream。 这是必需的,因为Image.getInstance()只能处理ByteArrays。
感谢您的更新..编辑我的答案.. – bakriOnFire 2015-10-19 12:19:58
- 1. 使用iText和Java将图像转换为pdf
- 2. 使用itext库将图像转换为pdf文件
- 3. 使用iText将HTML和图像转换为PDF
- 4. 使用iText将HTML转换为PDF
- 5. 使用iText将html转换为pdf
- 6. 使用iText将HTML转换为PDF
- 7. itext将PDF转换为csv
- 8. itext将xhtml转换为pdf
- 9. 如何使用iText将HTML与图像和超链接转换为PDF?
- 10. 使用ImageMagick将PDF转换为图像
- 11. 如何使用Wicked PDF将图像文件转换为PDF?
- 12. 如何将PDF转换为图像?
- 13. 如何将PDF转换为图像?
- 14. 如何使用iText库将XPS转换为PDF?
- 15. 如何使用ITEXT或PDFCROWD API将HTML页面转换为PDF
- 16. 如何使用itext liberary将pdf转换为文本文件
- 17. 如何使用iText将XHTML嵌套列表转换为pdf?
- 18. iText PDF;如何将jpeg2000转换为使用Java的jpg
- 19. 如何使用itext将文档转换为pdf文件
- 20. 将PDF转换为图像
- 21. 使用iText库将PDF转换为PDF/a
- 22. 如何使用ImageMagick将PDF文件转换为图像文件
- 23. 如何使用C#和ImageMagick将PDF转换为图像?
- 24. 使用ImageMagick.NET将PDF转换为图像 - 如何设置DPI
- 25. 如何使用ImageMagick for PHP将多页PDF转换为图像?
- 26. 如何使用Javascript将网页转换为PDF或图像?
- 27. PDF到使用iText在java中进行图像转换
- 28. ubuntu - 使用imagemagick转换utlity将图像转换为多页pdf
- 29. 将闪存图转换为图像/ pdf
- 30. 使用iText将html转换为pdf时应用css
http://stackoverflow.com/questions/5389994/convert-image-to-pdf-in-android – 2013-05-08 10:23:22
http://stackoverflow.com/questions/15742125/getting-image-from-drawable-and-adding -to-pdf-using-itext – 2013-05-08 10:24:02