您可以通过这种方式执行…您必须下载itextpdf-5.3.2.jar文件并将其附加到您的项目中。
public class WritePdfActivity extends Activity { private static String FILE = "mnt/sdcard/FirstPdf.pdf"; static Image image; static ImageView img; Bitmap bmp; static Bitmap bt; static byte[] bArray; @Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img=(ImageView)findViewById(R.id.imageView1); try { document document = new document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addImage(document); document.close(); } catch (Exception e) { e.printStackTrace(); }} private static void addImage(document document) { try { image = Image.getInstance(bArray); ///Here i set byte array..you can do bitmap to byte array and set in image... } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // image.scaleAbsolute(150f, 150f); try { document.add(image); } catch (documentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)