Save canvas as PDF

Is it possible to save canvas as PDF ?

You can draw in a picture, show picture in canvas and also save picture as PDF.
e.g. using MBS Xojo DynaPDF Plugin, currently in OmegaBundle.

@Christian_Schmitz Thanks Christian and without the plugin no other way to do that ?

There may be open source classes to write PDF.
But DynaPDF can do a lot…

I can neither confirm nor deny if this is coming in the next release of Xojo :roll_eyes: :wink: see number 2 here:

1 Like

One word: WHEN ??? :grinning: :grinning: :grinning:

“when it’s ready”

1 Like

I assume it will be this year as everyone talks about 2020r1…

The answer is yes.

Print the Canvas to PDF.

use the example

Var g As Graphics
Var p As PrinterSetup
p = New PrinterSetup
If p.ShowPageSetupDialog Then
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawString(“Hello World”, 50, 50)
End If
End If

replace g.DrawString with g.DrawPicture and pass your image from the Canvas…

Why i obtain a totally blank PDF ?

Var g As Graphics
Var p As PrinterSetup
p = New PrinterSetup
If p.ShowPageSetupDialog Then
g = p.ShowPrinterDialog
If g <> Nil Then

dim Pic As new Picture(ccCanvas.Width, ccCanvas.Height)
ccCanvas.DrawInto(Pic.Graphics, 0, 0)

End If
End If

How do you draw the image into ccCanvas.Graphics ?

Or was it in ccCanvas.Backdrop ?

and for your line:
remove it from the print line and try there.
Watch in the debugger where it is / what’s in Pic / ccCanvas…

Emile thanks for you help
I should create a new Picture in Open Canvas Event taking the backdrop of the Canvas and then print that Picture?
I’m trying it (and also try to understand the debugger result) … but i’m totally lost :weary:

In the open event of the canvas
Var picToPrint As New Picture(Me.Width, Me.Height)
Me.DrawInto(picToPrint.Graphics, 0, 0)
me.Backdrop = picToPrint

in the Print line
g.DrawPicture (picToPrint, 0, 0)

[quote=“Fabrizio_Cesare, post:12, topic:55108”]

How do you place data into this Canvas ?

and in the code above, why do you want to put whats in picToPrint.Graphics into picToPrint.Backdrop ?

Back to your question.

Add a button to load an image and display it into picToPrint.Backdrop,
in the Print code, pass picToPrint.Backdrop to it:
g.DrawPicture picToPrint.Backdrop,0,0

as the g.DrawString … code replacement in the LR code shared earlier.

Even if is this year, usually first time xojo has a new feature is mear unusable and with a lot of bugs, so, never wait for a feature.

There are many third party plug ins for pdf like

One last:

load a Picture into picToPrint.Backdrop, then execute the code below:

[quote=“Emile_Schwarz, post:9, topic:55108”]
Var g As Graphics
Var p As PrinterSetup
p = New PrinterSetup
If p.ShowPageSetupDialog Then
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawPicture picToPrint.Backdrop,0,0
End If
End If[/quote]

On macOS, click in the button PDF (Bottom/Left) and choose to save to disk,
give a file name,
you’re done (load it in Preview)
Or choose the first option: display in Preview…

If you are in Windows, choose the pdf printer.

In case of trouble (no image), try with a small image,
quit all applications if some are running,

Of course, having code that works is one thing,
but if you do not know how to create a pdf in Windows 10 / macOS, try learning that.

Same for the image to print:
it must not be 100MB (and if it is, start with a far small image).

If this code do not works,
Before the above code:
create (you know how) a Picture in one line (MyPict),
add the picToPrint.Backdrop into it
and in the code above, use:
g.DrawPicture MyPict,0,0

Also, you have to learn how to use the debuger: this will allow you to know what works / how it works and what do not works.

ROME was not built in one day.

If I want to learn about MADRID, it will takes me a long time too (even if I already know some other cities).

Being polyglot lower the learning curve, only lower the leaning curve: there is still many things to learn… some words are male in a language and can be female in another. And I do not talk about false friends…

The code below comes from (above) a button I add into one of my projects; I only changed the Canvas name and was able to create a PDF with the image that is stored in the cCover.Backdrop by my project.

Xojo 2019r3.1
macOS Catalina

No magic, no mystery, only read the LR (or this clue entry). :wink:

Sub Action() Handles Action
Var g As Graphics
Var p As PrinterSetup
p = New PrinterSetup
If p.ShowPageSetupDialog Then
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawPicture cCover.Backdrop,0,0
End If
End If
End Sub

cCover is a Canvas and have an image in its backdrop…

1 Like

At design interface in Canvas > Appearence > Backdrop i insert my Pic (added to my project).
It’s 700x900 and make at design the same Canvas size.
In open event (of my Canvas) i insert this code
Var printD As New Picture(Me.Width, Me.Height)
Me.DrawInto(printD.Graphics, 0, 0)
me.Backdrop = printD

I’ve understood that i need to create a new Picture from my Canvas
And finally in print code i insert:
g.DrawPicture cCanvas.Backdrop, 0, 0

So the pdf now is shown partially some part of the pic is not shown.
Re-reading all your kind suggestions (and trying to understand all the LR) i see that i continue not to understand where i’m wrong (and at this point i know i should have all clear … :flushed: but that’s it).

I’ve also deleted all the code in the open event of my canvas (in effect my pic is loaded at design and in your last suggestion seems you said that it’s the solution … ), but nothing is passed at print code …

I see that insert a breakpoint here:
g.DrawPicture cCanvas.Backdrop, 0, 0
the g value is 559, 773 so that should be the issue …

How can it be goes far away from my understanding.

Did you use my code as is (with a dedicated Canvas holding an image in .Backdrop) ?

As I wrote earlier, I fired Xojo 3.1 and checked there: it worked fine (generate the pdf with the image).

Is THIS working ?

No unfortunately not works.
I’ve created a little project (with the pic i’m using) and it shows that not works … if you’ve time / wants to take a look i’ll really appreciate that.