Android Question Open and Save a PDF File In the Database with App.

Discussion in 'Android Questions' started by Lowegaterecords, Nov 15, 2018.

  1. Lowegaterecords

    Lowegaterecords Member Licensed User

    Hi I'm trying to select a pdf file in the device with the Chooser as it happens with the images, but without success. My intent is to select a pdf through my app and then save it in the db of the app. I'm using SqlLite for the db. I'm using the chooser specifying the type of file to be selected but the pdfs on the device are not selectable, maybe you miss the file type header? And I was wondering if you need to use the BLOB to save it in the db? Thanks to the availability.


    Code:
    Sub Process_Globals

    Dim Chooser As ContentChooser
    Dim pdf As PDFRenderer

    End Sub

    Sub ImageViewAggPDF_Click

        Chooser.Initialize(
    "chooser")
        Chooser.Show(
    "pdf/*","Select an Pdf")
        
    ToastMessageShow("Select PDF",True)

    End Sub


    Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
     
        
    If Success Then
         
        pdf.Initialize(
    File.DirRootExternal,Dir,FileName)

        ImageViewResult.Bitmap=pdf.renderPageforDisplay(
    1)
     
     
        
    Else
            
    ToastMessageShow("No PDF SELECT",True)
        
    End If
     
     
    End Sub
     
    Last edited: Nov 15, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    This is a community forum. Please don't limit your questions to a single member.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
     
        
    If Success Then
        
            
    Dim data() As Byte = File.ReadBytes(Dir, FileName)
            
    SQL.ExecNonQuery2("INSERT INTO table1 VALUES(?)"Array(data))
     
        
    Else
            
    ToastMessageShow("No PDF SELECT",True)
        
    End If
     
     
    End Sub
     
  4. Lowegaterecords

    Lowegaterecords Member Licensed User

    Thanks Erel, which library should I add for the (ReadBytes)?
    The problem is that when I open the Chooser the pdf files are not selectable.
     
    Last edited: Nov 15, 2018
  5. Lowegaterecords

    Lowegaterecords Member Licensed User

    Guys anyone know how to set the Mimi type of the Chooser to make the PDF files selectable on the device?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Lowegaterecords likes this.
  7. Lowegaterecords

    Lowegaterecords Member Licensed User

    Thanks, Erel very clear, I'm having problems with the chooser, it seems that even setting the type of file to look for (Pdf) does not work files on my device displays them but are not selectable. Where am I doing wrong?
    Code:
    Sub ImageViewAggPDF_Click

        Chooser.Initialize(
    "Chooser")
        Chooser.Show(
    "pdf/*","Select an Pdf")
        
    ToastMessageShow("Select PDF",True)

    End Sub
     
  8. DonManfred

    DonManfred Expert Licensed User

    Show has Mime as the first argument. "pdf/*" is not a mimetype.
    Try "application/pdf"
     
    Lowegaterecords likes this.
  9. Lowegaterecords

    Lowegaterecords Member Licensed User

    Thanks DonManfred Solved it was so simple! Now I'm trying to load with the method AddTwoLinesAndBitmap all the pages of the pdf file in a listview but I can not increase the i in the for loop, where am I wrong?
    Code:
    Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
         
           
         
    If Success Then
           
            
    File.Copy(Dir,FileName,File.DirInternalCache,"PdfFile.pdf")
            pdf.Initialize(
    "",File.DirInternalCache,"PdfFile.pdf")
           
           
    Dim ImagePage As ItemSet 'Variable Type
           
           
    For i = 0 To pdf.PageCount -1
           
                 ImagePage.Picture= pdf.renderPageforDisplay(i)
                 ListViewCountPage.AddTwoLinesAndBitmap2(
    "","",ImagePage.Picture,ImagePage)
           
           
    Next
        
    Else
            
    ToastMessageShow("No PDF SELECT",True)
        
    End If
     
     
    End Sub
     
  10. DonManfred

    DonManfred Expert Licensed User

    Away from that i not fully understand your code
    What is ItemSet? Shouldn´t it be DIMmed and initialized inside the loop?

    You should always create a new thread for ANY new question.
     
    Lowegaterecords likes this.
  11. Lowegaterecords

    Lowegaterecords Member Licensed User

    We apologize for the complete global variable code.


    is a type variable (String, String, Picture) for the listview with the AddTwolinesAndBitmap method
    Code:
    Sub Globals

    Type ItemSet (FristRow As String,ScondRow As String, Picture As Bitmap)

    End Sub



    Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
       
         
         
    If Success Then
         
            
    File.Copy(Dir,FileName,File.DirInternalCache,"PdfFile.pdf")
            pdf.Initialize(
    "",File.DirInternalCache,"PdfFile.pdf")
         
           
    Dim ImagePage As ItemSet 'Variable Type
         
           
    For i = 0 To pdf.PageCount -1
         
                 ImagePage.Picture= pdf.renderPageforDisplay(i)
                 ListViewCountPage.AddTwoLinesAndBitmap2(
    "","",ImagePage.Picture,ImagePage)
         
           
    Next
        
    Else
            
    ToastMessageShow("No PDF SELECT",True)
        
    End If
     
     
    End Sub
     
  12. DonManfred

    DonManfred Expert Licensed User

    Code:
    Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
     
       
         
    If Success Then
       
            
    File.Copy(Dir,FileName,File.DirInternalCache,"PdfFile.pdf")
            pdf.Initialize(
    "",File.DirInternalCache,"PdfFile.pdf")
       
       
           
    For i = 0 To pdf.PageCount -1
                 
    Dim ImagePage As ItemSet 'Variable Type (Dim inside loop)
                ImagePage.initialize   
                 ImagePage.Picture= pdf.renderPageforDisplay(i)
                 ListViewCountPage.AddTwoLinesAndBitmap2(
    "","",ImagePage.Picture,ImagePage)
       
           
    Next
        
    Else
            
    ToastMessageShow("No PDF SELECT",True)
        
    End If
     
     
    End Sub
    PD: It is not a good idea to use thumbnails like this. You´ll ran into OOM errors fast i guess.
     
  13. Lowegaterecords

    Lowegaterecords Member Licensed User

    The idea is to create a view as it happens with the images, the thumbnails are resizable and adaptable to the screen, I do not understand why it does not work so not from errors, but does not load the images in the listview. I try to add pages one at a time.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice