Page 1 of 1

Printing from a data grid with variable height rows

Posted: Thu Sep 27, 2012 3:14 pm
by donryan
I have a datagrid form that contains variable height fields. Once the dg is populated with data, it extends beyond the visible window, thus adding a vertical scroll bar. I have a separate print routine that I am writing to Print to PDF. Using the examples in the book, I can get the header to print and the first page of the dg, but I am at a loss of how to scroll the dg and print it for as many iterations as required to print everything. I also need to know when the last of the dg is printed so that I can add my footer to the report. I've tried multiple iterations of the samples in the manual, but can't get anything to work -- any help would be appreciated. Here's what I've got so far ...

Code: Select all

 ---|  Get the PDF Template  |---
      hide stack "PDFLayout"
      go stack "PDFLayout"
      put the rect of graphic "header" into tHeaderRect
      put the rect of graphic "body" into tBodyRect
      put the rect of graphic "footer" into tFooterRect
      put the rect of graphic "Total" into tTotalRect
      close stack "PDFLayout"
      ---|  Initialize PDF file creation  |---
      put specialfolderpath("documents") & "/" into tPDF
      put "TestRPT.pdf" after tPDF
      delete file tPDF  --> delete any existing file first     
      set the printpaperorientation to "landscape"
      set the printscale to 1
      open printing to pdf tPDF
      ---|  Get the PDF Header  |---
      go stack "PDFHeader"
      set the defaultstack to "PDFHeader"
      print this card from the topleft of field "txtHeader" to \
               the bottomright of field "txtHeader" into tHeaderRect
      close stack "PDFHeader"
      ---|  Get the BodyText  |---
      #### NOTE: This works, but only prints the current view (one page) ####     
      ## go stack "PDFBody"
      ## set the defaultstack to "PDFBody"
      ## print this card from the topleft of group "dgDetailReport" to \
              the bottomright of group "dgDetailReport" into tBodyRect
      ## close stack "PDFBody"
      ##########

      
      ### This is where I need help to have the BodyText print everything in the group "dgDetailReport" ...

 
      ---|  Reset the default stack and exit  |---
      close printing
The code is creating a PDF file successfully. If I uncomment the "Get the BodyText" section, the current view of the datagrid is also printed correctly, I just can't figure out how to code it so that if the datagrid is more than one page, how do I scroll the datagrid, print again, and also know when the datagrid is done. Ideally, I'd like to be able to print the footer right below the last row of the datagrid

Re: Printing from a data grid with variable height rows

Posted: Thu Sep 27, 2012 6:22 pm
by dunbarx
I wonder if it would be better to offload your data via the "dgText" property, and, since this contains all the formatting tags, you can then print with the "revPrintText" command. You get your header and footer included under your control.

Just a thought...

Craig Newman

Re: Printing from a data grid with variable height rows

Posted: Thu Sep 27, 2012 7:50 pm
by donryan
Craig:

Thanks -- gave that a try but couldn't get it to work ??? Here's the code I used:

Code: Select all

      local tText
      put the dgText of group "dgDetailReport" into tText
      revPrintText tText
When I tried it, I got an error message:
573,92,1,revPrintText
253,55,1

I know there has to be a way to accomplish this, I just don't know how (been through the entire DG manual, still didn't help me). :oops:

-- Don

Re: Printing from a data grid with variable height rows

Posted: Fri Sep 28, 2012 4:50 am
by dunbarx
Hmmm.

I made a datagrid, stuck some data into it, and tried the same script. Worked fine.

If you step through the script, do you get valid data in tText?

If you, from the message box, execute: revPrintText "someText"

do you get something from the printer?

Craig Newman

Re: Printing from a data grid with variable height rows

Posted: Fri Sep 28, 2012 1:18 pm
by donryan
Craig:

If you look at the code I initially posted, I'm using this as part of a "Print to PDF" function -- I'm not sure if that is the problem. I did try using it with just a single line of text (eliminating the datagrid from the equation) and still got an error. So, I'm not sure if I can use the revPrintText within the "Print to PDF" function. If the two functions are not compatible, then I'm back to trying to scroll the datagrid via script and printing the rectangle of the grid -- and -- since my datagrid has varible line heights I also risk the possibility of clipping some lines of text.

I know that I can print the rectangle of the datagrid (that's the section of code I posted that is commented out), but how do I determine if the datagrid is scrollable, how do I scroll the datagrid via script, and how do I know when I've printed 100% of the data grid?

I appreciate your help with this! -- Don