Printing file images on Windows and Mac a Solution

On the Windows and Mac platforms there is no direct method of printing an image from a file in LiveCode.

In Linux you can shell out to the printer directly.

e.g. put shell(“lpr  myfile.jpg”)

In Widows you can print a text file from the command prompt but an image!

e.g. print c:\file.txt /c /d:lpt1

LiveCode does however allow you to print the rect of a card.

So here is my workaround (solution) for this problem.

We employ the use of two stacks.

PrintControl.livecode & PrintData.livecode

PrintControl

PrintControl allows you to drag an image into a preview area.

The dragged image if first sent to an image holder on the ImageToPrint card of the PrintData stack then the preview is created. The width and height of the PrintData stack is then scaled to match the new image.


on dragDrop
set the filename of image "ImageToPrint" of stack "PrintData" to the dragData["files"]
set the filename of me to the dragData["files"]
if there is a stack "PrintData" then
set the height of stack "PrintData" to the height of image "ImageToPrint" of stack "PrintData"
set the width of stack "PrintData" to the width of image "ImageToPrint" of stack "PrintData"
set the top of image "ImageToPrint" of stack "PrintData" to 0
set the left of image "ImageToPrint" of stack "PrintData" to 0
end if
end dragDrop

on dragEnter
put empty into me
set the dragAction to "copy"
end dragEnter

The Print button on the PrintControl stack opens the print dialogue and prints the ImageToPrint card of the PrintData stack.


on mouseUp
if there is a stack "PrintData" then
answer printer
if the result is "Cancel" then
exit mouseUp
end if
open printing
if the result is not "Cancel" then
print card "ImageToPrint" of stack "PrintData"
close printing
end if
else
answer "PrintData stack not found" with "OK"
end if
end mouseUp

The Reset button just loads up default images into both stacks.

Note> in production the PrintData stack should be hidden or moved off screen.

See the openCard of card Main of stack PrintControl.


--reset start images for both stacks
on openCard
if there is a stack "PrintData" then
--set the visible of stack "PrintData" to false --comment out for testing
end if
send "mouseUp" to button "Reset"
end openCard

--reset start images for both stacks
on mouseUp
put image "DragHere" into image "ThumbImage"
if there is a stack "PrintData" then
put image "PrintDefault" of stack "PrintData" into image "ImageToPrint" of stack "PrintData"
set the height of stack "PrintData" to the height of image "ImageToPrint" of stack "PrintData"
set the width of stack "PrintData" to the width of image "ImageToPrint" of stack "PrintData"
set the top of image "ImageToPrint" of stack "PrintData" to 0
set the left of image "ImageToPrint" of stack "PrintData" to 0
end if
end mouseUp

PrintData.zip Download    (downloaded 24 times)