Android Question Problem with pdf in Printing Library

lucdrb

Active Member
Licensed User
Longtime User
Hi,

I've created a pdf with the new printing library with the PdfDocument object.
I don't have de same result with different android version and different device.

The same program on a 5.x device got the android_5.pdf file and with a android 6.0 version got the android_6.pdf

Should I forgot something ?

Thanks in advance.

Luc
 

Attachments

  • Android_5.pdf
    49.1 KB · Views: 596
  • Adroid_6.pdf
    18.7 KB · Views: 581

lucdrb

Active Member
Licensed User
Longtime User
Hi,

I've made a copy of the sub code if you need more, let me know.

Regards
Luc

B4X:
Sub CreatePdf
    Pdf.Initialize
    'Détermine le nombre de jour du mois
   
    nbrJour = DateUtils.NumberOfDaysInMonth(Special_code.MoisTextVersNum(spnMois.SelectedItem),spnAnnee.SelectedItem)
    posN = 1
    Do While posN <> nbrJour
        y= 20
        DessinePagePDF
    Loop

    Dim out As OutputStream = File.OpenOutput(File.DirRootExternal,spnHoraire.SelectedItem & "_" & spnMois.SelectedItem & "_" & spnAnnee.SelectedItem & ".pdf", False)
    Pdf.WriteToStream(out)
    out.Close
    Pdf.Close
    lblPrint.Text = Language.GetString("{0048}", "Create") & " " & spnHoraire.SelectedItem & "_" & spnMois.SelectedItem & "" & spnAnnee.SelectedItem & ".pdf"
End Sub

