rreHardCopy - print the contents of a fld
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
rreHardCopy - print the contents of a fld
Hi,
I'm using rreHardCopy and I want to print the contents of a fld from a card. The fld is in a scroller so the contents is larger then the screen. I looked and found very little on this that's relevant. revPrintField isn't iOS compliant. Do I need to save the the contents of a fld to a PDF or a .txt file and then use "open printing to pdf"? It seems like printing a fld would have been done before. Any help will be appreciated.
I'm using rreHardCopy and I want to print the contents of a fld from a card. The fld is in a scroller so the contents is larger then the screen. I looked and found very little on this that's relevant. revPrintField isn't iOS compliant. Do I need to save the the contents of a fld to a PDF or a .txt file and then use "open printing to pdf"? It seems like printing a fld would have been done before. Any help will be appreciated.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
I'm working my way thru this along with Simon's help. Thank you again, Simon. I have a Print.livecode stack saved that gets loaded on installation. The print stack has a fld called PrintFld. The print stack is 612,792 which I believe is 8.5x11 inches, US Letter size. PrintFld is 1/4 inch all around shorter than the stack. The code below works find except the print stack size, even though it's saved at 612 x 792, is stuck at 320 x 480 so only part of the fld prints. What am I doing wrong?
Code: Select all
on mouseUp
local tPDFFile, tPrintPath
if environment() is not "mobile" then exit mouseUp
put fld "Routine_List" into tWhat2Print
put specialFolderPath("Documents") & "/Print.livecode" into tPrintPath
if there is a stack tPrintPath then -- "Print stack is there"
open invisible stack tPrintPath
set the height of stack tPrintPath to 792
set the width of stack tPrintPath to 612
## This returns 320 x 480
answer "Stack Height" && the height of stack tPrintPath && "Stack Width" && the width of stack tPrintPath
## This returns the size of the fld as saving in the print stack
answer "Fld Height" && the height of fld "PrintFld" of card 1 of stack tPrintPath && "Fld Width" && the width of fld "PrintFld" of card 1 of stack tPrintPath
else
answer "Print stack is missing"
end if
put tWhat2Print into fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath
set the textalign of line 1 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to "center"
set the textStyle of line 1 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to "bold,italic"
set the textSize of line 2 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to 10
set the textalign of line 2 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to "center"
repeat with nCount = 1 to the number of lines of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath
set the textShift of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to - 1
set the firstindent of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to 0
set the leftIndent of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack tPrintPath to 5
end repeat
put specialFolderPath("Documents") & "/test.pdf" into tPDFFile
if there is a file tPDFFile then
delete file tPDFFile
end if
set the printmargins to 18,18,18,18
open printing to pdf tPDFFile
print card 1 of stack tPrintPath
close printing
close stack tPrintPath
rreHardcopyPrintPDF tPDFFile, "Test PDF Print"
-- answer "PrintPDF returned" && the result
end mouseUp
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
I've never printed from mobile apps but in general you don't need to open a stack to use it. Opening it on mobile will always resize it to the screen.
So skip the "open" command and just set the defaultstack to the printing stack. See if that works.
Edit : typically printing stacks are saved as substacks. That way they are always available and don't need to be opened. I think it should work as a separate stack too, but if it doesn't try embedding it.
So skip the "open" command and just set the defaultstack to the printing stack. See if that works.
Edit : typically printing stacks are saved as substacks. That way they are always available and don't need to be opened. I think it should work as a separate stack too, but if it doesn't try embedding it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
Thank you, Jackqueline. I re-did the script to set the defaultStack. When I check the size of the print stack it keeps the right size. However, it stalls at the print cd 1 of this stack. Just before the print line I had "answer the short name of this stack", it came back with the correct name. I tried with both a free standing print stack and a sub stack. I checked to make sure it found the card still... no-joy.
Code: Select all
open printing to pdf tPDFFile
if there is a cd 1 of this stack then
answer "Printing?"
print card 1 of this stack
else
answer the result
end if
close printing
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
Refer to the main stack directly instead of as "this stack". For example:
print card 1 of stack "myMainStack"
Or you can do it the other way around. Eliminate the defaultstack command and refer to the printing stack by name when setting the text of its field. In other words, only one stack is "this" stack and the other one has to be specified.
print card 1 of stack "myMainStack"
Or you can do it the other way around. Eliminate the defaultstack command and refer to the printing stack by name when setting the text of its field. In other words, only one stack is "this" stack and the other one has to be specified.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
I've tried it both ways. I beginning to get worried. I've spent over four months on this app. and printing is the key. I thought this would be the easy part.
Here's the error it throws:
Code: Select all
on mouseUp
local tPDFFile, tPrintPath
if environment() is not "mobile" then exit mouseUp
-- answer "rreHardcopyIsAvailable returns" && rreHardcopyIsAvailable()
put fld List" into tWhat2Print
-- put specialFolderPath("Documents") & "/Print.livecode" into tPrintPath
-- set the defaultStack to "Print_Sub"
-- if there is a stack tPrintPath then -- "Print stack is there"
-- answer "Stack Height" && the height of this stack && "Stack Width" && the width of this stack
-- else
-- answer "Print stack is missing"
-- end if
put tWhat2Print into fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub"
set the textalign of line 1 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to "center"
set the textStyle of line 1 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to "bold,italic"
set the textSize of line 2 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to 10
set the textalign of line 2 of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to "center"
repeat with nCount = 1 to the number of lines of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub"
set the textShift of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to - 1
set the firstindent of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to 0
set the leftIndent of line nCount of fld "PrintFld" of grp "PrintGrp" of card 1 of stack "Print_Sub" to 5
end repeat
put specialFolderPath("Documents") & "/test.pdf" into tPDFFile
if there is a file tPDFFile then
delete file tPDFFile
end if
set the printmargins to 18,18,18,18
open printing to pdf tPDFFile
if there is a cd 1 of stack "Print_Sub" then
answer "Printing?"
print card 1 of stack "Print_Sub"
else
answer the result
end if
close printing
rreHardcopyPrintPDF tPDFFile, "Test PDF Print"
-- answer "PrintPDF returned" && the result
end mouseUp
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
I apologize, I've misled you. While you can work with an unopened stack in general, it seems it does need to be open to print (I must not have ever tried it any other way.) I'm not quite sure how I'd handle the small card size while printing. One thing you might try is to set the fullscreenMode to "noScale" in preOpenStack when going to the print stack. That will prevent LC from scaling the stack down. Set the fullscreenMode to empty when the stack closes, or if you are already using a fullscreenMode, reset it to what it was. This will probably look funny for a moment when it prints, but if it works it's a start.
If you want to decipher the error codes you get on mobile, click on User Samples in the toolbar and search for "LiveCode Error Lookup" or get it at http://revonline2.runrev.com/stack/712/ ... ror-Lookup. This stack tells you what the error codes mean. Generally the top line is the important one, but in this case the first few lines are irrelevant because error 411 on line 5 is sending the compiler off on a tangent. Error 411 is "card or stack must be open to print" and I think that's the issue here. (You can read about what all those numbers mean if you look up errorDialog in the dictionary.)
If you want to decipher the error codes you get on mobile, click on User Samples in the toolbar and search for "LiveCode Error Lookup" or get it at http://revonline2.runrev.com/stack/712/ ... ror-Lookup. This stack tells you what the error codes mean. Generally the top line is the important one, but in this case the first few lines are irrelevant because error 411 on line 5 is sending the compiler off on a tangent. Error 411 is "card or stack must be open to print" and I think that's the issue here. (You can read about what all those numbers mean if you look up errorDialog in the dictionary.)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
No worries, Jacqueline. You've been very helpful as always. The fullscreenMode doesn't seem to do anything. I put the noscale in a preOpenStack script of the Print stack but nothing different happened.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
I was not as careful as I thought I was. I reset the simm. to clear out the old files and viola... full size printing magically appeared. Tested on my device and the magic happens there too. The fullscreenMode set to noscale in the print stack was the key. Thank you, thank you, thank you, Jacqueline.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
Excellent! Sorry it took me so long to think of the fullscreenMode but I'm very glad it's working now. I'll keep this in mind if I ever need to print from mobile.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
So I'm having a pagination problem when printing. I found Jacqueline's earlier post on this but I must be doing something wrong. Currently there are 2 pages to print. The second page should only print 10 lines or so. However, the second page is being printed with the fld scrolled to the bottom with a full page of text instead of just the 10 extra lines. I have the margins set to 6 and no border on the fld. Any thoughts?
Code: Select all
open printing to pdf tPDFFile
if there is a stack tPrintPath then
put the pageHeights of fld "PrintFld" of cd 1 of stack tPrintPath into tFlfHeight
set the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath to 0
repeat with nLines = 1 to the num of lines in tFlfHeight
print cd 1 of stack tPrintPath
set the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath to (the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath) + line nLines of tFlfHeight
-- answer (the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath) + line nLines of tFlfHeight
end repeat
else
answer the result
end if
close printing
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
Ok so I'm getting closer. Still figuring out the margins and the fld formatting. And that's a whole issue in itself.
Code: Select all
set the printmargins to 27,27,27,27 -- L, T, R, B
set the printpapersize to 612,792 -- 8.5x11 inches, US Letter size
open printing to pdf tPDFFile
if there is a stack tPrintPath then
local tCurrentScroll, tPageCount
put the pageHeights of fld "PrintFld" of cd 1 of stack tPrintPath into tFldHeight
set the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath to 0
put the num of lines of tFldHeight into tPageCount
repeat with nLines = 1 to tPageCount
if nLines is 1 then
-- answer "First page"
print cd 1 of stack tPrintPath
else
if nLines = tPageCount then ## The last page to print
-- answer "Last page"
set the topLeft of fld "PrintFld" of cd 1 of stack tPrintPath to 0,0
set the height of fld "PrintFld" of cd 1 of stack tPrintPath to line nLines of tFldHeight
put line (nLines - 1) of tFldHeight into tPreviousValue
set the vScroll of fld "printFld" of cd 1 of stack tPrintPath to (tPreviousValue + line nLines of tFldHeight)
answer the vScroll of fld "printFld" of cd 1 of stack tPrintPath
print cd 1 of stack tPrintPath
else
put the vScroll of fld "printFld" of cd 1 of stack tPrintPath into tCurrentScroll
set the vScroll of fld "printFld" of cd 1 of stack tPrintPath to (tCurrentScroll + line nLines of tFldHeight)
print cd 1 of stack tPrintPath
end if
end if
end repeat
else
answer the result
end if
close printing
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
There should be no need to check for the page numbers and make changes to the size or position the field on the card. Rsizing the field in particular will change the scroll. Unless there's something unusual going on, this should be all you need:
Code: Select all
set the printmargins to 27,27,27,27 -- L, T, R, B
set the printpapersize to 612,792 -- 8.5x11 inches, US Letter size
open printing to pdf tPDFFile
if there is a stack tPrintPath then
local tCurrentScroll, tPageCount
put the pageHeights of fld "PrintFld" of cd 1 of stack tPrintPath into tFldHeight
set the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath to 0
put the num of lines of tFldHeight into tPageCount
repeat with nLines = 1 to tPageCount
put the vScroll of fld "printFld" of cd 1 of stack tPrintPath into tCurrentScroll
set the vScroll of fld "printFld" of cd 1 of stack tPrintPath to (tCurrentScroll + line nLines of tFldHeight)
print cd 1 of stack tPrintPath
end repeat
else
answer the result
end if
close printing
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
- Location: McKenna, WA
Re: rreHardCopy - print the contents of a fld
Hi Jacqueline,
Sorry, I tried that. The fld will not scroll and leave space under the remaining text lines. I burned up a ream of paper and a bucket of toner trying to get this to work. The other thing I found was that you MUST have fixed line height turned on and you MUST leave the height setting to the default. I have my text set to 10 which gives a default of 13 for the fixed line height. I tried changing it to 15 and it was not good. pageHeights and the print to pdf engine are not very forgiving. I do all the text formatting before I call pageHeights and that seems to give the correct values.
The thing I'm fighting now is the bottom margin. The print cd is 612,792, the print fld size in 0,0,585,765 which is 27 off the right and bottom edges of the cd. The left and top margins cooperate with the margin setting of 27,27,27,27. The right and bottom edges pretty much ignore the setting. I get around the right edge margin problem by stepping thru each line and setting the rightIndent of the line to 27. The bottom prints to about 1/4" from the edge of the paper... no matter what I set the bottom margin to.
Sorry, I tried that. The fld will not scroll and leave space under the remaining text lines. I burned up a ream of paper and a bucket of toner trying to get this to work. The other thing I found was that you MUST have fixed line height turned on and you MUST leave the height setting to the default. I have my text set to 10 which gives a default of 13 for the fixed line height. I tried changing it to 15 and it was not good. pageHeights and the print to pdf engine are not very forgiving. I do all the text formatting before I call pageHeights and that seems to give the correct values.
The thing I'm fighting now is the bottom margin. The print cd is 612,792, the print fld size in 0,0,585,765 which is 27 off the right and bottom edges of the cd. The left and top margins cooperate with the margin setting of 27,27,27,27. The right and bottom edges pretty much ignore the setting. I get around the right edge margin problem by stepping thru each line and setting the rightIndent of the line to 27. The bottom prints to about 1/4" from the edge of the paper... no matter what I set the bottom margin to.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- VIP Livecode Opensource Backer
- Posts: 7230
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: rreHardCopy - print the contents of a fld
Oh right. There's two approaches. One is to add enough carriage returns to the second page to allow scrolling. Alternately just forget the scroll and manipulate the text itself. You'll need to keep all your current properties, especially fixed line height:The fld will not scroll and leave space under the remaining text lines.
Code: Select all
open printing to pdf tPDFFile
if there is a stack tPrintPath then
local tCurrentScroll, tPageCount
put the pageHeights of fld "PrintFld" of cd 1 of stack tPrintPath into tFldHeight
set the vScroll of fld "PrintFld" of cd 1 of stack tPrintPath to 0
put the num of lines of tFldHeight into tPageCount
put (the height of fld "PrintFld" of cd 1 of stack tPrintPath) div \
(the effective textheight of fld "PrintFld" of cd 1 of stack tPrintPath) into tLines
repeat tPageCount
print cd 1 of stack tPrintPath
print break -- starts new page
delete line 1 to tLines of fld 1
end repeat
else
answer the result
end if
close printing
For the right and bottom margin issue, you could look at the printPaperRectangle property which will tell you what the printer thinks it should use as the print area. You may be able to calculate field dimensions from that, and resize the print field so that you don't need to specify indents. Or maybe just adding the "print break" command will be enough to handle the bottom margin.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com