OCR and Pdf plugin

203 views
Skip to first unread message

Soni Kumari

unread,
Oct 1, 2024, 6:46:51 AM10/1/24
to DroidScript
Why OCR Scanner and Pdf plugin not working 
OCR Scanner fully not working 
And pdf viewer plugin not working or loading documents only show blank white page

Jumar

unread,
Oct 1, 2024, 8:03:33 AM10/1/24
to DroidScript
For PDF Plugin

Can you paste some code for us to check?

Soni Kumari

unread,
Oct 1, 2024, 11:01:50 AM10/1/24
to DroidScript
This is the sample buddy!

// Load the PDFViewer plugin at the top of your script
app.LoadPlugin( "PDFViewer" )

function OnStart() {
    // create an instance of the PDFViewer component
    pdf = app.CreatePDFViewer()

    // create a fullscreen layout with object vertically centered
    lay = app.CreateLayout("Linear", "VCenter,FillXY")

    // add a pdf viewer control into the layout
    myPdf = pdf.AddView(lay, "mypdf.pdf", 0.8, 0.5)

    // add a button into the layout to zoom in the pdf view when click
    btn = app.AddButton(lay, "Zoom")
    btn.SetOnTouch(function() {
        myPdf.SetZoom( 1.5 )
    })

    // add the layout to the app
    app.AddLayout( lay )
}
Please help me out

Jumar

unread,
Oct 1, 2024, 11:34:18 AM10/1/24
to DroidScript
Do you have a copy of the "mypdf.pdf" file? You can add your own pdf file in the app you have created.

Soni Kumari

unread,
Oct 1, 2024, 11:43:12 AM10/1/24
to DroidScript
yes buddy I have in my storage of "mypdf.pdf"

Jumar

unread,
Oct 1, 2024, 11:46:59 AM10/1/24
to DroidScript
Here's a sample SPK. Install the PDFViewer plugin from DS Plugins Store and run the SPK below.
Sample App.spk

Soni Kumari

unread,
Oct 1, 2024, 12:06:49 PM10/1/24
to DroidScript
My brother thank you so much!
It worked 😄!
But I want show pdf file when users select files from storage

Alan Hendry

unread,
Oct 2, 2024, 6:00:03 PM10/2/24
to DroidScript
HI,
Have you looked at the Samples for CheckPermission and GetPermission
(for the user to choose a folder) and ChooseFile?
Regards, ah

Jumar

unread,
Nov 8, 2024, 9:53:43 AM11/8/24
to DroidScript
I just updated the PDFViewer plugin. Now it supports a fileUri and base64 data. You can also save pages as an image.

Try this:

app.LoadPlugin("PDFViewer")

function OnStart() {
   
    pdf = app.CreatePDFViewer()  

   
    lay = app.CreateLayout("Linear", "VCenter,FillXY")
   
    app.AddLayout( lay )
   
    SelectPDF()    
}

function SelectPDF()
{
    fldr = "/Internal/Documents/"
    perm = "internal"
   
    if( !app.CheckPermission( fldr ) )
    {
        app.GetPermission(perm, OnPermission)
        return
    }
   
     app.ChooseFile("Choose file", "application/pdf", fileUri => {
         myPdf = pdf.AddView(lay, fileUri, 1, 0.4, "page")
         myPdf.SetOnLoad( OnLoad )
     })
}

function OnLoad( info ) {
    btn = app.AddButton(lay, "Save pages")
    btn.SetOnTouch(function() {
        myPdf.SetZoom(2)
        myPdf.Save("*", "my-files.png", (filePath, page, totalPages) => {
            console.log(filePath+" has been saved!")
            console.log("Page "+page+" of "+totalPages)
        })
    })
}

function OnPermission(path, uri)
{
    if( !path )
        app.ShowPopup( "Permission not granted!" )
    else
        SelectPDF()
}

Alan Hendry

unread,
May 29, 2025, 8:47:17 AMMay 29
to DroidScript
HI,
DS 2.77.3 Android 14
OCR plugin (example in docs) gives message 
Cannot read properties of null - reading SetOnResult
(I need to rebuild an app that previously worked, for Play Store api rqmts)
Regards, ah
Reply all
Reply to author
Forward
0 new messages