Android Question Hello, is there a way to share a pdf file without saving it to the phone

stu14t

Active Member
Licensed User
Longtime User
helllllllllllo
Hello, is there a way to share a pdf file without saving it to the phone
https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/
You could share it to another app uisng an intent
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
You could share it to another app uisng an intent
B4X:
Dim Printer As Printer
    Printer.Initialize("")
    Printer.PrintWebView("job",WebView1)
I use this code and it shows me the default print page with a save to phone button as a pdf file, is there no way to share the file directly without saving it first?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
What you want to achieve to share a (pdf) file without saving it to the phone, is actually saving a pdf out of sight and without the permission of the phone user. Because this possibility was abused by people with criminal intentions, this is no longer allowed by Android. OS. So here you run into a "Security First" :cool:measure.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Yes it would help if the goal that needs to be achieved is better described instead of asking a question about a possible means. The question is how is the pdf file made or where does the pdf come from, where does it go (like a server or another phone and if so how should the pdf file be stored there).
And as always a small example project is of course very helpful to help you alfaizdev.
 
Upvote 0

stu14t

Active Member
Licensed User
Longtime User
I use the intent in one of my projects to hand images and files off to other apps. I first create the file and save this in the cache folder. After the intent has passed this off I clear the cache folder. This would work for you and no PDF file is retained.
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
I don't understand. You mean the file already in your phone?​
Okay, this attached file shows printing WebView1 content with the ability to save it as a pdf, I want to share it directly as a pdf.
 

Attachments

  • tt.zip
    38 KB · Views: 162
Upvote 0

aeric

Expert
Licensed User
Longtime User
I have just shared this example.
I don't think it is possible to share a file if it is not exist in your phone unless it is on a cloud storage.
 
Last edited:
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
Longtime User
Here's another solution

B4X:
    Dim phtmltopdf As PalmoHtmlToPdf
    phtmltopdf.Initialize("phtmltopdf")

    Private Provider As FileProvider
    Provider.Initialize
 
    phtmltopdf.ConvertFromString(htmlContent,Provider.SharedFolder,NameNew)
    Wait For  phtmltopdf_Finished (Success As Boolean)

        Dim in As Intent
        in.Initialize(in.ACTION_SEND, "شارك الملف")
        in.SetType("text/plain")
        in.PutExtra("android.intent.extra.STREAM", Provider.GetFileUri( NameNew))
        in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
        StartActivity(in)
 
Upvote 0
Top