Android Question PalmoHTMLToPDF --> PDF page orientation

Javier Campo Martinez

Member
Licensed User
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:

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 !!!!
 

Javier Campo Martinez

Member
Licensed User
Hi everybody!!!
i was investigating and it's possible to use the page tag in the style section of the HTML page. i put this:
B4X:
<style>
@page {
  size: legal landscape;
}
...
</style>
... and the PDF is generated in landscape mode.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…