Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:49:27+00:00 2026-06-06T22:49:27+00:00

Using pdfbox displays an error: import java.awt import javax` Based on the following code:

  • 0

Using pdfbox displays an error:

import java.awt
import javax`

Based on the following code:

imageType = BufferedImage.TYPE_INT_ARGB; //need to specifies java.awt
String[] formats = ImageIO.getReaderFormatNames(); //need to specifies javax
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:49:32+00:00Added an answer on June 6, 2026 at 10:49 pm

    Finally i found the solution. We can’t use awt with Android, so, finally go for the pdf viewver lib on http://sourceforge.net/projects/andpdf/files/

    Find out the apk and also source for pdf to image.

    Here is myclass to convert pdf to image:

    package com.print;
    
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.channels.FileChannel;
    
    import net.sf.andpdf.nio.ByteBuffer;
    import net.sf.andpdf.refs.HardReference;
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.RectF;
    import android.os.Bundle;
    import android.os.Environment;
    import android.os.Handler;
    import android.util.Log;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import com.sun.pdfview.PDFFile;
    import com.sun.pdfview.PDFImage;
    import com.sun.pdfview.PDFPage;
    import com.sun.pdfview.PDFPaint;
    import com.sun.pdfview.decrypt.PDFAuthenticationFailureException;
    import com.sun.pdfview.font.PDFFont;
    
    public class Transformer  extends Activity{
        /////////////////////////////////////////////
        private static final int STARTPAGE = 1;
        private static final float STARTZOOM = 1.0f;
    
        private static final String TAG = "PDFVIEWER";
        Bitmap _bitmap=null;
    
    //  private GraphView mGraphView;
        private String pdffilename;
        private PDFFile mPdfFile;
        private int mPage;
        private float mZoom;
        private File mTmpFile;
    
        private PDFPage mPdfPage; 
    
        private Thread backgroundThread;
       private Handler uiHandler;
    
        ImageView myimg;
        TextView command;
        Context context;
        ProgressDialog _p=null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.trans);
            context=Transformer.this;
              uiHandler = new Handler();
            initContrils();
        }
    
        private void initContrils() {
            // TODO Auto-generated method stub
             boolean showImages = getIntent().getBooleanExtra(printDemo.EXTRA_SHOWIMAGES, true);
                PDFImage.sShowImages = showImages;
                boolean antiAlias = getIntent().getBooleanExtra(printDemo.EXTRA_ANTIALIAS, true);
                PDFPaint.s_doAntiAlias = antiAlias;
                boolean useFontSubstitution = getIntent().getBooleanExtra(printDemo.EXTRA_USEFONTSUBSTITUTION, false);
                PDFFont.sUseFontSubstitution= useFontSubstitution;
                boolean keepCaches = getIntent().getBooleanExtra(printDemo.EXTRA_KEEPCACHES, false);
                HardReference.sKeepCaches= keepCaches;
    
                if (this.getIntent() != null) {
                    pdffilename = getIntent().getStringExtra(printDemo.EXTRA_PDFFILENAME);
            }
            mPage = STARTPAGE;
            mZoom = STARTZOOM;
            myimg=(ImageView)findViewById(R.id.imageView1);
            command=(TextView)findViewById(R.id.textView1);
            _p=new ProgressDialog(context);
            _p.setMessage("Converting........");
            _p.setCancelable(false);
            _p.show();
            setContent();
        }
    
        private void setContent() {
            try { 
                parsePDF(pdffilename);
                startRenderThread(mPage, mZoom);
    
            }
            catch (PDFAuthenticationFailureException e) {
                Log.e("Amit...","Error....");
            }
        }
        private synchronized void startRenderThread(final int page, final float zoom) {
              Log.e("Amit","renderrar");
            if (backgroundThread != null)
                return;
            backgroundThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (mPdfFile != null) {
    
                            showPage(page, zoom);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                    backgroundThread = null;
                }
            });
            updateImageStatus();
            backgroundThread.start();
    
        }
    
        private void updateImageStatus() {
            if (backgroundThread == null) {
                updateTexts();
                return;
            }
    
            uiHandler.postDelayed(new Runnable() {
                @Override public void run() {
                    updateImageStatus();
                }
            }, 1000);
        }
    
    
    /*
            private void setPageBitmap(Bitmap bi) {
                if (bi != null)
                    _bitmap = bi;
                else {
                    _bitmap = Bitmap.createBitmap(100, 100, Config.RGB_565);
                    Canvas can = new Canvas(_bitmap);
                    can.drawColor(Color.RED);
    
                    Paint paint = new Paint();
                    paint.setColor(Color.BLUE);
                    can.drawCircle(50, 50, 50, paint);
    
                    paint.setStrokeWidth(0);
                    paint.setColor(Color.BLACK);
                    can.drawText("Bitmap", 10, 50, paint);
                }
            }*/
    
            protected void updateTexts() {
                int maxCmds = PDFPage.getParsedCommands();
                int curCmd = PDFPage.getLastRenderedCommand()+1;
                if(maxCmds==curCmd){
    
                        _p.dismiss();
                        finish();
    
                    Log.e("Amit","check update_finish()");
                }else {
                    setContent();
                    Log.e("Amit","check update_again");
    
                }
    
         }
    
    
            private Bitmap showPage(int page, float zoom) throws Exception {
                Bitmap b=null;
                try {
                    Log.e("amit","Go to page bitmap");
                    mPdfPage = mPdfFile.getPage(page, true);
                    float wi = mPdfPage.getWidth();
                    float hei = mPdfPage.getHeight();
    
    
                    RectF clip = null;
    
                    Bitmap bi = mPdfPage.getImage((int)(wi*zoom), (int)(hei*zoom), clip, true, true);
                    b=bi;
    
                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                    b.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
                    File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "Firstpdf.jpg");
                    f.createNewFile();
                    FileOutputStream fo = new FileOutputStream(f);
                    fo.write(bytes.toByteArray());
                    Log.e("amit","Go to page bitmap______SAVE");
    
                } catch (Throwable e) {
                    Log.e(TAG, e.getMessage(), e);
    
                }
    
                return b;
            }
    
            private void parsePDF(String filename) throws PDFAuthenticationFailureException {
    
                try {
                    File f = new File(filename);
                    long len = f.length();
                    if (len == 0) {
                        Log.e("amit","No file found");
                    }
                    else {
                        Log.e("amit","file '" + filename + "' has " + len + " bytes");
                        openFile(f);
                    }
                }
                catch (PDFAuthenticationFailureException e) {
                    throw e; 
                } catch (Throwable e) {
                    e.printStackTrace();
    
                }
    
    
            }
    
    
            /**
             * <p>Open a specific pdf file.  Creates a DocumentInfo from the file,
             * and opens that.</p>
             *
             * <p><b>Note:</b> Mapping the file locks the file until the PDFFile
             * is closed.</p>
             *
             * @param file the file to open
             * @throws IOException
             */
            public void openFile(File file) throws IOException {
                // first open the file for random access
                RandomAccessFile raf = new RandomAccessFile(file, "r");
    
                // extract a file channel
                FileChannel channel = raf.getChannel();
    
                // now memory-map a byte-buffer
                ByteBuffer bb =
                        ByteBuffer.NEW(channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()));
                // create a PDFFile from the data
    
                    mPdfFile = new PDFFile(bb);
    
    
               Log.e("Amit","Pages-----"+mPdfFile.getNumPages());
            }
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote some code in Java using the pdfbox API that splits a pdf
Using DMD 2.057, I cannot get the following code to compile: import std.stdio; import
Last year, I made an application in Java using PDFBox to get the raw
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I'm writing a java app that creates a pdf from scratch using the pdfbox
Using boost python I need create nested namespace. Assume I have following cpp class
I am using the Apache PDFBox java library to create PDFs. Is there a
I am attempting to run the following Java code on an Ubuntu system. The
Using import datetime in python, is it possible to take a formatted time/date string
I'm using PDFBox for a C# .NET project. and I'm getting a TypeInitializationException (The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.