Picture on PDF

Something like

call d.SetFont "Times", pdf.kfsNone, 18.0, true, pdf.kcp1252 call d.WriteText 25.0, 50.0, "Hello world"

No it is just making it for all of the different file numbers.

Rather than doing:

[code] 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
[/code]

What else can/should I do?

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

Rather than doing :

[code] 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
[/code]

Ect. ect. ect. for 36 assets

what can/should I do?

  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.

[quote=175420:@Christian Schmitz]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.[/quote]

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

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.

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.

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

[code]//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[/code]

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

[code]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[/code]

example based on your info
https://dl.dropboxusercontent.com/u/42062295/RealSoftware/forum%20-%20canvas%20picture%20to%20pdf_2.rbp

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.rdS.com/gpdf/

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

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