Spanish [SOLUCIONADO] Ver archivo PDF en mi aplicacion

edgar_ortiz

Active Member
Licensed User
Longtime User
De antemano, agradezco su tiempo.

Tengo varios archivos PDF en mi aplicación y necesito mostrarlos dentro de mi aplicacion.

alguna idea de como ver un archivo PDF dentro de mi aplicación?

Saludos,

Edgar
 

edgar_ortiz

Active Member
Licensed User
Longtime User


Gracias José, en efecto fue la base para que funcionara, por si a alguien le sirve, adjunto el codigo basado en el ejemplo de @DonManfred, tiene pequeñas modificaciones, como lo son: Muestra el numero de pagina en forma correcta, no da el error "Pdfium_onTap Not Found" y cuando el usuario "rota" el telefono, lo regresa a la ultima pagina que estaba viendo.

B4X:
'
'NOTA:
' Definir en Starter
'Dim PdfActualPage As Int = 0
'
#Region  Project Attributes
    #ApplicationLabel: PDF Viewer
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#AdditionalJar: android-pdf-viewer.aar
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: Pdfium.aar

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pdf As PdfiumCore
    Private PDFView1 As PDFView
    Private btnFirst As Button
    Private btnPrev As Button
    Private lblPages As Label
    Private btnNext As Button
    Private btnLast As Button
    Private glPages As Int
End Sub


Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    '
    pdf.Initialize("PDFium")
    File.Copy(File.DirAssets,"sample.pdf",File.DirInternal,"sample.pdf")
    
    Dim cfg As Configurator = PDFView1.fromUri(File.DirInternal,"sample.pdf")
    cfg.SetEventname("PDFium")
    cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.addOnTapListener.load

End Sub

Sub PDFium_loadComplete(pages As Int)
    Log($"PDFium_loadComplete(${pages})"$)
    glPages = pages
    lblPages.Text = $"${glPages}"$
    '
    Log(Starter.PdfActualPage)
    If Starter.PdfActualPage > 0 Then
        PDFView1.jumpTo(Starter.PdfActualPage)
        'PDFView1.jumpTo2(Starter.PdfActualPage, False)
    End If
End Sub

Sub PDFium_onInitiallyRendered(page As Int)
    Log($"PDFium_onInitiallyRendered(${page})"$)
End Sub

Sub Pdfium_onTap(event As Object)
    Log($"Pdfium_onTap(${event})"$)
End Sub

Sub PDFium_onPageChanged(page As Int, TotalPages As Int)
    Log($"PDFium_onPageChanged(${page},${TotalPages})"$)
    lblPages.Text = $"${page+1}/${glPages}"$
    Starter.PdfActualPage    = page
    Log("Actual Page:")
    Log(Starter.PdfActualPage)
End Sub

Sub PDFium_PageNum(page As Int)
    Log($"PDFium_PageNum(${page})"$)
End Sub

Sub PDFium_Show()
    Log($"PDFium_Show()"$)
End Sub

Sub Pdfium_onLayerDrawn(cnvs As Object, arg1 As Float, arg2 As Float, arg3 As Int)
    Dim jocnvs As JavaObject = cnvs ' Honestly i don´t know what we can do with it :D
    ' The Canvas is a android.view.DisplayListCanvas

    Log($"Pdfium_onLayerDrawn(${arg1},${arg2},${arg3} (Zoom = ${PDFView1.Zoom}))"$)
End Sub

Sub Activity_Resume
    Log("Activity_Resume")
    Log(Starter.PdfActualPage)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnFirst_Click
    PDFView1.jumpTo2(0,False)   
End Sub

Sub btnPrev_Click
    PDFView1.jumpTo2(PDFView1.CurrentPage-1,False)
End Sub

Sub lblPages_Click
    
End Sub

Sub btnNext_Click
    PDFView1.jumpTo2(PDFView1.CurrentPage+1,False)
End Sub

Sub btnLast_Click
    PDFView1.jumpTo2(glPages-1,False)
End Sub

Saludos,

Edgar
 

Markitos012

New Member
Que tal, copie el código del programa pero igual me pide librería y no se como se instala, alguien me podría ayudar?
 
Top