Print a file?

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Print a file?

Post by bogs » Sat Mar 06, 2021 9:11 pm

I know you can print a card, stack, or a field (or at least the text of a field), is there a way to print a file (image file) or, alternately, is there a way to print an image (either on a card or not on a card)?
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: Print a file?

Post by dunbarx » Sun Mar 07, 2021 12:10 am

Bogs.

If the image is on the card, why not just print the card?

If it is not on the card, do you mean to open an image file in some form of "app" and print from there? On a Mac, for example, I could open a screenshot in "preview" and print.

Craig

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

Re: Print a file?

Post by bogs » Sun Mar 07, 2021 10:30 am

Perhaps my description was too vague, that was unintended. I'll try for a bit better, since your reply intimates it is not possible.

I have a rather long list of readings in a field that has table / non table elements and colors. This is a picture (without a colored entry) of how the field looks -

Image

Printing the card, the field includes the scrollbar, printing the text of the field does not, but the text sits right at each line and all formatting (looks) gets lost completely.

For comparison, this is printing the field to .ps (printer paper looks exactly the same) and of course, aside from 'reading' and the lines looking too close to the edge, no colors (Yes, I tried the htmlText, but that caused other problems) -

Image

My initial forray was to print the card, however, since I've never used printing previously, I was under the mistaken impression about what that meant, and the result.....well, let's just say that it is not what I was looking for.

Studying printing some more, I found you *could* print a field, which would have worked out fine I think, however, what came out (in .ps or actual printer or .pdf) had the numbers running into the lines of the table, which is *not* what it looks like in the program.

Eventually, I wound up exporting a snapshot of the field to a .png, and of course this looks exactly like the field does in the program retaining colors, spacing, etc, however, I am unable to figure out how to send that to a printer whether the .png is in an image or is a file, short of launching it in an image program, which would be rather pointless.

From your answers, as I started out with, I take it you can *not* print a file (I find that surprising), and apparently you can't print an image like you can a field (which I would also find surprising).

I really need to stop being so surprised I guess.

So I take it that the only way to print an image would be to put it on a separate card and make it fully the size of the image, then print the card after turing it white so it doesn't look like your printing a card, is that it? If I understood all I read, you don't need the card or image to be visible, you just need them to exist?

Also, are there other 'gotchas' I should be aware of? Will a single card print over multiple sheets? Do I need to manually set the scale, or does the printing occur at 1:1 and flow to the next page? Those questions came from my reading, but I'm not sure I understood the descriptions properly.

I'm also not sure why you can't just send a file to the printer, since a few of the parameters suggest it will take a 'container' argument, and after all, a file is just a container.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Print a file?

Post by jacque » Sun Mar 07, 2021 5:49 pm

It sounds like you want:

Code: Select all

print <card> from <topLeft> to <bottomRight>
where the described rectangle surrounds the area of interest.

Unlike printing a field, this gives you a bitmap which should capture colors and /or images. Printing can be as easy or complicated as you want. Using some of the other commands can give you exacting control over the printed results.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: Print a file?

Post by dunbarx » Sun Mar 07, 2021 6:01 pm

Bogs.

Is it possible to solve all your problems by simply specifying the rectangle in which to print? Check out the "print"
command, with its two parameters. This would lose the scrollbar, and I got from your post that this was an issue.

But basically, if you can create, on a card, an "image" of what you want the final printed document to look like, I still don't see why you cannot use the built-in LC print tools to do it. This might take some fooling around, hiding controls or parts of controls, overlaying, whatever. And maybe this is just too much, er, fooling around.

Others may chime in with a simple solution regarding printing "externally".

Craig

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Print a file?

Post by SparkOut » Sun Mar 07, 2021 7:19 pm

The change in view of the text kerning/rendering sounds like a case of what the "formatForPrinting" command was created for on Windows, which I'm assuming you're not using.
But whether I set it or not on my Windows system I can output to pdf or printer and the view looks fine if I use "revPrintField" which shows gridlines and text colours of a scrolling field but without the scrollbar.
If that really isn't working for you, then I would create a substack for printing, go invisible to the printing substack, and use that to place the image snapshot, then print the substack's card. A few tweaks like Craig says, and you should be able to do this fine.

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

Re: Print a file?

Post by bogs » Sun Mar 07, 2021 9:34 pm

First off, thank you everyone who chimed in.

I'll reply in reverse order, since it will be easier to track for me that way :D
SparkOut wrote:
Sun Mar 07, 2021 7:19 pm
The change in view of the text kerning/rendering sounds like a case of what the "formatForPrinting" command was created for on Windows, which I'm assuming you're not using.
Your assumption is correct, the program was made (and runs) on 'nix currently. I came across formatForPrinting before I posted, heh, as well I read about -
print

