Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

printing multiple pages?

Community Beginner ,
Dec 17, 2009 Dec 17, 2009

Hi--

I've been killing myself for weeks on this issue and still can't figure it out.

I'm importing a large text file and trying to print it with a footer. My method for all of this is very simple. I'm dynamically creating a sprite container that is fed to the the printjob() class. Inside that I'm creating a dynamic text field and scaling it to the right page height/width (408x574) and adding a footer below that.

Using a loop, I'm scrolling the text field to the top of the next page and adding the page number to the footer and adding the page to the job. Mostly, this works fine, but I'm noticing some lines from the text field are not printing. This happens at the page breaks and is not consistent across different printers I use.

Essentially, this is the code I use to print:

if (pj.start()) {

        rect1 = new Rectangle(-60,-66,540,720);

        for (i=0;i<10;i++) {

            pj.addPage(container,rect1);

            tf.scrollV+=56;

            container.footer.pageNum.htmlText="- "+Number(i+1)+" -";

        }

        pj.send();

        pj=null;

    }

This whole project has been more than a little frustrating because I'm getting so many conflicting pieces of data. For example, using textLineMetrics, I learned each and every line of my text field is 14 pixels high. That's why I'm using the 574px height. That equates to 41 lines of text, but viewing it onscreen, it's more than that.

Please...please! If anyone can offer some insight or a fix for this, I'll be very grateful.

Thank you!

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2009 Dec 17, 2009

assign text to each textfield character-by-character while checking the sprite's height with the footer already added.  when the height exceeds your printjob's pageHeight minus the footer's height, back up the text to the previous logical (eg, space) break.  add that page to the printjob and proceed with the next page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2009 Dec 17, 2009

Thank you for the reply!

I've considered doing this, but the problem is my incoming text contains html tags (<u></u>, etc) so the values I'd get back would be inaccurate since those tags disappear when creating the output. My first solution to that was to apply the text to another textfield and select/copy what would fit, but then I ran into the problem of how to move the selected HTML text to another field while maintaining the formatting.

What baffles me most of all is why can I add text to a text field on the stage, scroll it X number of lines and see it working every single time, but when I try to capture that area with printJob() it fails?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2009 Dec 17, 2009

it's going to be more complex to deal with with html text.

and, as you already know, know you see on-screen is not exactly what you see on a printed page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 17, 2009 Dec 17, 2009

I've had several ideas about how to make this work, but don't  think any of them are really feasible.

My first plan was to make the text field height equal to all the text and change the .y position. That worked, but some lines were split in half (top on one page, bottom on the next page). I thought about adding some code to make all the text white except where I needed it, but that might require knowing which lines are visible.

Is there just a quick method for selecting a block of text by LINE not by character? With that, I think I could rule the world.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 17, 2009 Dec 17, 2009

textfields in as3 have an getLineText(index) method that returns the text on line number index.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 21, 2009 Dec 21, 2009
LATEST

After more than three weeks of messing with at least a dozen different approaches, I think I found a solution. It's a total kludge, but seems to work.

I know the height of my textfield and the heights of each line of text and though my math has been correct to fit enough lines into the textfield for the addPage() command, all the lines haven't been printing on all the printers I've tested with so I'm keeping the textfield the same height, but reducing the number of visible lines by one as a precaution.

To do this, I'm filling the textfield with my html-formatted text then deleting the lines above and below that don't fit in the textfield. A kludge, as I've said, but it has worked in my tests so far.

The big problem is the html formatting. Because I'm loading an external file with the html tags I won't get accurate results on the number of lines or any metrics until those tags are removed and the formatting applied to the text. At one point I hoped to to just copy X number of lines from one textfield to another, but realized there's no paste function with ActionScript.

Several of my other attempts have included splitting the incoming text file by line break (but that only returned hard breaks; not very useful) then I tried splitting it by word, but when I applied them to my textfield it would only apply the closing tags (</b>, </u>, etc) if they were included with the same word as the opening tags. That is, this would work: <b>word</b>, but not this <b>word, word</b>.

All in all, I've found the printJob() class to be an utter failure for printing. Its implemenation with the rectangle class and lack of real pagination support make this practically useless for me. I can only hope CS5 has improved upon this with its other text enhancements.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines