Open a pdf from a Canvas

Hi everybody

I need to open a pdf file from a canvas by clicking on it, so as i very new i do not how to do it.
There is a way to do it, and if so, might somebody help me?

Thanks in advance
Alan

folderitem.Launch method will help to open file in PDF Viewer.

http://documentation.xojo.com/index.php/FolderItem.Launch

Hi Christian

Thanks for you reply, i tried and did not works as what im really need is open the file in a pdf viewer , but from the canvas by clicking on it.
The file is already stored in my database as binary, so i do not need get it from a folder but open from a canvas.

Hope im been clear in poor english

Thanks again

you can load BLOB value from database (SQL Select and than pick Field’s stringValue). This value can be written to temp file and launched in system’s PDF viewer.

Or you use Mac’s built in functions and open PDF as picture to display first page.
Or cross platform use our DymaPDF Pro plugin to raster page as picture and show it.

Hi Christian

Many thanks, i try and will let you know!

Thanks

Hi Christian

i forgot to ask you:-))

Might you write me down some example (if you want) in order to have an idea on how to do it?

thanks for the help
Alan

Ciao Alan,

Based on example here:

[code]Dim picFile As FolderItem
picFile = GetOpenFolderItem("")

If picFile <> Nil Then
Dim pic As Picture
pic = Picture.Open(picFile)
ImageWell1.Image = pic
End If[/code]

Set Canvas1 instead of ImageWell1 and you will get page 1 of the selected PDF in your Canvas. I do not recall how to display page 2.

Is this what you’re seeking ?

Buongiorno Alan,

after re-reading your question I think I misunderstand it.

Do you wan to click in a PDF file (any PDF file) and get it opened by your application in your Canvas ?

Hi Emily

First of all many thanks for your help.

Yes i want to open any pdf file from my application by clicking on my canvas.
The file (pdf) has already been stored and is “icon” is showed when i click on the canvas.

So i like to open the file by click on it and read it using a default pdf viewer.

It is possible?

Many many thanks

Domenico

Use the shared example. Place it in the MouseDown event and all is clear.

Ask if you still have problem.

BTW: I still do not know how to read other pages.

Hi Emile
many thanks but i think Antonio find the way:

//Leggi dal db il record rs e il campo “src” il tuo sorgente pdf
dim f as FolderItem=SpecialFolder.ApplicationData.Child(FileTypes.All)
dim rs as RecordSet
dim ok as boolean

rs = TattooPictures.SQLSelect(“SELECT * FROM Fornitore WHERE ID= '”+ ListboxAseo.Cell(ListboxAseo.ListIndex, 0) +"’")

if f<>nil and f.IsWriteable then
dim b as binaryStream
try
b=BinaryStream.Create(f,true)
Catch
b=nil
end try
if b<>nil then

  b.Write rs.Field("LogoF").StringValue
  
  ok=true
end if

end if
if ok then f.Launch true

Alan,

where in your original question are-you talking about database ?

I am sorry, but I do not understand where the data base code above will have to do with pdf and canvas.

However, if you have your answer, I am happy.

Hi Emile

[quote]
Hi Christian

Thanks for you reply, i tried and did not works as what im really need is open the file in a pdf viewer , but from the canvas by clicking on it.
The file is already stored in my database as binary, so i do not need get it from a folder but open from a canvas.

Hope im been clear in poor english

Thanks again[/quote]

The code is in the Mouse Up event so when i click on the canvas will open any file showed in it.

If you are on Mac OS X :

dim f as FolderItem = SpecialFolder.Desktop.child("xmetro.pdf") dim p as picture p = Picture.Open(f) Canvas1.Backdrop = p

On PC, if you have installed the Adobe Acrobat Reader plugin, you can load a PDF into an HTMLViewer.

Our MBS DynaPDF Plugin can read and raster PDF pages cross platform.
Or PDFKit / CoreGraphics on Mac OS X only.

Hi Michel

many thanks but your solution did not work.

I do click on the canvas and nothing happen…

[quote=125226:@Alan Castellana]many thanks but your solution did not work.

I do click on the canvas and nothing happen…[/quote]

If you want this code to work in the mouseDown event, you need to use Me instead of Canvas1, and make sure the path to your PDF file is right. Try this :

Function MouseDown(X As Integer, Y As Integer) As Boolean dim f as FolderItem = GetOpenFolderItem("application/pdf") dim p as picture p = Picture.Open(f) me.Backdrop = p End Function

This way you can choose the file to open. I tested it successfully. Do not paste the first and last line, as they are already there when you add the MouseDown handler to your canvas.

Hi Michel

Ok seems logic you solution , let me try and get back to you with the result.

Many thanks for your support and patient

Regards

[quote=124300:@Alan Castellana]I need to open a pdf file from a canvas by clicking on it, so as i very new i do not how to do it.
There is a way to do it, and if so, might somebody help me?[/quote]

Here is a code that lets you choose a PDF file, it then opens it in the canvas, as well as in the default application for it. Put it into the canvas MouseDown event :

I made it into three different parts so you can cut what you do not need :

[code] //Choose a file
dim f as FolderItem = GetOpenFolderItem(“application/pdf”)

//Place the PDF in the canvas
dim p as picture
p = Picture.Open(f)
me.Backdrop = p

//Open the PDF in the default application
f.Launch[/code]