Printing a Browser Widget

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Printing a Browser Widget

Post by kdjanz » Tue Mar 26, 2019 1:10 am

Mac on Mojave, LC Community 8.2.0 and 9.0.3

I have a browser widget alone on a card which displays a simple HTML text table. I clone this card 25 times while randomizing the text in the tables - all so far so good.

When I go to print the 25 randomized cards, they all appear blank when I look at them in Preview via the printing dialog. I can see the tables on the cards, but they don't seem to print. Suggestions?

I then thought that I could use the snapshot command to grab the browser and turn it into a PNG that I would then paste into a graphic that I created over the browser rectangle. I used the tutorial on creating a thumbnail and tried to set the imagedata of my image to the imagedata from the snapshot. My images all remained empty.

Any help on either approach would be appreciated.

Thanks

Kelly

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6186
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Printing a Browser Widget

Post by dunbarx » Tue Mar 26, 2019 2:08 pm

Hi.

This is an interesting question to me, because I do not use widgets.

But I made a stack with two cards, each with a browser widget that was set to the LC home page. Each card's widget worked just fine. I put a field on card 1 as well.

But when I went to print the cards, I got nothing but the field.
LC 9.0.3 Mac 10.13.4

So, anyone?

Craig Newman

bogs
Posts: 3832
Joined: Sat Feb 25, 2017 10:45 pm

Re: Printing a Browser Widget

Post by bogs » Tue Mar 26, 2019 2:28 pm

dunbarx wrote:
Tue Mar 26, 2019 2:08 pm
So, anyone?
... else that is, I have less than no clue here :mrgreen:
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2124
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Printing a Browser Widget

Post by [-hh] » Tue Mar 26, 2019 2:38 pm

Print/PrintToPDF is not supported by the browser widget.
It is on the long list of LC promises for LC 9.

But, of course, you can make a snapshot from (the rect of) the widget and print that, even very long pages:

Use "BrowserSnapshot_v015" from "Sample Stacks" or from
http://livecodeshare.runrev.com/stack/920/
shiftLock happens

bogs
Posts: 3832
Joined: Sat Feb 25, 2017 10:45 pm

Re: Printing a Browser Widget

Post by bogs » Tue Mar 26, 2019 2:52 pm

[-hh] wrote:
Tue Mar 26, 2019 2:38 pm
But, of course, you can make a snapshot from (the rect of) the widget and print that, even very long pages:
Oddly enough, when I tried just that, I got an error :?

However, I was able to export a snapshot of the general area of the widget (but only by shooting the stack). Go figure.
Selection_001.png
It is a (widget) shoot...
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2124
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Printing a Browser Widget

Post by [-hh] » Tue Mar 26, 2019 3:35 pm

That*s why I said "(the rect of) the widget".
shiftLock happens

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Printing a Browser Widget

Post by kdjanz » Tue Mar 26, 2019 3:46 pm

Could someone give me a code fragment on how you are doing the snapshot?

I tried that but the rectangle seemed to have an issue between global and window coordinates. The other issue was that the snapshot seemed to be random static - tearing of the image so that columns & rows don’t line up.

Thanks

Kelly

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2124
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Printing a Browser Widget

Post by [-hh] » Tue Mar 26, 2019 3:58 pm

Code: Select all

if there is no img "temp" then create img "temp"
put globalLoc(the topleft of widget "browser"), \
   globalLoc(the botright of widget "browser") into rct
export snapshot from rect rct to img "temp" as PNG
shiftLock happens

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Printing a Browser Widget

Post by kdjanz » Tue Mar 26, 2019 4:03 pm

Thanks!

The global additions should help.

Could you add a couple more lines to put the snapshot into an image “theImage” that I already have on the card to cover the browser widget. With the ‘wallpaper’ image covering the browser, I’m hoping I can then print the card.

Thanks

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2124
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Printing a Browser Widget

Post by [-hh] » Tue Mar 26, 2019 4:12 pm

You cannot put an image on top of a browser widget (which is a native display).

So lock screen, show the widget, do the snapshot as above (use "theImage" instead of "temp"), hide the widget, set topleft of image "theImage" to the topleft of widget "browser".
Depending on your CPU/GPU you have to "wait 10 ticks with messages" after step 2.
shiftLock happens

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Printing a Browser Widget

Post by kdjanz » Tue Mar 26, 2019 4:26 pm

i'll try that this evening when I get back to LiveCode.

Thanks for the quick help.

Kelly

bogs
Posts: 3832
Joined: Sat Feb 25, 2017 10:45 pm

Re: Printing a Browser Widget

Post by bogs » Tue Mar 26, 2019 5:12 pm

[-hh] wrote:
Tue Mar 26, 2019 3:35 pm
That*s why I said "(the rect of) the widget".
LOL ! You mean because I didn't have the parenthesis around "the rect of", that caused it to fail? I am sooooooo glad you stopped by, I don't think I'd have ever caught that one :oops:
Image

kdjanz
Posts: 142
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Printing a Browser Widget

Post by kdjanz » Tue Mar 26, 2019 5:40 pm

That belongs in the Department of Subtle! How is a newbie ever going to... <Despair>

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2124
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Printing a Browser Widget

Post by [-hh] » Tue Mar 26, 2019 6:56 pm

When writing snapshot from (the rect of) widget I meant that
   "export snapshot from widget"
is not possible, so we have to use
   "export snapshot from rect <rectangle>".

With this form <rectangle> is *always* in *global* coordinates.

So we could have a function globalRect to write

Code: Select all

export snapshot from rect globalRect(the rect of widget "browser") to img "temp" as PNG
Here is the function.

Code: Select all

function globalRect pRect
  return the globalLoc of (item 1 to 2 of pRect), \
         the globalLoc of (item 3 to 4 of pRect)
end globalRect
p.s. globalRect(the rect of this card) = the rect of this stack.
shiftLock happens

bogs
Posts: 3832
Joined: Sat Feb 25, 2017 10:45 pm

Re: Printing a Browser Widget

Post by bogs » Wed Mar 27, 2019 12:38 pm

kdjanz wrote:
Tue Mar 26, 2019 5:40 pm
That belongs in the Department of Subtle! How is a newbie ever going to... <Despair>
kdjanz, my assumption was wrong (happens :wink: )

While there are edge cases where something like that will trip you up, by the time you hit them, you will no longer be a newbie, so take heart :D
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”