Android Tutorial Create PDF with b4a and php

DonManfred

Expert
Licensed User
Hallo,

from time to time someone is asking on how to create a pdf with b4a.
I dont know how to do that ONLY with b4a.

Today i spend a few hours to write a b4a-example and a php-script which creates the pdf using fpdf.

ATTENTION: This b4a-example uses CreateMap so you need B4A V3.8 for it to work...

The logic "in app" is simple.
- A list with commands is created and send to php-script.
- The php-script do all given commands in order to create a pdf.
- The pdf is then written to disc and the url to this pdf is returned to the app.
- The app see this url and download this pdf
- After finished downloading the pdf it is showed in a pdf-viewer

B4X:
Dim cmds As List
cmds.Initialize
' "init" should be the first action
cmds.Add(CreateMap("action": "init", "grid": 5,"showfooter": True))
' Author, Creator, Title, Subject and Keywords should be called before the first "NewPage"
cmds.Add(CreateMap("action": "SetAuthor", "author": "Manfred Ssykor"))
cmds.Add(CreateMap("action": "SetCreator", "creator": "b4a-php-pdf"))
cmds.Add(CreateMap("action": "SetTitle", "title": "Title bla bla bla"))
cmds.Add(CreateMap("action": "SetSubject", "subject": "Subject bla bla bla"))
cmds.Add(CreateMap("action": "SetKeywords", "keywords": "Keywords bla "))
' NewPage creates a new Page in pdf
cmds.Add(CreateMap("action": "NewPage"))

cmds.Add(CreateMap("action": "SetFont","font": "DejaVu","style": "","size": 12))
cmds.Add(CreateMap("action": "settext", "text": "Примерен доставчик ООД","border": "LBRT", "x": 140, "y": 10, "w": 72, "h": 10, "r": 255,"g": 0,"b": 0,"align":"C"))

' SetFont can be used to change the font used in pdf after this action
cmds.Add(CreateMap("action": "SetFont","font": "courier","style": "","size": 12))

' SetText writes a text into the pdf.
' border can be one OR more chars out of L, B, T, R (resp. Left, Bottom, Top, Right)
' x, y, w and h are the position and width/height of textbox
' r, g, b are the color for this text in RGB-format
' align can be L,C,R (leftjustify, center, rightjustify
cmds.Add(CreateMap("action": "SetText", "text": " ","border": "LBR", "x": 5, "y": 5, "w": 72, "h": 5, "r": 64,"g": 64,"b": 64,"align":"L"))

cmds.Add(CreateMap("action": "setfont","font": "courier","style": "","size": 14))

' Red Text
cmds.Add(CreateMap("action": "settext", "text": "this is a test","border": "", "x": 5, "y": 10, "w": 72, "h": 5, "r": 255,"g": 0,"b": 0,"align":"C"))
' Green Text
cmds.Add(CreateMap("action": "settext", "text": "Hello world","border": "B", "x": 5, "y": 25, "w": 72, "h": 5, "r": 0,"g": 255,"b": 0,"align":"L"))

' Blue Text
cmds.Add(CreateMap("action": "SetText", "text": "Hellooooo :-)","border": "", "x": 5, "y": 50, "w": 72, "h": 5, "r": 0,"g": 0,"b": 255,"align":"L"))

' SetDrawColor definies the color for lines, boxes and so on
' r,g,b is the color to use for drawings in RGB-format
cmds.Add(CreateMap("action": "SetDrawColor", "r": 128, "g": 128, "b": 128))
cmds.Add(CreateMap("action": "line", "x1": 5, "y1": 50, "x2": 72, "y2": 5))


' SetFillColor definies the color for filling rects for example
' r,g,b is the color to use for fill in RGB-format
cmds.Add(CreateMap("action": "SetfillColor", "r": 128, "g": 0, "b": 128))
' rect draws a rectangle
' x, y, w, h is the position and size of the rect
' style can be
' D OR empty String: draw. This Is the default value.
' F: fill
' DF OR FD: draw AND fill
cmds.Add(CreateMap("action": "rect", "x": 5, "y": 75, "w": 25, "h": 25, "style":"DF"))

' SetImage put a image into the pdf
' imgurl = url of the image
' x,y,w,h is the position and size of the image
' type can be JPG, JPEG, PNG and GIF.
cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World", "x": 40, "y": 80, "w": 180, "h": 75,"type": "png"))

