-3
我有工作的小应用程序,使用意图访问相机。该应用程序将捕获的图像返回到图像视图。我想添加一个功能,将imageview中的图像转换为pdf文件。有人很好地帮助如何去做这个我有工作小应用程序,使用意图访问相机。该应用程序返回一个图像捕获到图像视图
我有工作的小应用程序,使用意图访问相机。该应用程序将捕获的图像返回到图像视图。我想添加一个功能,将imageview中的图像转换为pdf文件。有人很好地帮助如何去做这个我有工作小应用程序,使用意图访问相机。该应用程序返回一个图像捕获到图像视图
建议您使用itext pdf库。这里是gradle:'com.itextpdf:itextpdf:5.1.1'
Document document=new Document();
String dirpath=android.os.Environment.getExternalStorageDirectory().toString();
PdfWriter.getInstance(document,new FileOutputStream(dirpath+"/example.pdf")); // Change pdf's name.
document.open();
Image img =Image.getInstance(dirpath+"/"+"example.jpg"); // Change image's name and extension.
float scaler = ((document.getPageSize().getWidth() - document.leftMargin()
- document.rightMargin() - 0)/img.getWidth()) * 100; // 0 means you have no indentation. If you have any, change it.
img.scalePercent(scaler);
img.setAlignment(Image.ALIGN_CENTER | Image.ALIGN_TOP);
//img.setAlignment(Image.LEFT| Image.TEXTWRAP);
/* float width = document.getPageSize().width() - document.leftMargin() - document.rightMargin();
float height = document.getPageSize().height() - document.topMargin() - document.bottomMargin();
img.scaleToFit(width, height)*/ Or try this.
document.add(img);
document.close();
Atif AbbAsi让我试试并找回你。 – jaldesa
好的,让我知道它是否有帮助。 –