-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
好的,讓我知道它是否有幫助。 –