' SetLineWidth sets the width of a line of rect´s or line´s (float)
cmds.Add(CreateMap("action": "SetLinewidth", "w": 1.5))
cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://pdf.basic4android.de/b4arulez.gif", "x": 5, "y": 160, "w": 75, "h": 75,"type": "gif"))
cmds.Add(CreateMap("action": "SetDrawColor", "r": 128, "g": 0, "b": 128))
cmds.Add(CreateMap("action": "line", "x1": 48, "y1": 180, "x2": 70, "y2": 175))

cmds.Add(CreateMap("action": "setfont","font": "courier","style": "BI","size": 16))
cmds.Add(CreateMap("action": "settext", "text": "Erel rulez!","border": "0", "x": 75, "y": 170, "w": 25, "h": 5, "r": 255,"g": 0,"b": 0,"align":"L"))

cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://pdf.basic4android.de/icon.png", "x": 125, "y": 180, "w": 72, "h": 72,"type": "png"))

Dim json As JSONGenerator
json.Initialize2(cmds)
Log(json.ToString)
Dim job As HttpJob
Dim p As PhoneId
job.Initialize("createpdf", Me)
job.download2("http://pdf.basic4android.de/", Array As String( _
    "json", json.ToString, _
    "DeviceID", p.GetDeviceId _
))

B4X:
Sub JobDone(job As HttpJob)
  ProgressDialogHide
  If job.Success = True Then
      If job.JobName = "getpdf" Then
        Dim OutStream As OutputStream
      Log("DownloadReady: "&job.Tag)
      OutStream = File.OpenOutput(File.DirRootExternal, job.Tag, False) ' Job.Tag is read to set the Original Filename we specify earlier in the creation of the Job
            File.Copy2(job.GetInputStream,OutStream) ' save the file
        OutStream.Close
        Log(job.Tag&" written to "&File.DirRootExternal) ' Write the Originalname to the log to see what happens ;-)
            Dim i As Intent
            i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirRootExternal & "/", job.Tag))
            'i.SetComponent("android/com.android.internal.app.ResolverActivity")
            i.SetType("application/pdf")
            StartActivity(i)
        End If
      If job.JobName = "createpdf" Then
            Log(job.GetString)
            Dim parser As JSONParser
            parser.Initialize(job.GetString)
            Dim m As Map = parser.NextObject
            Dim pdf As String = m.Get("pdf")
            Dim resultcode As Int = m.Get("resultcode")
            If resultcode = 0 Then
                If pdf <> "" Then
                    Dim job As HttpJob
                    job.Initialize("getpdf", Me)
                    job.Tag = "result.pdf"
                    job.download(pdf)
                End If  
            End If
        End If
    Else
        Log("Error: " & job.ErrorMessage)
  End If
End Sub
As you can see; most of the fpdf-features are wrapped in php-script

To TEST you can use the url provided in the example. But please, if you want to USE it in your app. Please use your own webserver!

Hope you enjoy this example and be the code a kind of help in your future projects

Version 1.1 of PHP-Script now uses mpdf- instead of fpdf-class and is now able to use unicode


Due to the size of the php-archive you need to download it here. It´s all you need on php to run that on your server.
 

Attachments

Last edited:

stevel05

Expert
Licensed User
Nice one. A good example of cloud computing.
 

peacemaker

Well-Known Member
Licensed User
1) Local pictures (on Android) can be used ?
2) Seems, URL base should be edited in your PHP-script ?
3) What is the requirements to PHP on the hosting ? Any lib installed ?
 

peacemaker

Well-Known Member
Licensed User
Thanks, just mention this in the topic start.
 

luciano deri

Active Member
Licensed User
Hy, running the example in Debug Legacy i have this error
LogCat connected to: 1W14C0002793
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


06/04/2015


10:37:36
** Activity (main) Create, isFirst = true **
Notice: DEBUG enabled


40


Notice: TimeNow: 15:00


