B4J Question help in creating a PDF file

codie01

Active Member
Licensed User
Longtime User
Hi I have no issues, The following is sample code as done in my ABMaterial (Which rocks) website.

Step 1 create the Document Object

B4X:
    Dim PDFjetPDF1 As PDFjetPDF=CreateBasePDFDocument
   
    Dim PDFPage As PDFjetPage
    PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.Executive_PORTRAIT)
   
    Dim PDFFont1 As PDFjetFont
    PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA)
    PDFFont1.SetSize(45)

    Dim PDFFont2 As PDFjetFont
    PDFFont2.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD)
    PDFFont2.SetSize(75)
   
    Dim PDFFont2 As PDFjetFont
    PDFFont2.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD)
    PDFFont2.SetSize(75)
   
    AddTextCentered(PDFPage,PDFFont1,LabelDate,40)
    AddTextCentered(PDFPage,PDFFont1,labelContract,90)
    AddTextCentered(PDFPage,PDFFont2,LabelTypeCode,160)
    AddTextCentered(PDFPage,PDFFont2,LabelTypeSize,245)
    AddTextCentered(PDFPage,PDFFont1,LabelTypeName,310)
   
    PDFjetPDF1.Close

Step 2 Create the document "DO NOT CHANGE THE NAME OF THIS SUB"

B4X:
Sub CreateBasePDFDocument As PDFjetPDF
    Dim PDFDestination As OutputStream
    PDFDestination=File.OpenOutput(File.DirApp, itemTakesku & ".pdf", False)
    'PDFDestination=File.OpenOutput(File.DirApp, itemTakesku & ".pdf", False)

    PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
    PDFjetPDF1.SetAuthor(myUsername)
    PDFjetPDF1.SetSubject("Shelflabel")
    PDFjetPDF1.SetTitle("shelflabel")
   
    Return PDFjetPDF1
End Sub

Step Three, Sub called on PDFjetPD1.Close "DO NOT CHANGE THE NAME OF THIS SUB" you can test for creation or do something else as I have

[Code]
Sub PDFjetPDF1_CloseComplete(Success As Boolean)
    If Success Then
        page.ShowModalSheet("myModalPDF")
        Dim myModalPDF As ABMModalSheet = page.ModalSheet("myModalPDF")
        Dim myPDF1 As ABMPDFViewer = myModalPDF.Content.Component("pdf")
        myPDF1.SetDocument(File.DirApp & itemTakesku & ".pdf")
        myModalPDF.Refresh
    Else
        Log("An error has occurred and creation of the PDF document has failed")
    End If
    Return
End Sub

Kind Regards,
Philip
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Hi I have no issues, The following is sample code as done in my ABMaterial (Which rocks) website.

Step 1 create the Document Object

B4X:
    Dim PDFjetPDF1 As PDFjetPDF=CreateBasePDFDocument
  
    Dim PDFPage As PDFjetPage
    PDFPage.Initialize(PDFjetPDF1, PDFjetConstants1.PageSize.Executive_PORTRAIT)
  
    Dim PDFFont1 As PDFjetFont
    PDFFont1.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA)
    PDFFont1.SetSize(45)

    Dim PDFFont2 As PDFjetFont
    PDFFont2.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD)
    PDFFont2.SetSize(75)
  
    Dim PDFFont2 As PDFjetFont
    PDFFont2.Initialize(PDFjetPDF1, PDFjetConstants1.CoreFont.HELVETICA_BOLD)
    PDFFont2.SetSize(75)
  
    AddTextCentered(PDFPage,PDFFont1,LabelDate,40)
    AddTextCentered(PDFPage,PDFFont1,labelContract,90)
    AddTextCentered(PDFPage,PDFFont2,LabelTypeCode,160)
    AddTextCentered(PDFPage,PDFFont2,LabelTypeSize,245)
    AddTextCentered(PDFPage,PDFFont1,LabelTypeName,310)
  
    PDFjetPDF1.Close

Step 2 Create the document "DO NOT CHANGE THE NAME OF THIS SUB"

B4X:
Sub CreateBasePDFDocument As PDFjetPDF
    Dim PDFDestination As OutputStream
    PDFDestination=File.OpenOutput(File.DirApp, itemTakesku & ".pdf", False)
    'PDFDestination=File.OpenOutput(File.DirApp, itemTakesku & ".pdf", False)

    PDFjetPDF1.Initialize("PDFjetPDF1", PDFDestination)
    PDFjetPDF1.SetAuthor(myUsername)
    PDFjetPDF1.SetSubject("Shelflabel")
    PDFjetPDF1.SetTitle("shelflabel")
  
    Return PDFjetPDF1
End Sub

Step Three, Sub called on PDFjetPD1.Close "DO NOT CHANGE THE NAME OF THIS SUB" you can test for creation or do something else as I have

[Code]
Sub PDFjetPDF1_CloseComplete(Success As Boolean)
    If Success Then
        page.ShowModalSheet("myModalPDF")
        Dim myModalPDF As ABMModalSheet = page.ModalSheet("myModalPDF")
        Dim myPDF1 As ABMPDFViewer = myModalPDF.Content.Component("pdf")
        myPDF1.SetDocument(File.DirApp & itemTakesku & ".pdf")
        myModalPDF.Refresh
    Else
        Log("An error has occurred and creation of the PDF document has failed")
    End If
    Return
End Sub

Kind Regards,
Philip




Many thanks Philip, but I'm still in error ...
could you take a look at my project or send me a working project?

I'm sending my project here and the error photo, my library photo too ...
 

Attachments

  • erro.JPG
    erro.JPG
    193.1 KB · Views: 406
  • lib.JPG
    lib.JPG
    138.6 KB · Views: 368
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Fixed and working as attached :)


Still giving error
you can send me the libraries jPDFjet.jar, jPDFjet.xml, jPDFjet.html and also PDFjet.jar, which is what this problem is giving to my machine ...
I'm the latest version of B4J ...
 

Attachments

  • errro novamente.JPG
    errro novamente.JPG
    178.2 KB · Views: 345
Upvote 0

Harris

Expert
Licensed User
Longtime User
That same NoSuchMethodError Font.setSize(F)V was previously reported last week I believe...
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Libs as requested :)


It worked perfectly, thank you so much!

you saved me!

This will help a lot of people who need to generate pdf files!

Many thanks Philip (Codie01)



Attached is the pdf generated by the font that you have set, using the files you just received from sending me!
Thank you!
 

Attachments

  • my_file.pdf
    1.3 KB · Views: 444
Upvote 0
Top