with PdfDocument i can't create single pdf page for single image

Viewed 19

i hope you are fine.

i took a code of converting images to pdf file (thanks a lot to who shared the way), i edited it to be able to create a single image to pdf (single page), but always when i try the code i get two pages ! even if i determine only one page !. can some one help me ?

this is the code :

android.graphics.pdf.PdfDocument document = new android.graphics.pdf.PdfDocument();
try {
               File item = new File("/storage/emulated/0/folder/img/test.png");
                    Bitmap bitmap = BitmapFactory.decodeFile(item.getAbsolutePath());
                    android.graphics.pdf.PdfDocument.PageInfo pageInfo = new android.graphics.pdf.PdfDocument.PageInfo.Builder(bitmap.getWidth(), bitmap.getHeight(), 1).create();
                    android.graphics.pdf.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);
                    canvas.drawBitmap(bitmap, 0, 0, null);
                    document.finishPage(page);
                
                document.writeTo(new FileOutputStream("/storage/emulated/0/folder/img/test.pdf"));
            } catch (IOException e) {
                e.printStackTrace();
            }
0 Answers
Related