Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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
Comments
Peter_in_2780 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.
Eddie Silva 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900