2017-05-25 20 views

回答

0

建议您使用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(); 
+0

Atif AbbAsi让我试试并找回你。 – jaldesa

+0

好的,让我知道它是否有帮助。 –

相关问题