i am unable to find correct source code for this.while i am downloading and adding the source code I am getting errors like class cannot find create class.of course i added some of the jars are in library also.please provide some proper and useful code for that.
Asked
Active
Viewed 3,683 times
1 Answers
1
To convert pdf to images use android-pdfview and following code
DecodeServiceBase decodeService = new DecodeServiceBase(new PdfContext());
decodeService.setContentResolver(mContext.getContentResolver());
// a bit long running
decodeService.open(Uri.fromFile(pdf));
int pageCount = decodeService.getPageCount();
for (int i = 0; i < pageCount; i++) {
PdfPage page = decodeService.getPage(i);
RectF rectF = new RectF(0, 0, 1, 1);
// do a fit center to 1920x1080
double scaleBy = Math.min(AndroidUtils.PHOTO_WIDTH_PIXELS / (double) page.getWidth(), //
AndroidUtils.PHOTO_HEIGHT_PIXELS / (double) page.getHeight());
int with = (int) (page.getWidth() * scaleBy);
int height = (int) (page.getHeight() * scaleBy);
// you can change these values as you to zoom in/out
// and even distort (scale without maintaining the aspect ratio)
// the resulting images
// Long running
Bitmap bitmap = page.renderBitmap(with, height, rectF);
try {
File outputFile = new File(mOutputDir, System.currentTimeMillis() + FileUtils.DOT_JPEG);
FileOutputStream outputStream = new FileOutputStream(outputFile);
// a bit long running
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
} catch (IOException e) {
LogWrapper.fatalError(e);
}
}
You should perform this task in background e.g. AsyncTask

Muhammad Hamza Shahid
- 956
- 1
- 15
- 23
-
we have to add any library along with this code – user5829627 Apr 29 '16 at 05:21
-
2You have to use the library at https://github.com/JoanZapata/android-pdfview – Muhammad Hamza Shahid Apr 29 '16 at 05:23
-
after writing code what u send we have to add only this jar graddle-wrapper.jar or anything else – user5829627 Apr 29 '16 at 05:54
-
1also make sure you are writing this code in a background task e.g. AsyncTask – Muhammad Hamza Shahid Apr 29 '16 at 05:57
-
sorry I am new to android and I didn't understand background means – user5829627 Apr 29 '16 at 06:00
-
See this http://stackoverflow.com/a/9671602/1798737 for Asynstask example and write this code in doInBackground() function. – Muhammad Hamza Shahid Apr 29 '16 at 06:03
-
thanq so much Muhammad Hamza Shahid – user5829627 Apr 29 '16 at 06:29
-
i added library still i'm facing errors in the code – user5829627 May 09 '16 at 06:41
-
What's the error? its better to post a new question for that with complete log and code. – Muhammad Hamza Shahid May 09 '16 at 06:46
-
if iam trying to keep a question it is showing like use grammer even iam using right english. – user5829627 May 09 '16 at 06:52
-
Can you tell the error and in which its occuring? – Muhammad Hamza Shahid May 09 '16 at 06:56
-
at DeviceServiceBase class create the class – user5829627 May 09 '16 at 07:02
-
sorry at DecodeServiceBase class – user5829627 May 09 '16 at 07:04
-
and also variable mOutputDir in try block where it is created – user5829627 May 09 '16 at 07:07
-
mOutputDir is the path to directory where the newly created image will be stored you can initialize it like String mOutputDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() – Muhammad Hamza Shahid May 09 '16 at 07:14
-
what is mContext in doInBackGround method – user5829627 May 09 '16 at 07:26
-
Replace mContext with ActivityName.this – Muhammad Hamza Shahid May 09 '16 at 07:28
-
u please tell how to add library – user5829627 May 09 '16 at 08:41
-
also variable pdf not created – user5829627 May 09 '16 at 09:03
-
To add library check Gthub intructions are there and pdf is the is the File variable of pdf file that you need to process – Muhammad Hamza Shahid May 09 '16 at 09:36
-
bro iam getting so many errors after adding library into work space hava a look on this screen shot – user5829627 May 10 '16 at 05:29
-
how to keep images pls suggest – user5829627 May 10 '16 at 05:35
-
u given source code but u r not responding for the errors it is giving. – user5829627 May 10 '16 at 08:56