2 Replies Latest reply on Mar 11, 2008 8:19 AM by mediaops

    Add Print Button

    mediaops
      I'm not a coder, but is there a way you can add a button that when clicked, prints the "text" box only for the page displayed, not the whole page?

      I've got a scrolling text box on each of several pages and I want to add a button to each page that gives the person the option to print the contents of the text box.

      If so, could someone please help me with the code or are there any examples that you know of you could refer me to.

      Thank you in advance.
        • 1. Re: Add Print Button
          Level 7
          There are xtras like PrintOMatic that will allow you to print from
          within Director.

          However, I would probably approach this as follows:
          1). when the print button is clicked, determine which text member is to
          be printed
          2). write the contents (#text, #rtf or #html) of this member to disk
          (temporarily), using an xtra like PRegEx or FileIO
          3). use an xtra like Buddy API to print the file with its associated
          application
          4). delete the temporary file

          Here's a possibility. Note, however, that it uses 4 BudAPI functions and
          you only get 2 for free. You could substitute all the others, excepting
          baShell(), with the equivalent (free) FileXtra4 functions
          -- script "print text member"
          -- requires PRegEx and Buddy API xtras:
          -- Buddy API: http://www.mods.com.au
          -- PRegEx: http://www.openxtras.org/pregex/
          property myPrintMember
          property myFormatType
          property myFile

          on getPropertyDescriptionList
          tDefault = member 0 of castLib 0
          repeat with s = 1 to the lastChannel
          if sprite(s).member.type = #text then
          tDefault = sprite(s).member
          exit repeat
          end if
          end repeat

          pdl = [:]
          pdl[#myPrintMember] = [#comment:"Text member to print:", #format:
          #text, #default: tDefault]
          pdl[#myFormatType] = [#comment:" Format to print:", #format:
          #symbol, #default: #text, #range: [#text, #rtf, #html]]
          return pdl
          end

          on mouseUp me
          -- error check:
          if (ilk(myPrintMember, #member) = 0) then exit
          if (myPrintMember.type <> #text) then exit

          case myFormatType of
          #text:
          data = myPrintMember.text
          extn = ".txt"
          #rtf:
          data = myPrintMember.rtf
          extn = ".rtf"
          #html:
          data = myPrintMember.html
          extn = ".html"
          end case

          myFile = baSysFolder("personal") & "temp" & extn
          -- assume file doesn't pre-exist, though it would be sensible to
          check first (skipped for clarity)
          nCharsWritten = re_write(myFile, [data])
          -- error check write operation (skipped for clarity)
          OK = baShell("print", myFile, "", "", "hidden")
          -- error check print (refer to docs for meaning of OK if < 32)
          (skipped for clarity)

          end

          on endSprite me
          if voidP(myFile) then exit
          if baFileExists(myFile) then
          OK = baDeleteFile(myFile)
          -- error check delete operation (skipped for clarity)
          end if
          end
          • 2. Re: Add Print Button
            mediaops Level 1
            Thanks Sean,

            I'll take a look at the extras and experiment with your solutions. Appreciate you taking the time to write this all out.

            Bob