Notice: New Time: 15:03
Error: Error bla
Warning: bla
Notice: bla
Debug: bla
[{"showfooter":true,"action":"init","charset":"ISO-8859-3","grid":5},{"action":"SetAuthor","author":"Manfred Ssykor"},{"action":"SetCreator","creator":"b4a-php-pdf"},{"action":"SetTitle","title":"Title bla bla bla"},{"action":"SetSubject","subject":"Subject bla bla bla"},{"action":"SetKeywords","keywords":"Keywords bla "},{"action":"NewPage"},{"style":"","action":"SetFont","font":"courier","size":12},{"style":"","action":"SetFont","font":"DejaVu","size":12},{"w":72,"g":0,"text":"Примерен доставчик ООД","b":0,"r":255,"align":"C","action":"settext","border":"LBRT","h":10,"y":10,"x":140},{"w":72,"g":64,"text":" ","b":64,"r":64,"align":"L","action":"SetText","border":"LBR","h":5,"y":5,"x":5},{"style":"","action":"setfont","font":"courier","size":14},{"w":72,"g":0,"text":"this is a test","b":0,"r":255,"align":"C","action":"settext","border":"","h":5,"y":10,"x":5},{"w":72,"g":255,"text":"Hello world","b":0,"r":0,"align":"L","action":"settext","border":"B","h":5,"y":25,"x":5},{"w":72,"g":0,"text":"Hellooooo :)","b":255,"r":0,"align":"L","action":"SetText","border":"","h":5,"y":50,"x":5},{"b":128,"action":"SetDrawColor","g":128,"r":128},{"y1":50,"action":"line","y2":5,"x2":72,"x1":5},{"b":128,"action":"SetfillColor","g":0,"r":128},{"w":25,"action":"rect","style":"DF","h":25,"y":75,"x":5},{"w":180,"action":"SetImage","type":"png","h":75,"y":80,"x":40,"imgurl":"http:\/\/chart.googleapis.com\/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World"},{"w":1.5,"action":"SetLinewidth"},{"w":75,"action":"SetImage","type":"gif","h":75,"y":160,"x":5,"imgurl":"http:\/\/pdf.basic4android.de\/b4arulez.gif"},{"b":128,"action":"SetDrawColor","g":0,"r":128},{"y1":180,"action":"line","y2":175,"x2":70,"x1":48},{"style":"BI","action":"setfont","font":"courier","size":16},{"w":25,"g":0,"text":"Erel rulez!","b":0,"r":255,"align":"L","action":"settext","border":"0","h":5,"y":170,"x":75},{"w":72,"action":"SetImage","type":"png","h":72,"y":180,"x":125,"imgurl":"http:\/\/pdf.basic4android.de\/icon.png"}]


** Activity (main) Resume **


** Service (httputils2service) Create **


** Service (httputils2service) Start **


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
<head><!--[if IE 6]><link rel="stylesheet" href="../nonauth/style/pda.css" media="all" type="text/css" /><![endif]--><script type="text/javascript">var x_czs = {};</script><script type="text/javascript" src="/nonauth/getTranslations.js.php?v=3127"></script><script type="text/javascript" src="/nonauth/getLoginType.js.php?v=3127&dest=aHR0cDovL3BkZi5iYXNpYzRhbmRyb2lkLmRlL2luZGV4LnBocD9qc29uPSU1QiU3QiUyMnNob3dmb290ZXIlMjIlM0F0cnVlJTJDJTIyYWN0aW9uJTIyJTNBJTIyaW5pdCUyMiUyQyUyMmNoYXJzZXQlMjIlM0ElMjJJU08tODg1OS0zJTIyJTJDJTIyZ3JpZCUyMiUzQTUlN0QlMkMlN0IlMjJhY3Rpb24lMjIlM0ElMjJTZXRBdXRob3IlMjIlMkMlMjJhdXRob3IlMjIlM0ElMjJNYW5m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MlNldEltYWdlJTIyJTJDJTIydHlwZSUyMiUzQSUyMnBuZyUyMiUyQyUyMmglMjIlM0E3NSUyQyUyMnklMjIlM0E4MCUyQyUyMnglMjIlM0E0MCUyQyUyMmltZ3VybCUyMiUzQSUyMmh0dHAlM0ElNUMlMkYlNUMlMkZjaGFydC5nb29nbGVhcGlzLmNvbSU1QyUyRmNoYXJ0JTNGY2h0JT


Message longer than Log limit (4000). Message was truncated.
java.lang.RuntimeException: JSON Object expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:50)
at de.donmanfred.codetest.main._jobdone(main.java:733)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:962)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
 

DonManfred

Expert
Licensed User
1. You should never post in an existing thread. Always start a new thread for your question.
2.
can i use this with B4J ?
It is just using okhttputils2 for the http jobs. Yes, it can be used in B4J and even B4i i guess.

Have you a little Example ?
The Example code you can find in Post #1

here a copy.
B4X:
Dim cmds As List
cmds.Initialize
' "init" should be the first action
cmds.Add(CreateMap("action": "init", "grid": 5,"showfooter": True))
' Author, Creator, Title, Subject and Keywords should be called before the first "NewPage"
cmds.Add(CreateMap("action": "SetAuthor", "author": "Manfred Ssykor"))
cmds.Add(CreateMap("action": "SetCreator", "creator": "b4a-php-pdf"))
cmds.Add(CreateMap("action": "SetTitle", "title": "Title bla bla bla"))
cmds.Add(CreateMap("action": "SetSubject", "subject": "Subject bla bla bla"))
cmds.Add(CreateMap("action": "SetKeywords", "keywords": "Keywords bla "))
' NewPage creates a new Page in pdf
cmds.Add(CreateMap("action": "NewPage"))

