Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to share file as PDF in full-size using a share feature

I have a share feature in my app that I use to share the file as PDF, the issue is when I share as PDF the image doesnt show the full PDF image I shared. I want the PDF file to show as full size when I share it. This is the code am using

private void sharePdf() {
    try {
        Bitmap bitmap;
        View v1;
        // File path;
        File att = null;
        root = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
        if (!root.exists())
            root.mkdir();
        {
            menu_layout.setVisibility(View.GONE);
            bottom_layout.setVisibility(View.GONE);
            menus.setVisibility(View.GONE);
            v1 = rl_layout.getRootView();
            v1.setDrawingCacheEnabled(true);

            bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 0, bytes);
            time = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.ENGLISH).format(new Date());
            path1 = new File(root.getAbsolutePath() + File.separator + time + ".png");
            path1.createNewFile();
            FileOutputStream fo = new FileOutputStream(path1);
            fo.write(bytes.toByteArray());
            fo.close();

            Bitmap bgBit = null;
            try {
                Uri uri = Uri.fromFile(new File(custombackground));
                if (uri != null && custombackground != null && !custombackground.trim().equalsIgnoreCase("")) {
                    bgBit = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                }
            } catch (Exception ex) {

            }
            if (bgBit != null) {
                bitmap = overlay(bgBit, drawingPanelView.getBitmap());
                bytes = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 0, bytes);
            }

            att = new File(root.getAbsolutePath() + File.separator
                    + "note.png");
            if (att.exists()) {
                att.delete();
            }
            att.createNewFile();
            FileOutputStream fo_att = new FileOutputStream(att);
            fo_att.write(bytes.toByteArray());
            fo_att.close();

            menu_layout.setVisibility(View.VISIBLE);
            bottom_layout.setVisibility(View.VISIBLE);
            menus.setVisibility(View.VISIBLE);
        }

        File pdfFile = new File(root.getAbsolutePath() + File.separator + "share_temp.pdf");
        if (!pdfFile.exists()) {
            pdfFile.createNewFile();
        }
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(pdfFile.getAbsoluteFile()));
        document.open();
        document.add(new Paragraph(content.getText().toString()));

        Image image = Image.getInstance(att.getAbsolutePath());
        document.add(image);
        for (HashMap<String, String> item : list) {
            List<String> vales = new ArrayList<>(item.values());
            for (String path : vales) {
                File fileIn = new File(path);
                if (fileIn.exists()) {
                    image = Image.getInstance(fileIn.getAbsolutePath());
                    document.add(image);
                }
            }
        }
        document.close();


        final Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
        emailIntent.putExtra(android.content.Intent.EXTRA_CC, "");
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pdfFile));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

       } catch (Exception e) {
      }

    }

This is how the PDF file shows, but I want it to show the full size

image

Comments