iOS Question Download PDF Document using HttpUtils2

Isingh

New Member
Licensed User
Hi everyone:
I am new to B4I and I am currently developing an app that involves downloading a PDF Document. I am a bit confused as what datatype a downloadable PDF Document is.
My code:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Private pg As Page
    Private job1, job2, job3 As HttpJob
    Private pdfurl = "https://origin2.cdn.componentsource.com/sites/default/files/resources/anywhere-software/534291/b4ibeginnersguidev1_1.pdf"
End Sub

and here is where I started the download:
B4X:
Sub ImageView1_Click
    job3.Initialize("Job3", Me)
    job3.Download(pdfurl)
   
End Sub


and here is job done:
B4X:
Sub JobDone (Job As HttpJob)
    Dim pdf_data As PDFDocument
   
     

    If Job.Success = True Then
       
      If Job.JobName = "Job3" Then
                pdf_data = Job.get
                'the part I am confused about. Job.getwhat?
               
        End If
    Else
        Log("Error: " & Job.ErrorMessage)

    End If
   
   
    Job.Release
       
   
End Sub
Also, how do I initialize the pdfDocument variable since the pdfDocument.initilize()takes a local directory and a file name?

I also found this https://www.b4x.com/android/forum/threads/download-huge-files-with-httputils2.30220/
but I am unsure how to integrate the changed part into my code. Do I edit the preexisting library file or do I have to start a new one?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you can use the newer and simpler method: https://www.b4x.com/android/forum/threads/79345/#content

The data type is not relevant. You need to save the downloaded resource as a file:
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirTemp, "test.pdf", False)
File.Copy2(job.GetInputStream, out)
out.Close

Now you can use this file with WebView or PDFDocument.
 
Upvote 0

Isingh

New Member
Licensed User
Note that you can use the newer and simpler method: https://www.b4x.com/android/forum/threads/79345/#content

The data type is not relevant. You need to save the downloaded resource as a file:
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirTemp, "test.pdf", False)
File.Copy2(job.GetInputStream, out)
out.Close

Now you can use this file with WebView or PDFDocument.

I am assuming iHttpUtil2 is the same thing as OKHttpUtils2 on IOS devices? Also, what happens if I want to store the file permanently on the device?
 
Last edited:
Upvote 0
Top