Picture on PDF

  1. ‹ Older
  2. 5 years ago

    @ChristianSchmitz so you have a property "chart as picture" on the window and fill it when you update the chart in the canvas?
    great, so next

    you replace the lines

    dim p as picture
          p = new picture (canvas1.width,canvas1.height,32)
          
          //Then call
          
          DoThePaint(p.graphics)


    with this line

    dim p as picture = self.chart

    and maybe it works?

    That did not seem to improve anything as the pdf is still empty other than the DynaPDF watermark.

  3. Christian S

    19 Mar 2015 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    did you debug it? is chart variable filled in that code?
    What does the math give on coordinates?

  4. Edited 5 years ago

    @ChristianSchmitz did you debug it? is chart variable filled in that code?
    What does the math give on coordinates?

    With the code, the p variable gives "Nil", so it is receiving nothing.

    With Jeff's code, the p variable returned a picture.

    Height adjusts based on the width and height of the window.

    In the standard setup, the height is 304 and the width is 861

  5. The following is a crude example following Jeff's and Christian's suggestions. It is probably not the greatest since I still struggle with the Canvas and Picture objects, but it does work.

    https://dl.dropboxusercontent.com/u/42062295/RealSoftware/forum%20-%20canvas%20picture%20to%20pdf.rbp

  6. @LangueRodriguez The following is a crude example following Jeff's and Christian's suggestions. It is probably not the greatest since I still struggle with the Canvas and Picture objects, but it does work.

    https://dl.dropboxusercontent.com/u/42062295/RealSoftware/forum%20-%20canvas%20picture%20to%20pdf.rbp

    That worked with a little tweeking. Thank you so much. Now it is just adding additional text to the file. How would I accomplish that?

  7. Jeff T

    20 Mar 2015 Pre-Release Testers Midlands of England, Europe

    Something like

     call d.SetFont "Times", pdf.kfsNone, 18.0, true, pdf.kcp1252
      call d.WriteText 25.0, 50.0, "Hello world"
  8. No it is just making it for all of the different file numbers.

    Rather than doing:

      if NumberofFiles = 1 then
        
        dim d1 as new MyDynapdfMBS
        dim e1 as MyDynapdfMBS
        dim file1 as FolderItem
        
        d1.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file1=SaveLocation.Child(Savename1+".pdf")
        
        call d1.CreateNewPDF file1
        call d1.Append
        
        call d1.SetUseTransparency(false) // No transparent color
        call d1.SetCompressionFilter(d1.kcfFlate) //no Compression
        call d1.SetResolution(300) // max resolution
        
        // get picture
        dim x1,y1,w1,h1 as integer
        dim dw1 as integer = d1.GetPageWidth-100
        dim dh1 as integer = d1.GetPageHeight-100
        
        // scale to fit the page size
        
        w1=550
        h1=200
        
        x1=50+(dw1-w1)/2
        y1=50+(dh1-h1)/2
        
        // add image to pdf
        call d1.InsertPicture(p, x1, y1, w1, h1)
        
        call d1.SetFont "Times", d1.kfsNone, 12.0, true, d1.kcp1252
        call d1.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d1.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d1.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d1.WriteText 25.0, 280.0, TextField50.text +" "+ TextField1.text +" "+ TextField2.text +" "+ TextField62.text
        call d1.WriteText 25.0, 260.0, TextField3.text +" "+ TextField4.text
        
        call d1.EndPage
        call d1.CloseFile
        
        
        
        
      elseif NumberofFiles = 2 then
        
        // File 2
        
        dim d2 as new MyDynapdfMBS
        dim e2 as MyDynapdfMBS
        dim file2 as FolderItem
        
        d2.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file2=SaveLocation.Child(Savename2+".pdf")
        
        call d2.CreateNewPDF file2
        call d2.Append
        
        call d2.SetUseTransparency(false) // No transparent color
        call d2.SetCompressionFilter(d2.kcfFlate) //no Compression
        call d2.SetResolution(300) // max resolution
        
        // get picture
        dim x2,y2,w2,h2 as integer
        dim dw2 as integer = d2.GetPageWidth-100
        dim dh2 as integer = d2.GetPageHeight-100
        
        // scale to fit the page size
        
        w2=550
        h2=200
        
        x2=50+(dw2-w2)/2
        y2=50+(dh2-h2)/2
        
        // add image to pdf
        call d2.InsertPicture(p, x2, y2, w2, h2)
        
        call d2.SetFont "Times", d2.kfsNone, 12.0, true, d2.kcp1252
        call d2.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d2.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d2.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d2.WriteText 25.0, 280.0, TextField51.text +" "+ TextField5.text +" "+ TextField6.text +" "+ TextField63.text
        call d2.WriteText 25.0, 260.0, TextField7.text +" "+ TextField8.text
        
        call d2.EndPage
        call d2.CloseFile
        
        
        
        //file 1
        
        dim d1 as new MyDynapdfMBS
        dim e1 as MyDynapdfMBS
        dim file1 as FolderItem
        
        d1.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file1=SaveLocation.Child(Savename1+".pdf")
        
        call d1.CreateNewPDF file1
        call d1.Append
        
        call d1.SetUseTransparency(false) // No transparent color
        call d1.SetCompressionFilter(d1.kcfFlate) //no Compression
        call d1.SetResolution(300) // max resolution
        
        // get picture
        dim x1,y1,w1,h1 as integer
        dim dw1 as integer = d1.GetPageWidth-100
        dim dh1 as integer = d1.GetPageHeight-100
        
        // scale to fit the page size
        
        w1=550
        h1=200
        
        x1=50+(dw1-w1)/2
        y1=50+(dh1-h1)/2
        
        // add image to pdf
        call d1.InsertPicture(p, x1, y1, w1, h1)
        
        call d1.SetFont "Times", d1.kfsNone, 12.0, true, d1.kcp1252
        call d1.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d1.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d1.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d1.WriteText 25.0, 280.0, TextField50.text +" "+ TextField1.text +" "+ TextField2.text +" "+ TextField62.text
        call d1.WriteText 25.0, 260.0, TextField3.text +" "+ TextField4.text
        
        call d1.EndPage
        call d1.CloseFile
        

    What else can/should I do?

  9. Now that I have my pdf working, I need to make it for all of the assets in the group.

    Rather than doing :

     if NumberofFiles = 1 then
        
        dim d1 as new MyDynapdfMBS
        dim e1 as MyDynapdfMBS
        dim file1 as FolderItem
        
        d1.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file1=SaveLocation.Child(Savename1+".pdf")
        
        call d1.CreateNewPDF file1
        call d1.Append
        
        call d1.SetUseTransparency(false) // No transparent color
        call d1.SetCompressionFilter(d1.kcfFlate) //no Compression
        call d1.SetResolution(300) // max resolution
        
        // get picture
        dim x1,y1,w1,h1 as integer
        dim dw1 as integer = d1.GetPageWidth-100
        dim dh1 as integer = d1.GetPageHeight-100
        
        // scale to fit the page size
        
        w1=550
        h1=200
        
        x1=50+(dw1-w1)/2
        y1=50+(dh1-h1)/2
        
        // add image to pdf
        call d1.InsertPicture(p, x1, y1, w1, h1)
        
        call d1.SetFont "Times", d1.kfsNone, 12.0, true, d1.kcp1252
        call d1.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d1.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d1.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d1.WriteText 25.0, 280.0, TextField50.text +" "+ TextField1.text +" "+ TextField2.text +" "+ TextField62.text
        call d1.WriteText 25.0, 260.0, TextField3.text +" "+ TextField4.text
        
        call d1.EndPage
        call d1.CloseFile
        
        
        
        
      elseif NumberofFiles = 2 then
        
        // File 2
        
        dim d2 as new MyDynapdfMBS
        dim e2 as MyDynapdfMBS
        dim file2 as FolderItem
        
        d2.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file2=SaveLocation.Child(Savename2+".pdf")
        
        call d2.CreateNewPDF file2
        call d2.Append
        
        call d2.SetUseTransparency(false) // No transparent color
        call d2.SetCompressionFilter(d2.kcfFlate) //no Compression
        call d2.SetResolution(300) // max resolution
        
        // get picture
        dim x2,y2,w2,h2 as integer
        dim dw2 as integer = d2.GetPageWidth-100
        dim dh2 as integer = d2.GetPageHeight-100
        
        // scale to fit the page size
        
        w2=550
        h2=200
        
        x2=50+(dw2-w2)/2
        y2=50+(dh2-h2)/2
        
        // add image to pdf
        call d2.InsertPicture(p, x2, y2, w2, h2)
        
        call d2.SetFont "Times", d2.kfsNone, 12.0, true, d2.kcp1252
        call d2.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d2.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d2.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d2.WriteText 25.0, 280.0, TextField51.text +" "+ TextField5.text +" "+ TextField6.text +" "+ TextField63.text
        call d2.WriteText 25.0, 260.0, TextField7.text +" "+ TextField8.text
        
        call d2.EndPage
        call d2.CloseFile
        
        
        
        //file 1
        
        dim d1 as new MyDynapdfMBS
        dim e1 as MyDynapdfMBS
        dim file1 as FolderItem
        
        d1.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file1=SaveLocation.Child(Savename1+".pdf")
        
        call d1.CreateNewPDF file1
        call d1.Append
        
        call d1.SetUseTransparency(false) // No transparent color
        call d1.SetCompressionFilter(d1.kcfFlate) //no Compression
        call d1.SetResolution(300) // max resolution
        
        // get picture
        dim x1,y1,w1,h1 as integer
        dim dw1 as integer = d1.GetPageWidth-100
        dim dh1 as integer = d1.GetPageHeight-100
        
        // scale to fit the page size
        
        w1=550
        h1=200
        
        x1=50+(dw1-w1)/2
        y1=50+(dh1-h1)/2
        
        // add image to pdf
        call d1.InsertPicture(p, x1, y1, w1, h1)
        
        call d1.SetFont "Times", d1.kfsNone, 12.0, true, d1.kcp1252
        call d1.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d1.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d1.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d1.WriteText 25.0, 280.0, TextField50.text +" "+ TextField1.text +" "+ TextField2.text +" "+ TextField62.text
        call d1.WriteText 25.0, 260.0, TextField3.text +" "+ TextField4.text
        
        call d1.EndPage
        call d1.CloseFile
        

    Ect. ect. ect. for 36 assets

    what can/should I do?

  10. Christian S

    20 Mar 2015 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany
    1. pack code for one file in a method.
    2. Call it for each case passing parameters which differentiate the PDF
    3. remove those SetLicenseKey calls. You don't need them.
  11. @ChristianSchmitz 1. pack code for one file in a method.

    1. Call it for each case passing parameters which differentiate the PDF
    2. remove those SetLicenseKey calls. You don't need them.

    So are you suggesting I do a method "PDF1", method "PDF2", and so forth and call them in method "mConvertToPDF"?

  12. Christian S

    20 Mar 2015 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    no. A method CreatePDF which creates a PDF.

    CreatePDF "file1.pdf", param1, param2, param3

    and call it 30 times with different parameters to avoid duplicate code.

  13. Something like this. Change your mConvertToPdf method so it accepts more arguments.

    Protected Sub mConvertToPdf(p As Picture, Savename as String, TechnicianName As String, WitnessName As String, PSI As String, TotalTime As String, Text1 As String, Text2 As String, Text3 As String, Text4 As String, Text5 As String, Text6 As String)

    Where Text1 is TextField51 for file 2, and TextField50 for file 1 in your example
    Text2 is TextField5 for file 2, and TextField1 for file 1 in your example
    Text3 is TextField6 for file 2, and TextField2 for file 1 in your example
    Text4 is TextField63 for file 2, and TextField62 for file 1 in your example
    Text5 is TextField7 for file 2, and TextField3 for file 1 in your example
    Text6 is TextField8 for file 2, and TextField4 for file 1 in your example

    You then call the method with different arguments for each file you want to create.

  14. @LangueRodriguez p As Picture, Savename as String, TechnicianName As String, WitnessName As String, PSI As String, TotalTime As String, Text1 As String, Text2 As String, Text3 As String, Text4 As String, Text5 As String, Text6 As String

    So to call the parameters in this example, what would I do? Thank you so much Langue!

    //file 1
        
        dim d1 as new MyDynapdfMBS
        dim e1 as MyDynapdfMBS
        dim file1 as FolderItem
        
        d1.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
        file1=SaveLocation.Child(Savename1+".pdf")
        
        call d1.CreateNewPDF file1
        call d1.Append
        
        call d1.SetUseTransparency(false) // No transparent color
        call d1.SetCompressionFilter(d1.kcfFlate) //no Compression
        call d1.SetResolution(300) // max resolution
        
        // get picture
        dim x1,y1,w1,h1 as integer
        dim dw1 as integer = d1.GetPageWidth-100
        dim dh1 as integer = d1.GetPageHeight-100
        
        // scale to fit the page size
        
        w1=550
        h1=200
        
        x1=50+(dw1-w1)/2
        y1=50+(dh1-h1)/2
        
        // add image to pdf
        call d1.InsertPicture(p, x1, y1, w1, h1)
        
        call d1.SetFont "Times", d1.kfsNone, 12.0, true, d1.kcp1252
        call d1.WriteText 25.0, 530.0, "Tested By:  " + TechnicianNameField.text + "         Witnessed by:  " + WitnessNameField.text
        call d1.WriteText 320.0, 530.0, PSIField.text + "PSI"
        call d1.WriteText 430.0, 530.0, "Total Time: " + timelabel1.text
        call d1.WriteText 25.0, 280.0, TextField50.text +" "+ TextField1.text +" "+ TextField2.text +" "+ TextField62.text
        call d1.WriteText 25.0, 260.0, TextField3.text +" "+ TextField4.text
        
        call d1.EndPage
        call d1.CloseFile

    And if I understand you, I would have one method calling in other methods as Christian stated?

  15. Jeff T

    20 Mar 2015 Pre-Release Testers Midlands of England, Europe
    for x = 1 to numberofdocuments
    
    //set up picture and strings for document (x)
    
    call MakePdf ( p , "File" + str(x) + ".pdf", TechnicianName , WitnessName, PSI , TotalTime , Text1 , Text2 , Text3 , Text4 , Text5  , Text6)
    
    next
  16. example based on your info
    https://dl.dropboxusercontent.com/u/42062295/RealSoftware/forum%20-%20canvas%20picture%20to%20pdf_2.rbp

  17. 2 years ago
  18. Dave S

    30 May 2018 San Diego, California USA

    Another easy alternative for creating PDF documents using Xojo (macOS, Windows, Linux etc) is my gPDF class
    Its dead simple, as it uses the same syntax as you use with a Xojo canvas or picture.

    http://www.rdsisemore.com/gpdf/

  19. Sascha S

    30 May 2018 Pre-Release Testers, Xojo Pro Germany, Lower Saxony

    I can highly recommend Einhugurs PDFPlugin . Dead simple to use.

  20. Tim P

    30 May 2018 Pre-Release Testers Rochester, NY

    lol, the first one is a spam post, followed by spam post from a regular member, followed by a recommendation -_-;

or Sign Up to reply!