Sub DessinePagePDF
    Pdf.StartPage(595, 842)
        Private cuUser As Cursor = DB_requetes.GetUser
        cuUser.Position = 0
        'Ecrit la premiere ligne
        'Première colonne Jour de la semaine
        Pdf.Canvas.DrawText(cuUser.GetString("prenom_user") & " " & cuUser.GetString("nom_user"),10,y,Typeface.DEFAULT_BOLD,8, Colors.Blue,"LEFT")   
        'deuxième colonne date du jour
        Pdf.Canvas.DrawText(spnMois.SelectedItem & "-" & spnAnnee.SelectedItem,210,y,Typeface.DEFAULT_BOLD,8, Colors.Blue,"LEFT")
        'Deuxieme ligne
        y = y +20
        Pdf.Canvas.DrawText(Language.GetString("{0036}", "Arrivée"),35,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
        Pdf.Canvas.DrawText(Language.GetString("{0037}", "Depart"),205,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
        Pdf.Canvas.DrawText(Language.GetString("{0038}", "Temps"),350,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
        Pdf.Canvas.DrawText(Language.GetString("{0039}", "Rem"),420,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
        y = y +10
        Pdf.Canvas.DrawLine(2,y,593,y,Colors.Blue,4)
        Private HeureIn, HeureOut As Float
        Private compteur As Int = 0
        'Recherche tout les enregistrement pour le mois/année sélectionné
        Private cu As Cursor
        cu = DB_requetes.GetAlltempsHoraire(Special_code.MoisTextVersNum(spnMois.SelectedItem),spnAnnee.SelectedItem,spnHoraire.SelectedItem)
        For n = posN To nbrJour
            posN = n
            DateTime.DateFormat = "MM/dd/yyy"
            Private Debutjourn As Float = DateTime.DateTimeParse(Special_code.MoisTextVersNum(spnMois.SelectedItem) & "/" & Special_code.TransJMIntStr(n) & "/" & spnAnnee.SelectedItem,"00:00:00")
            Private Finjourn As Float = DateTime.DateTimeParse(Special_code.MoisTextVersNum(spnMois.SelectedItem) & "/" & Special_code.TransJMIntStr(n) & "/" & spnAnnee.SelectedItem,"23:59:59")
            'Recherche s'il y a un enregistrement temps dans la base de données
            Private result As Boolean = DB_requetes.GetAlltempshorairejour(Debutjourn,Finjourn,mpHoraire.Get(spnHoraire.SelectedItem))
            If result Then
                If cu.RowCount >= 2 Then
                For i = 0 To cu.RowCount -1 Step 2
                    cu.Position = i
                    'Vérifie que l'enregistrement en entrée correspond a la date du jour et l'imprime si OK
                    If Special_code.TransJMIntStr(DateTime.GetDayOfMonth(cu.GetString("dateheure_temps"))) =  Special_code.TransJMIntStr(n) Then
                        'Le premier enregistrement est une entrée
                        If cu.GetString("in_temps") Then
                            HeureIn = cu.GetString("dateheure_temps")
                            compteur = compteur+1
                        End If
                        cu.Position = i+1
                        'le Deuxième est une sortie
                        If  cu.GetString("in_temps") = False Then
                            HeureOut = cu.GetString("dateheure_temps")
                            compteur = compteur+1
                        End If
                       
                        If compteur = 2 Then
                            y = y + 20 'passe à la ligne suivante
                            DateTime.timeformat = "HH:mm"
                            DateTime.DateFormat = "EEEE"
                            Pdf.Canvas.DrawText(DateTime.Date(HeureIn),10,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            DateTime.DateFormat = "dd"
                            Pdf.Canvas.DrawText(DateTime.Date(HeureIn),80,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            Pdf.Canvas.DrawText("->",97,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            Pdf.Canvas.DrawText(DateTime.Time(HeureIn),110,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            DateTime.DateFormat = "EEEE"
                            Pdf.Canvas.DrawText(DateTime.Date(HeureOut),185,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            DateTime.DateFormat = "dd"
                            Pdf.Canvas.DrawText(DateTime.Date(HeureOut),245,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            Pdf.Canvas.DrawText("->",262,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            Pdf.Canvas.DrawText(DateTime.Time(HeureOut)  ,275,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            Dim per As Period = DateUtils.PeriodBetween(HeureIn, HeureOut)
                            Dim j As Int = per.Days
                            Dim h As Int = per.Hours
                            Dim m As Int = per.Minutes
                            If j > 0 Then
                                h = h + (j*24)
                            End If
                            MinuteResult = MinuteResult + (h*60) + m
                            Private tempsPasse,heur,minut As String
                            heur = Special_code.TransJMIntStr(h)
                            minut = Special_code.TransJMIntStr(m)
                            tempsPasse = heur & ":" & minut
                            Pdf.Canvas.DrawText(tempsPasse,350,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                            compteur = 0
                        End If
                    End If
                Next
                End If
            Else
                'Il n'y a pas d'enregistrement temps -> imprime la date et le jour uniquement
                y = y + 20 'passe à la ligne suivante
                'Ecrit la première colonne
                DateTime.DateFormat = "MM/dd/yyyy"
                Private NomJour As String  = DateUtils.GetDayOfWeekName(DateTime.DateParse(Special_code.MoisTextVersNum(spnMois.SelectedItem) & "/" & Special_code.TransJMIntStr(n) & "/" & spnAnnee.Selecteditem))
                DateTime.DateFormat    = "EEEE"
                Pdf.Canvas.DrawText(NomJour,10,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
                Pdf.Canvas.DrawText(Special_code.TransJMIntStr(n),80,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
            End If
            'Imprime de toute façon la sixième colonne qui est la remarque
            Private cuRem As Cursor = DB_requetes.GetRemarqueJour(Debutjourn, mpHoraire.Get(spnHoraire.SelectedItem))
            If cuRem.RowCount > 0 Then
                cuRem.Position = 0
                Pdf.Canvas.DrawText(cuRem.GetString("nom_remarque"),420,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")
            End If
        Next
        If posN = nbrJour Then
            y= y +10
        Pdf.Canvas.DrawLine(165,50,165,y,Colors.Blue,1)
        Pdf.Canvas.DrawLine(340,50,340,y,Colors.Blue,1)
        Pdf.Canvas.DrawLine(410,50,410,y,Colors.Blue,1)
        Pdf.Canvas.DrawLine(2,y,593,y,Colors.blue,4)
            y = y + 30
            Pdf.Canvas.DrawText(Language.GetString("{0047}", "Durée Tot") & " : " &  Special_code.GetHeureMinute(MinuteResult),350,y,Typeface.DEFAULT_BOLD,8, Colors.Blue,"LEFT")
            MinuteResult = 0
            Pdf.FinishPage
        End If
End Sub
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
I have some problem;

My phone and my Android Tv card diffrent size result for text.

@lucdrb ; I think problem is not andriond version 5 or 6. Problem is screen size/screen resolutions what is your screen size and resolution each device.


I thinking each devices has different text size (dip). But, why pdf lib code diffrent size!!!
@Erel how can we create same char size on pdf page with different device?
 
Last edited:
Upvote 0

lucdrb

Active Member
Licensed User
Longtime User
I found a error in the code:
I put the
/ GetDeviceLayoutValues.Scale
after the Textsize instead of the x value and all is OK

B4X:
Pdf.Canvas.DrawText(Language.GetString("{0036}", "Arrivée"),35,y,Typeface.DEFAULT_BOLD,15 / GetDeviceLayoutValues.Scale, Colors.Black,"LEFT")

Anyway, many thanks for your always valuable help

Luc
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
I see the problem. You need to divide the text size with GetDeviceLayoutValues.Scale:
B4X:
Pdf.Canvas.DrawText(Language.GetString("{0036}", "Arrivée"),35 / GetDeviceLayoutValues.Scale,y,Typeface.DEFAULT_BOLD,8, Colors.Black,"LEFT")

Thank your for reply; I will update my code.
 
Upvote 0
Top