Skip to content Skip to sidebar Skip to footer

How I Can Convert A Bitmap Into Pdf Format In Android

**I have bitmap in 'thepic' variable which is of Bitmap type.. imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); String realpath=getRealPathFromURI(imageUri); the

Solution 1:

you can do by this way...you have to download itextpdf-5.3.2.jar file and attach in your project..

publicclassWritePdfActivityextendsActivity 
{
  privatestaticStringFILE = "mnt/sdcard/FirstPdf.pdf";

  staticImage image;
  staticImageView img;
  Bitmap bmp;
  staticBitmap bt;
  static byte[] bArray;

  @OverridepublicvoidonCreate(Bundle savedInstanceState) 
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    img=(ImageView)findViewById(R.id.imageView1);

    try 
    {
        Documentdocument = newDocument();

        PdfWriter.getInstance(document, newFileOutputStream(FILE));
        document.open();

        addImage(document);
        document.close();
    }

    catch (Exception e) 
    {
        e.printStackTrace();
    }

}
  privatestaticvoidaddImage(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();
    }
 }
 }

Solution 2:

You need to use a 3rd party library, there's no built in ability. I know a few libraries that do the reverse (Qoppa, PDFTron, Reade) but they all cost a lot of money. I've heard iText works well for writing to bitmaps, but haven't used it myself.

Solution 3:

I haven't tried this but looking on stackoverflow I am giving you answer.

  1. It is not possible as per this answer on SO

  2. It is possible as per this answer on SO

So you check both answers study them and see whether it hepls you or not.

Post a Comment for "How I Can Convert A Bitmap Into Pdf Format In Android"