print card (cut off the picture at the limit of the cards size)
bogs wrote:My initial forray was to print the card, however, since I've never used printing previously, I was under the mistaken impression about what that meant, and the result.....well, let's just say that it is not what I was looking for.
printField (2nd picture in the last post of mine)
bogs wrote: I found you *could* print a field, which would have worked out fine I think, however, what came out (in .ps or actual printer or .pdf) had the numbers running into the lines of the table, which is *not* what it looks like in the program.
printText (looked much worse than printField, obviously no formatting of the text, certainly no colors)

printHtml (printed the text clearly, and the bold, but no colors or table, and I didn't see how to insert a table in html in Lc in the html section of recognized symbols)

print from <TL> to <BR> (which give a picture of the field alright, but if the field is long enough only prints to the bottom of page 1 and cuts off instead of going to the next printing page)

That last one did surprise me a bit, especially if Lc is using the OS's printer driver, I'd have thought that you'd just send the information, the printer would spit out pages until it is done. What do I know ?
SparkOut wrote:
Sun Mar 07, 2021 7:19 pm
If that really isn't working for you, then I would create a substack for printing, go invisible to the printing substack, and use that to place the image snapshot, then print the substack's card. A few tweaks like Craig says, and you should be able to do this fine.
Thank you for confirming -
bogs wrote:So I take it that the only way to print an image would be to put it on a separate card and make it fully the size of the image, then print the card after turing it white so it doesn't look like your printing a card, is that it? If I understood all I read, you don't need the card or image to be visible, you just need them to exist?
Now if you (or anyone else) can answer the 2nd part of that...
Also, are there other 'gotchas' I should be aware of? Will a single card print over multiple sheets? Do I need to manually set the scale, or does the printing occur at 1:1 and flow to the next page? Those questions came from my reading, but I'm not sure I understood the descriptions properly.
... then I may be in business :D
dunbarx wrote:
Sun Mar 07, 2021 6:01 pm
But basically, if you can create, on a card, an "image" of what you want the final printed document to look like, I still don't see why you cannot use the built-in LC print tools to do it.
Yah, see, from every other rad language I've used, I thought this would be dead easy here. In Delphi, this was literally 1 to 2 lines of code *IF* that, just to print something (file, field, whatever). Maybe I just expect too much.

If you lasted this far, the print is of a field that is already formatted how it should look on the printed page. From the testing I've completed so far, it looks like an image is going to be the last output before printing. This image maybe be several pages long, I sure hope I don't have to specify where page breaks go on top of everything else?
jacque wrote:
Sun Mar 07, 2021 5:49 pm
It sounds like you want:

Code: Select all

print <card> from <topLeft> to <bottomRight>
where the described rectangle surrounds the area of interest.

That would be great, but I couldn't find a way to accommodate the way printing seems to work here. Just to save some (of you all's) time, I found out how to set margins, open the printer dialog, open (or not) the settings dialog and stuff like that already and have a pretty firm grasp on those topics.

At this point, all I have left to figure out is how to span the image over multiple pages, cause just like the TL to BR bit, I only get 1 full page of the image on paper. The whole image is there heh, and if I run it from an image software I could print it over as many pages as I need.
Image

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Print a file?

Post by SparkOut » Sun Mar 07, 2021 10:37 pm

I'm still unsure what your problem is with revPrintField - whether it's the age of the version you're using, a problem on *nix, or syntax/settings in your printing commands.

If I make a big field with scrollbar and put lots of random stuff in it, some words with formatting (red, bold) and gridlines (not a basic table field) and

Code: Select all

open printing with dialog
   revPrintField (the name of field "testPrintStuff")
close printing
I can pick the print destination and choose my home printer, or as attached, print to MS pdf. It automatically spans over multiple pages. The file is attached (and looks the same on the paper output). Didn't even need to play with formatForPrinting.
I added a fake ".zip" extension to the filename to be able to upload here - it's NOT zipped. Just rename it to delete the .zip and leave as .pdf
Attachments
test revPrintField.pdf.zip
This is not a zip file, it's a pdf. Just delete the fake extension
(184.27 KiB) Downloaded 204 times

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

Re: Print a file?

Post by bogs » Sun Mar 07, 2021 10:55 pm

Well, I dunno what is up with it on here either. Certainly it could be the version I'm using, although I only tested up to 6.7.11, but I don't believe so, for a LOT of reasons. It could also be a 'nix thing, but I doubt that as well.

Aside from the things I mentioned above, it also didn't print the whole field (cut off several lines or, I suspect, only printed the actual size of the field, not by the amount of text in it) AND had no colors.

It did better than printText at not running everything into the lines of the table (yes, this is a constructed table, not a cells modified table).

Oh well.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Print a file?