cmds.Add(CreateMap("action": "SetFont","font": "DejaVu","style": "","size": 12))
cmds.Add(CreateMap("action": "settext", "text": "Примерен доставчик ООД","border": "LBRT", "x": 140, "y": 10, "w": 72, "h": 10, "r": 255,"g": 0,"b": 0,"align":"C"))

' SetFont can be used to change the font used in pdf after this action
cmds.Add(CreateMap("action": "SetFont","font": "courier","style": "","size": 12))

' SetText writes a text into the pdf.
' border can be one OR more chars out of L, B, T, R (resp. Left, Bottom, Top, Right)
' x, y, w and h are the position and width/height of textbox
' r, g, b are the color for this text in RGB-format
' align can be L,C,R (leftjustify, center, rightjustify
cmds.Add(CreateMap("action": "SetText", "text": " ","border": "LBR", "x": 5, "y": 5, "w": 72, "h": 5, "r": 64,"g": 64,"b": 64,"align":"L"))

cmds.Add(CreateMap("action": "setfont","font": "courier","style": "","size": 14))

' Red Text
cmds.Add(CreateMap("action": "settext", "text": "this is a test","border": "", "x": 5, "y": 10, "w": 72, "h": 5, "r": 255,"g": 0,"b": 0,"align":"C"))
' Green Text
cmds.Add(CreateMap("action": "settext", "text": "Hello world","border": "B", "x": 5, "y": 25, "w": 72, "h": 5, "r": 0,"g": 255,"b": 0,"align":"L"))

' Blue Text
cmds.Add(CreateMap("action": "SetText", "text": "Hellooooo :-)","border": "", "x": 5, "y": 50, "w": 72, "h": 5, "r": 0,"g": 0,"b": 255,"align":"L"))

' SetDrawColor definies the color for lines, boxes and so on
' r,g,b is the color to use for drawings in RGB-format
cmds.Add(CreateMap("action": "SetDrawColor", "r": 128, "g": 128, "b": 128))
cmds.Add(CreateMap("action": "line", "x1": 5, "y1": 50, "x2": 72, "y2": 5))


' SetFillColor definies the color for filling rects for example
' r,g,b is the color to use for fill in RGB-format
cmds.Add(CreateMap("action": "SetfillColor", "r": 128, "g": 0, "b": 128))
' rect draws a rectangle
' x, y, w, h is the position and size of the rect
' style can be
' D OR empty String: draw. This Is the default value.
' F: fill
' DF OR FD: draw AND fill
cmds.Add(CreateMap("action": "rect", "x": 5, "y": 75, "w": 25, "h": 25, "style":"DF"))

' SetImage put a image into the pdf
' imgurl = url of the image
' x,y,w,h is the position and size of the image
' type can be JPG, JPEG, PNG and GIF.
cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World", "x": 40, "y": 80, "w": 180, "h": 75,"type": "png"))

' SetLineWidth sets the width of a line of rect´s or line´s (float)
cmds.Add(CreateMap("action": "SetLinewidth", "w": 1.5))
cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://pdf.basic4android.de/b4arulez.gif", "x": 5, "y": 160, "w": 75, "h": 75,"type": "gif"))
cmds.Add(CreateMap("action": "SetDrawColor", "r": 128, "g": 0, "b": 128))
cmds.Add(CreateMap("action": "line", "x1": 48, "y1": 180, "x2": 70, "y2": 175))

cmds.Add(CreateMap("action": "setfont","font": "courier","style": "BI","size": 16))
cmds.Add(CreateMap("action": "settext", "text": "Erel rulez!","border": "0", "x": 75, "y": 170, "w": 25, "h": 5, "r": 255,"g": 0,"b": 0,"align":"L"))

cmds.Add(CreateMap("action": "SetImage", "imgurl": "http://pdf.basic4android.de/icon.png", "x": 125, "y": 180, "w": 72, "h": 72,"type": "png"))

Dim json As JSONGenerator
json.Initialize2(cmds)
Log(json.ToString)
Dim job As HttpJob
Dim p As PhoneId
job.Initialize("createpdf", Me)
job.download2("http://pdf.basic4android.de/", Array As String( _
    "json", json.ToString, _
    "DeviceID", p.GetDeviceId _
))
 
Last edited:

sdleidel

Member
Licensed User
OK...
I have Change this...
Prgramm runs, but Nothing is going on...
Ist the Webadress ok to testing ?
 
Top