This is the LAST part of my project. I am saving an image as a PDF using MBS DynaPDF. I am attempting to make the image come from a canvas. The canvas size can be adjusted, so keeping it non-reliant on the canvases size is a must. This is the hack-job that I have so far:
[code] // get picture
dim p as picture=Canvas1.Backdrop
dim x,y,w,h as Double
dim f as Double
dim dw as integer = d.GetPageWidth
dim dh as integer = d.GetPageHeight
// scale to fit the page size
f=min(dw/p.Width, dh/p.Height)
w=f*p.Width
h=f*p.Height
x=(dw-500)
y=(dh-2600)
// add image to pdf
call d.InsertPicture(p, x, y, w, h)
call
call d.EndPage
call d.CloseFile
file.Launch[/code]
I have come to the conclusion that I suck at manipulating the plug ins.
this is from project “Create PDF with Picture.rbp”:
[code] dim d as new MyDynapdfMBS
dim file as FolderItem
d.SetLicenseKey “Starter” // For this example you can use a Starter, Lite, Pro or Enterprise License
file=SpecialFolder.Desktop.Child(“Create PDF with Picture.pdf”)
call d.CreateNewPDF file
call d.Append
call d.SetSaveNewImageFormat(false) // if possible pass through
call d.SetUseTransparency(false) // no transparent color
call d.SetCompressionFilter(d.kcfFlate) // no compression
call d.SetResolution(300) // max resolution
// get picture
dim p as Picture = LogoMBS(500)
dim x,y,w,h as integer
dim f as Double
dim dw as integer = d.GetPageWidth-100
dim dh as integer = d.GetPageHeight-100
// scale to fit the page size
f=min(dw/p.Width, dh/p.Height)
w=fp.Width
h=fp.Height
x=50+(dw-w)/2
y=50+(dh-h)/2
// add image to pdf
call d.InsertPicture(p, x, y, w, h)
as you see it starts with a new dynapdf object. We call CreateNewPDF with a folderitem to start a new PDF with output to this file. Next we append a page to the PDF.
For best image compression quality, we allow pass through, set the compression to no compression (flate), limit resolution to 300 dpi and disable any transparency.
Now we get a picture, in this case form the LogoMBS function. You could of course use your canvas here (query backdrop).
Next we do some math to scale it down/up to have the size of the page minus a 100 points. This keeps a border. Now we center picture and use InsertPicture function to put it on the page.
Finally the page is closed as well as the file and we can launch it in pdf viewer.
When I try to execute the pdf, I get NilObjectException error.
[code] dim d as new MyDynapdfMBS
dim e as MyDynapdfMBS
dim file as FolderItem
d.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
file=SaveLocation.Child(Savename1+".pdf")
call d.CreateNewPDF file
call d.Append
call d.SetResolution(300) // max resolution
// no recompressing
call d.SetSaveNewImageFormat(false)
// get picture
dim p as picture=Canvas1.Backdrop
dim x,y,w,h as Double
dim f as Double
dim dw as integer = d.GetPageWidth
dim dh as integer = d.GetPageHeight
// scale to fit the page size
f=min(dw/p.Width, dh/p.Height) //This is where I am getting the NilObjectError
w=f*p.Width
h=f*p.Height
x=(dw-500)
y=(dh-2600)
// add image to pdf
call d.InsertPicture(p, x, y, w, h)
call d.EndPage
call d.CloseFile
file.Launch[/code]
Also, one thing I sometimes find problematic in starting out with the DynaPDFMBS example projects is the fact that they tend to ignore the boolean result values of the DynaPDF functions (by invoking “call”). This can make it harder to tell which function call is causing a problem in our code.
I find it helpful to replace this: call pdf.yaddayadda() with something like this: if NOT pdf.yaddayadda() then break
Also, one thing I sometimes find problematic in starting out with the DynaPDFMBS example projects is the fact that they tend to ignore the boolean result values of the DynaPDF functions (by invoking “call”). This can make it harder to tell which function call is causing a problem in our code.
I find it helpful to replace this: call pdf.yaddayadda() with something like this: if NOT pdf.yaddayadda() then break [/quote]
I marked it in my code. It is as the f=min(dw/p.Width, dh/p.Height) line.
So it looks like perhaps your canvas doesn’t have a backdrop? When it breaks in the debugger, is p NIL? Unless you’ve explicitly assigned a picture to be the canvas’ backdrop, it will be. The contents of a canvas (as drawn by your paint event code) will not create a backdrop picture.
[quote=175193:@Peter Truskier]Doh! I totally skipped over that. Sorry…
So it looks like perhaps your canvas doesn’t have a backdrop? When it breaks in the debugger, is p NIL? Unless you’ve explicitly assigned a picture to be the canvas’ backdrop, it will be. The contents of a canvas (as drawn by your paint event code) will not create a backdrop picture.[/quote]
So it is drawn by the paint event. What is the remedy?
is that for the chart project you have?
maybe you could store the picture from the chart in a property on the window, so you have it later for creating the PDF?
[quote=175205:@Christian Schmitz]is that for the chart project you have?
maybe you could store the picture from the chart in a property on the window, so you have it later for creating the PDF?[/quote]
It is for the chart project. So you suggest I store it as a picture property?
Now that it is a picture property “chart” how should I implement that into my code above?
[quote=175209:@Jeff Tullin]Need more information than that.
The method doesnt need a return type.
Whats the problem/symptom?
That method draws the image called render onto the graphics passed into the method.
As a parameter not as a return type.[/quote]
Okay, so now it is not filling in the pdf at all. Just a blank form with the DynaPDF stamp over it.
The question at this point it why am I seeing nothing?
code is as follows:
[code] dim d as new MyDynapdfMBS
dim e as MyDynapdfMBS
dim file as FolderItem
d.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
file=SaveLocation.Child(Savename1+".pdf")
call d.CreateNewPDF file
call d.Append
call d.SetResolution(300) // max resolution
// no recompressing
call d.SetSaveNewImageFormat(false)
//In the save PDF code,
dim p as picture
p = new picture (canvas1.width,canvas1.height,32)
//Then call
DoThePaint(p.graphics)
dim x,y,w,h as Double
dim f as Double
dim dw as integer = d.GetPageWidth
dim dh as integer = d.GetPageHeight
// scale to fit the page size
f=min(dw/p.Width, dh/p.Height)
w=f*p.Width
h=f*p.Height
x=(dw-500)
y=(dh-2600)
// add image to pdf
call d.InsertPicture(p, x, y, w, h)
call d.EndPage
call d.CloseFile
file.Launch[/code]
[quote=175225:@Christian Schmitz]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
[code]dim p as picture
p = new picture (canvas1.width,canvas1.height,32)
//Then call
DoThePaint(p.graphics)[/code]
with this line
dim p as picture = self.chart
and maybe it works?[/quote]
That did not seem to improve anything as the pdf is still empty other than the DynaPDF watermark.
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.
[quote=175310:@LangueR]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.