Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# printing
I have a richTextBox with a long text that i need to send to fax using Windows fax and scan. this process works well if the text doesn't span more than one page, if it does it generates a tiff file that cannot be read
 
my code looks like:
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            
            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                listBox1.Items.Add(printer);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            richTextBoxLink1.CreateDocument(printingSystem1);
            richTextBoxLink1.Print(listBox1.SelectedItem.ToString());
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            linesPrinted = 0;
            printDialog1.PrinterSettings.PrinterName = listBox1.SelectedItem.ToString();
            printDocument1.Print();
        }
 
        void doc_EndPrint(object sender, PrintEventArgs e)
        {
           
        }
 
        void doc_BeginPrint(object sender, PrintEventArgs e)
        {
            linesPrinted = 0;
        }
 
        private int linesPrinted = 0;
 
        void doc_PrintPage(object sender, PrintPageEventArgs e)
        {
            int x = e.MarginBounds.Left;
            int y = e.MarginBounds.Top;
            Brush brush = new SolidBrush(richTextBox1.ForeColor);
 
            while (linesPrinted < richTextBox1.Lines.Length)
            {
                e.Graphics.DrawString(richTextBox1.Lines[linesPrinted++],
                     richTextBox1.Font, brush, x, y);
                y += 15;
                if (y >= e.MarginBounds.Bottom)
                {
                    e.HasMorePages = true;
                    return;
                }
                else
                    e.HasMorePages = false;
            }
            e.Graphics.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
        }
    }
the form contains a button, a richtextbox and a list box. when running, select the fax (from windows fax and scan - windows 7) and press the button.
 
if I print to a normal printer or a pdf writer is fine, it only doesn't work with the fax, am I doing something wrong?
Posted 30-Aug-12 2:02am
Comments
Peter_in_2780 at 30-Aug-12 21:42pm
   
Are you missing an ...endPage() call somewhere? I don't know about the one you're using, but a lot of print APIs want one to flush this page and initialise the next.
Member 8219251 at 31-Aug-12 10:16am
   
HI Peter, thank you for your suggestion, the strange part is that if I select a normal printer or a pdf writer it prints correctly, so I am starting to think that it is a bug in the .Net framework.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 500
1 Prakriti Goyal 292
2 Yogesh Kumar Tyagi 224
3 Maciej Los 195
4 CPallini 170
0 OriginalGriff 6,652
1 Sergey Alexandrovich Kryukov 5,449
2 Maciej Los 3,474
3 Peter Leow 3,303
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100