Click here to Skip to main content
15,309,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to store this file in firebase storage , this file is pdf file i have created and it now downloading into my phone directory/file manager, but i want store it on firebase storage as well/ too....

What I have tried:

private void creatPdf(String Name1, String father_n1, String id_n1, String mob_n1, String dist_sp1, String police_sp1, String crime_sp1, String date_i1, String time_i1, String detail_i1, String address_p1 ) throws FileNotFoundException, URISyntaxException {


        String pdfPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();

        File file = new File(pdfPath, System.currentTimeMillis()+".pdf");

        OutputStream outputStream = new FileOutputStream(file);




      //  String pth = file.toURI().getPath();

       // File file1 = new File(new URI(pth));

        PdfWriter writer = new PdfWriter(file);

        PdfDocument pdfDocument = new PdfDocument(writer);

        Document document = new Document(pdfDocument);

        pdfDocument.setDefaultPageSize(PageSize.A4);

        document.setTopMargin(5);

        Drawable drawable = getDrawable(R.drawable.logo);

        Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

        ByteArrayOutputStream   stream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

        byte[] bitmapData = stream.toByteArray();

        ImageData imageData = ImageDataFactory.create(bitmapData);

        Image image = new Image(imageData);

        image.setHeight(100);
        image.setWidth(100);
        image.scaleToFit(100, 100);
        image.setHorizontalAlignment(HorizontalAlignment.CENTER);

        Paragraph firText = new Paragraph("First Information Report").setBold().setFontSize(19).setTextAlignment(TextAlignment.CENTER);

        float[] width = {100f , 100f};

        Table table = new Table(width);

        table.setHorizontalAlignment(HorizontalAlignment.CENTER);

        table.addCell(new Cell().add(new Paragraph("Name")));
        table.addCell(new Cell().add(new Paragraph(Name1)));

        table.addCell(new Cell().add(new Paragraph("Father Name")));
        table.addCell(new Cell().add(new Paragraph(father_n1)));

        table.addCell(new Cell().add(new Paragraph("CNIC Number")));
        table.addCell(new Cell().add(new Paragraph(id_n1)));

        table.addCell(new Cell().add(new Paragraph("Mobile Number")));
        table.addCell(new Cell().add(new Paragraph(mob_n1)));

        table.addCell(new Cell().add(new Paragraph("Present Address")));
        table.addCell(new Cell().add(new Paragraph(address_p1)));

        table.addCell(new Cell().add(new Paragraph("District")));
        table.addCell(new Cell().add(new Paragraph(dist_sp1)));

        table.addCell(new Cell().add(new Paragraph("Police Station")));
        table.addCell(new Cell().add(new Paragraph(police_sp1)));

        table.addCell(new Cell().add(new Paragraph("Nature of Crime")));
        table.addCell(new Cell().add(new Paragraph(crime_sp1)));

        table.addCell(new Cell().add(new Paragraph("Date of Incident")));
        table.addCell(new Cell().add(new Paragraph(date_i1)));

        table.addCell(new Cell().add(new Paragraph("Time of Incident")));
        table.addCell(new Cell().add(new Paragraph(time_i1)));


        float[] width1 = {940f , 360f};

        Table table1 = new Table(width1);

        table1.setHorizontalAlignment(HorizontalAlignment.CENTER);


        table1.addCell(new Cell(90, 90).add(new Paragraph("Detail of Incident")));
        table1.addCell(new Cell().add(new Paragraph(detail_i1)));


        BarcodeQRCode QRCode = new BarcodeQRCode(Name1+"\n"+father_n1+"\n"+id_n1+"\n"+mob_n1+"\n"+address_p1+"\n"+
                dist_sp1+"\n"+police_sp1+"\n"+crime_sp1+"\n"+date_i1+"\n"+time_i1+"\n"+detail_i1);

        PdfFormXObject qrCodeObject = QRCode.createFormXObject(ColorConstants.BLACK, pdfDocument);

        Image qrImage = new Image(qrCodeObject).setWidth(80).setHorizontalAlignment(HorizontalAlignment.CENTER);


        document.add(image);
        document.add(firText);
        document.add(table);
        document.add(table1);
        document.add(qrImage);

        document.close();
        Toast.makeText(FIRActivity.this, "FIR Registered, check pdf file", Toast.LENGTH_SHORT).show();





    }
Posted
Comments
OriginalGriff 16-Jan-22 3:21am
   
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?
Whet help do you need?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Meer Saqib Baloch 16-Jan-22 5:53am
   
what a pathetic reply i got from you, on my first post on this platform, really disgusting welcome...!

well.! sir i don't want to pick pdf file from my phone direcory, but what i want is when pdf file created at the same time it should be stored on firbabase
OriginalGriff 16-Jan-22 6:54am
   
THat's not a solution to your problem: it's saying that we have no idea what you have tried yet, or what problem you encountered when trying.

Since we can't see your screen, access your HDD, or read your mind, a request for better information is preferable to closing the question as "not answerable as it stands".

And if you think that asking for better info is "disgusting" and "pathetic" then I strongly suggest you never use the internet again as there is much, much worse stuff out there ...

I refuse to help people who are rude, so I'll wish you a good day and have nothing further to do with you. Goodbye.
Maciej Los 16-Jan-22 3:38am
   
Meer Saqib Baloch 16-Jan-22 5:52am
   
sir i don't want to pick pdf file from my phone direcory, but what i want is when pdf file created at the same time it should be stored on firbabase
Maciej Los 16-Jan-22 7:01am
   
Follow the link and check out the method to save pdf in firebase database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900