Post by jacque » Mon Mar 08, 2021 8:30 pm

I spent a good deal of time creating printing templates for a project about 10 years ago, which should fit into your setup pretty well. :) However, my app printed on Mac and Windows, and I have a vague recollection that printing is somewhat different on 'nix so it may very well be your hardware.

If you want a straightforward printout then the revPrintField handler should work; it does on Mac and Windows. If you examine that script you will see all the things you need to account for, because aside from a plain "print card" command, you need to manage most of the printer behavior. You will also need to account for printer margins -- the part of the paper where the printer cannot lay down ink -- and how it corresponds to 1) the space along the edges of the card where your objects are placed, and 2) the margins you set for the printout. I.e, if you set a 1-inch margin and the left edge of the field is 72 pixels in from the left of the card, the printout will have a 2-inch margin. If the printer cannot print within a 1/4" of the paper edge, then you will have a 2.25-inch margin.

When printing a field that is longer than the height of the card, you need to use the pageHeights property (see the dictionary.) Basically that tells you how much text will fit on a page. You run a loop that prints the card, scrolls the field to the next line in the pageHeights, print the card again, and so forth until all the text has been sent to the printer.

RevPrintField manages all this for you. If it isn't working on your setup you'll need to do it yourself.

In my project, I set up a substack where each card is a printing template for the report I needed to print. This included images, fields, and other objects placed where they should appear on the paper. Objects that needed to be at the left-most side of the printout were placed at the very edge of the card so that the printmargins did not need to account for any extra space inside the card itself. Ditto for top margin; remember that the printer will provide its own margin (generally printers can't print within 1/2" from the top of the paper). Place top objects as near the top of the card as possible, knowing there will be at least a half-inch of paper above it plus whatever you specify as the top printmargin.

If you can test revPrintField from one of your Mac or Windows VMs I think things will be a lot easier. I used to charge clients extra for every print template I had to create because it is exacting work -- but you get much more polished results if you do handle it yourself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Print a file?

Post by bogs » Mon Mar 08, 2021 9:00 pm

jacque wrote:
Mon Mar 08, 2021 8:30 pm
When printing a field that is longer than the height of the card, you need to use the pageHeights property (see the dictionary.) Basically that tells you how much text will fit on a page. You run a loop that prints the card, scrolls the field to the next line in the pageHeights, print the card again, and so forth until all the text has been sent to the printer.
LOL!! You'll never guess what I was reading this morning....
Image
Frightening, isn't it? If you keep having similar thought lines to mine, I may have to recommend institutionalization ! (Come on in, the straight jackets are fine! :shock: )

I want to thank you for the lengthy reply, though, it cleared up a few things I was unable to find anywhere else, at least in a way that I understood it.
jacque wrote:
Mon Mar 08, 2021 8:30 pm
If you can test revPrintField from one of your Mac or Windows VMs I think things will be a lot easier.
Well, if it were going to eventually run on either of those platforms, I might just do that since, as you might guess, I try to make sure things look and work the same no matter where it is destined to run. In this case, though, the program is solely for myself and I don't run on either of those two platforms.

Putting that another way, lets say that (as SparkOut's testing indicates) it works PERFECTLY on either other desktop. It would not be of any help to me for the issues I'm seeing, as (ultimately) it is only going to be deployed here. In point of fact, the printing part of this is the least important part, but I figured I'd make use of this to start exploring it.

As far as 'revPrintField' alone goes, I had hoped it would work out but it absolutely does not in the versions I've run it in so far. I could live with the numbers being close to the lines, but the coloring isn't just for looks and it's lack of ability to include that part of it in this setup makes it a no go.

I'll be fooling around with pageHeights the rest of the day looks like, Thanks again for the information, to all that have replied. i'm also looking into printCommand ('nix only) which should circumvent most of the madness I think, since I can then print the file directly without the rest of this stuff getting in the way ;)
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Print a file?

Post by jacque » Mon Mar 08, 2021 9:33 pm

bogs wrote:
Mon Mar 08, 2021 9:00 pm
Frightening, isn't it? If you keep having similar thought lines to mine, I may have to recommend institutionalization ! (Come on in, the straight jackets are fine! :shock: )
Well, if we get good enough at it, I may not have to post here at all.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Print a file?

Post by bogs » Mon Mar 08, 2021 9:35 pm

jacque wrote:
Mon Mar 08, 2021 9:33 pm
bogs wrote:
Mon Mar 08, 2021 9:00 pm
Frightening, isn't it? If you keep having similar thought lines to mine, I may have to recommend institutionalization ! (Come on in, the straight jackets are fine! :shock: )
Well, if we get good enough at it, I may not have to post here at all.
That won't work, I'd have to have you picked up as a 'Missing Person' :P
Image

Post Reply