Save pdf data in storage

124 views
Skip to first unread message

Soni Kumari

unread,
Jul 4, 2026, 9:11:10 PMJul 4
to DroidScript
Hi there! I'm working on a project that converts image to pdf. To convert i use base64
data:application/pdf;base64 so how to save this data in device storage.
Please tell me the way, I'd very appreciative 🙏 

Jumar

unread,
Jul 5, 2026, 6:08:40 AMJul 5
to DroidScript
Try this:

var appFolder = "/Internal/Documents/MyFolder";

function writePdfToDocuments(filePath, b64pdf) {
        const perm = "internal"
       
        if( !app.CheckPermission(appFolder) ) {
                app.GetPermission(perm, path => {
                        if (!path) {
                            app.ShowPopup("Permission not granted")
                        }
                        else {
                            writePdfToDocuments(filePath, b64pdf)
                        }
                    })
            return
        }
       
        app.MakeFolder(appFolder)
        app.WriteFile(filePath, b64pdf, "Base64")
        app.ShowPopup("PDF is saved to Documents/MyFolder folder")
    }

Regards

Soni Kumari

unread,
Jul 5, 2026, 9:36:40 AMJul 5
to DroidScript
Thank you so much for this! 
But Is there any more ways to save direct in Documents without permission?

Jumar

unread,
Jul 5, 2026, 10:15:20 AMJul 5
to DroidScript
Saving directly without asking permission is a NO for latest android.

To avoid asking for permission, initiate a download action the way download works for the web. I haven't tried this btw.

Soni Kumari

unread,
Jul 5, 2026, 1:44:50 PMJul 5
to DroidScript
Thanks for replying Jumar!
I was asking because when i convert lots images to pdf in base64 then app get hangs sp there any to fast processing and without app freezing?

Jumar

unread,
Jul 5, 2026, 9:03:20 PMJul 5
to DroidScript
Try running a background nodejs process to handle batch conversion so that your main thread will not hang.

Soni Kumari

unread,
Jul 5, 2026, 11:45:38 PMJul 5
to DroidScript
I don't understand this :(

Jumar

unread,
Jul 6, 2026, 7:40:22 AMJul 6
to DroidScript
When creating an app we are working mostly in the main thread. When we do heavy operation (such as batch image to pdf conversion), this will take some time to complete making our main thread seems like hanging. Luckily, DroidScript supports Nodejs so we can run a nodejs thread in the background which is separated from our main ui thread. You just let nodejs handle heavy processing and then notify the main thread once nodejs finishes the job.

Soni Kumari

unread,
Jul 6, 2026, 4:13:29 PMJul 6
to DroidScript
But how sir! I'm really confused here any demo files
I use js lib to convert image to pdf 

Alan Hendry

unread,
Jul 9, 2026, 4:50:39 AMJul 9
to DroidScript
HI,
When you create a new project/app
there's an option for Node (instead of Native)
then sub-options of Simple and Node Server
They sill create Sample code
Regards, ah

Jumar

unread,
Jul 14, 2026, 8:33:53 AMJul 14
to DroidScript
Hi.

Try this code:

Your main file code: [MyProjectName].js


function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
     
    txt = app.AddText(lay, "This is your main thread", 1)
   
    callNodeJs = app.AddButton(lay, "Generate pdf in nodejs")
    callNodeJs.SetOnTouch( CallNodeJS )

    app.AddLayout( lay )
   
    node = app.CreateNode();
    node.SetOnReady(node_OnReady);
}

function node_OnReady()
{
    node.Run("node_script.js")
}

function CallNodeJS()
{
    node.Func("GeneratePDF", "Value from main thread")
}

function OnPDFComplete(param1)
{
    app.ShowPopup(param1+": PDF completed...")
}



node_script.js file code:


console.log("Hello from nodejs")

// This function will be called from the main ui thread
function GeneratePDF(param1)
{
    // generate pdf here
    console.log(param1 + ": Generating pdf...")
   
    // call OnPDFComplete() function in the main thread after 4 seconds
    setTimeout(() => {
        parent.Func("OnPDFComplete", "Value from nodejs")
    }, 4000)
Reply all
Reply to author
Forward
0 new messages