Greetings !!!
First of all, i hope you guys to be healthy in these quarantined days.
I was using the library PalmoHTMLToPDF in order to generate a PDF from a HTML template, which is working very well:
www.b4x.com
But, I noticed that there is no way (at least known for me) to change the PDF page orientation. The PDF is generated in portrait mode.
Is there any way to change the PDF orientation page before generating the document?
This is my code:
Thanks in advance !!!!
First of all, i hope you guys to be healthy in these quarantined days.
I was using the library PalmoHTMLToPDF in order to generate a PDF from a HTML template, which is working very well:
HtmlToPdf
Hello everybody, I've created this library that converts an html file (or string) to a pdf file programmatically. A couple of important notes: it only works on devices with SDK versions >= 21 and it cannot read files from the asset folder (you can either copy the file to the internal folder...
But, I noticed that there is no way (at least known for me) to change the PDF page orientation. The PDF is generated in portrait mode.
Is there any way to change the PDF orientation page before generating the document?
This is my code:
B4X:
Sub GenerarDefinitivo()
Dim OrigFormat As String=DateTime.DateFormat 'save orig date format
DateTime.DateFormat="yyyyMMddHHmmss"
Dim MyDate As String=DateTime.Date(DateTime.Now)
DateTime.DateFormat="dd/MM/yyyy"
Dim miFechaPlanilla As String=DateTime.Date(DateTime.Now)
DateTime.DateFormat=OrigFormat 'return to orig date format
Dim j As Int 'library Phone
'Works only on devices with SDK >= 21
Dim rr As RuntimePermissions
rr.CheckAndRequest(rr.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
miNombrePDF = "PEDIDO_ESPECIAL-" & MyDate & ".pdf"
phtmltopdf.Initialize("phtmltopdf")
File.Copy(File.DirAssets,"PLANTILLA_DEFINITIVA.htm",File.DirInternal,"PLANTILLA_DEFINITIVA.htm")
''leer archivo en una linea
Dim miContenido As String = File.ReadString( File.DirInternal,"PLANTILLA_DEFINITIVA.htm" )
ProgressDialogShow2("Generando formato...", False)
Sleep(0)
For j=0 To 100000
Next
'procesar contenido
Dim miContenidoProcesado As String = miContenido
''the method "GenerarDefinitiva" returns the HTML string to be converted to PDF
miContenidoProcesado= modDataProvider.GenerarDefinitiva(miContenidoProcesado,miFechaPlanilla)
''Convert to PDF
phtmltopdf.ConvertFromString(miContenidoProcesado, File.DirRootExternal, miNombrePDF)
ProgressDialogHide
End Sub
Sub phtmltopdf_Finished (Success As Boolean)
Log(Success)
ToastMessageShow("Document generated.",False)
File.Copy(File.DirRootExternal, miNombrePDF, Starter.Provider.SharedFolder, miNombrePDF)
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
Starter.Provider.SetFileUriAsIntentData(in, miNombrePDF)
in.SetComponent("android/com.android.internal.app.ResolverActivity")
in.SetType("application/pdf")
in.Flags = 1
StartActivity(in)
End Sub
Thanks in advance !!!!