B4J Question help in creating a PDF file

codie01

Active Member
Licensed 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
 

Lucas Siqueira

Active Member
Licensed 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

Lucas Siqueira

Active Member
Licensed 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

Harris

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

Lucas Siqueira

Active Member
Licensed 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

Top