CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2014
    Posts
    36

    Android Application for Converting Image file to PDF or PDF to any Image File

    The latest version of Aspose.Pdf for Android 1.2.0 has been released. This new release provides some great features including PDF to image conversion using android application with the help of the com.aspose.pdf.facades.PdfConverter class. Previously, this feature was only supported in Aspose.Pdf for .NET and Aspose.Pdf for Java. Aspose.Pdf for Android is built on top of Aspose.Pdf for Java and they have worked hard to support this feature in Aspose.Pdf for Android so that their Android customers can also use this handy feature for PDF manipulation. In this new release, they have introduced some great classes including:

    - BaseParagraph
    - BorderCornerStyle
    - BorderCornerType
    - BorderInfo
    - BorderSide
    - FloatingBox
    - HeaderFooter
    - Heading
    - Hyperlink
    - Image
    - LevelFormat
    - MarginInfo
    - NewParargraphPlacementInfo
    - PageGenerator
    - PageInfo
    - Paragraphs
    - TableImporter
    - TOCInfo
    - WebHyperlink

    Based on newly added classes, you can set a table’s border style, margins and padding, convert PDF documents to images, work with FloatingBox objects, convert image files to PDF format and much more. This release includes plenty of new and improved features as listed below

    - Add PdfConverter facade (beta)
    - Add Generator functionality
    - TEXT to PDF conversion issue is resolved - using textbuilder
    - Exception resolved while Adding image to an existing PDF document
    - Exception resolved while Adding image to an existing PDF document

  2. #2
    Join Date
    Jun 2013
    Posts
    4

    Re: Android Application for Converting Image file to PDF or PDF to any Image File

    thank you for sharing. it is what i am looking for to convert image to pdf. may i ask any other image formats are supported?
    and can i convert image to Word Office document.

  3. #3
    Join Date
    Jan 2014
    Posts
    36

    Re: Android Application for Converting Image file to PDF or PDF to any Image File

    Quote Originally Posted by dwimage View Post
    thank you for sharing. it is what i am looking for to convert image to pdf. may i ask any other image formats are supported?
    and can i convert image to Word Office document.
    I am not sure about converting image to word document in android app but you can ask this question on Aspose community forum for android and you can even request this feature there also and they can guide you how can acheive it.

    Below is the link of the forum. Best of luck.

    http://www.aspose.com/community/forums/default.aspx

  4. #4
    Join Date
    Mar 2014
    Posts
    3

    Re: Android Application for Converting Image file to PDF or PDF to any Image File

    the above Aspose.Pdf for Android 1.2.0 can help you convert image to pdf and convert pdf to image but if you want image to word, you can google and search, there are many pc software, i am not sure about Android related application. good luck.

  5. #5
    Join Date
    Oct 2014
    Posts
    1

    Re: Android Application for Converting Image file to PDF or PDF to any Image File

    As i see, this PDF to image converting application is designe for android. And i appreciate its functionalities. but, now, i'm not quiet sure whether this application can control the converted image size. For instance, i wanna to keep the converted image into a specific size area and view the image.

  6. #6
    Join Date
    Nov 2016
    Posts
    1

    Re: Android Application for Converting Image file to PDF or PDF to any Image File

    Hello,

    Download source code from here: http://deepshikhapuri.blogspot.in/20...cument-to.html

    MainActivity.java

    package com.deepshikha.convertbitmap;

    import android.Manifest;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.pdf.PdfDocument;
    import android.net.Uri;
    import android.provider.MediaStore;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.content.ContextCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.util.Log;
    import android.view.Display;
    import android.view.View;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.Toast;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;

    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    public static final int GALLERY_PICTURE = 1;
    Button btn_select, btn_convert;
    ImageView iv_image;
    boolean boolean_permission;
    boolean boolean_save;
    Bitmap bitmap;
    public static final int REQUEST_PERMISSIONS = 1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    init();
    listener();
    fn_permission();
    }

    private void init() {
    btn_select = (Button) findViewById(R.id.btn_select);
    btn_convert = (Button) findViewById(R.id.btn_convert);
    iv_image = (ImageView) findViewById(R.id.iv_image);
    }

    private void listener() {
    btn_select.setOnClickListener(this);
    btn_convert.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
    switch (view.getId()) {
    case R.id.btn_select:
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, GALLERY_PICTURE);
    break;

    case R.id.btn_convert:
    if (boolean_save){

    Intent intent1=new Intent(getApplicationContext(),PDFViewActivity.class);
    startActivity(intent1);

    }else {
    createPdf();
    }
    break;


    }
    }

    private void createPdf(){
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics displaymetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    float hight = displaymetrics.heightPixels ;
    float width = displaymetrics.widthPixels ;

    int convertHighet = (int) hight, convertWidth = (int) width;

    // Resources mResources = getResources();
    // Bitmap bitmap = BitmapFactory.decodeResource(mResources, R.drawable.screenshot);

    PdfDocument document = new PdfDocument();
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(bitmap.getWidth(), bitmap.getHeight(), 1).create();
    PdfDocument.Page page = document.startPage(pageInfo);

    Canvas canvas = page.getCanvas();


    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#ffffff"));
    canvas.drawPaint(paint);



    bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), true);

    paint.setColor(Color.BLUE);
    canvas.drawBitmap(bitmap, 0, 0 , null);
    document.finishPage(page);


    // write the document content
    String targetPdf = "/sdcard/test.pdf";
    File filePath = new File(targetPdf);
    try {
    document.writeTo(new FileOutputStream(filePath));
    btn_convert.setText("Check PDF");
    boolean_save=true;
    } catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(this, "Something wrong: " + e.toString(), Toast.LENGTH_LONG).show();
    }

    // close the document
    document.close();
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == GALLERY_PICTURE && resultCode == RESULT_OK) {

    if (resultCode == RESULT_OK) {
    Uri selectedImage = data.getData();
    String[] filePathColumn = {MediaStore.Images.Media.DATA};

    Cursor cursor = getContentResolver().query(
    selectedImage, filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String filePath = cursor.getString(columnIndex);
    cursor.close();


    bitmap = BitmapFactory.decodeFile(filePath);
    iv_image.setImageBitmap(bitmap);


    btn_convert.setClickable(true);
    }
    }
    }

    private void fn_permission() {
    if ((ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)||
    (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {

    if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.READ_EXTERNAL_STORAGE))) {
    } else {
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},
    REQUEST_PERMISSIONS);

    }

    if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))) {
    } else {
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
    REQUEST_PERMISSIONS);

    }
    } else {
    boolean_permission = true;


    }
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_PERMISSIONS) {

    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

    boolean_permission = true;


    } else {
    Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();

    }
    }
    }


    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured