Android Question How to make background white in PDF Renderer?

Syd Wright

Well-Known Member
Licensed User
User "KeirS" has made a nice PDF viewer wrapper: https://www.b4x.com/android/forum/threads/beta-renderpdf-a-native-android-pdf-renderer.46826/

It shows pictures very well, but texts are shown on a dark background and thus become almost unreadable. This is the case with all the PDF files that I tested.
How can the background be changed to white? The attached picture also shows what I mean.

Here is my code.

B4X:
Sub Process_Globals
    Dim PDFReader As RenderPDF
    Dim RP As RuntimePermissions
End Sub

Sub Globals
    Dim ButPrev1 As Button
    Dim ButNext1 As Button
    Dim Imageview1 As ImageView
    Dim Page1 As Long
    Dim PageCount1 As Long
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Wait For (DO_PERMISSION1(RP.PERMISSION_WRITE_EXTERNAL_STORAGE)) Complete (Result1 As Boolean)
    If Result1=False Then Activity.Finish

    File.Copy(File.DirAssets,"sample1.pdf",File.DirInternal,"Test.pdf")
    ButNext1.Initialize("ButNext1")
    ButPrev1.Initialize("ButPrev1")
    Imageview1.Initialize("ImageView1")
    Activity.AddView(Imageview1,0,0,100%x,100%y)
    Activity.AddView(ButPrev1,0,0,10%x,10%y)
    Activity.AddView(ButNext1,90%x,0,10%x,10%y)
 
    'Open PDF for Reading
    PDFReader.Initialize(File.DirInternal,"Test.pdf")
    PDFReader.RenderPageToFile(0,File.DirInternal,"TestPDF1.png")
    PageCount1 = PDFReader.GetPageCount
    Page1=0
    SHOW_PDF1(Page1)
End Sub

Sub Activity_Resume

End Sub

Sub SHOW_PDF1(PDFPage1 As Int)
    Dim b1 As Bitmap
    Dim o1 As OutputStream
 
    o1 = File.OpenOutput(File.DirInternal,"TestPDF1.png",False)
    b1.Initialize3(PDFReader.RenderPage(PDFPage1))
    b1.WriteToStream(o1,100,"PNG")
    'b1.WriteToStream(o1,100,"JPEG")
    o1.Close
    Imageview1.Color = Colors.RGB(255,255,255)
    Imageview1.SetBackgroundImage(b1)
    Log("Page Count: " & PDFReader.GetPageCount & ", Page: " & (Page1+1))
    Log("Page 1 Height: " & PDFReader.GetPageHeight(PDFPage1))
    Log("Page 1 Width: " & PDFReader.GetPageWidth(PDFPage1))
    Log("Scale For Print:" & PDFReader.GetScaleForPrint)
    PDFReader.SetRenderForPrint(True)
    Log("Render For Print:" & PDFReader.GetRenderForPrint)
    PDFReader.SetDensity(100)
    Log("Bitmap Density: " & PDFReader.GetDensity())
    'PDFReader.Close
End Sub

Sub ButNext1_Click
    If Page1>=PageCount1-1 Then Return
    Page1=Page1+1
    SHOW_PDF1(Page1)
End Sub

Sub ButPrev1_Click
    If Page1=0 Then Return
    Page1=Page1-1
    SHOW_PDF1(Page1)
End Sub

Sub DO_PERMISSION1(Permit1 As String) As ResumableSub
    RP.CheckAndRequest(Permit1)
    Wait For Activity_PermissionResult (Permit1 As String, Result2 As Boolean)
    If Result2 = False Then
      Log("No permission for: " & Permit1)
      Return False
    End If
    Log("Permission OK for: " & Permit1)
    Return True
End Sub
 

Attachments

Top