Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:18:25+00:00 2026-05-23T12:18:25+00:00

I am developing an application to print preview the files that user likes to

  • 0

I am developing an application to print preview the files that user likes to print, i write the following code but i am unable to see the text or content on the preview page why it is happening can any one help me

My code is as follows

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
    private PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
    private PrintDocument printDocument1 = new PrintDocument();

    // Declare a string to hold the entire document contents.
    private string documentContents;

    // Declare a variable to hold the portion of the document that
    // is not printed.
    private string stringToPrint;


    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void ReadDocument()
    {

        string docName = "ACH.txt";
        string docPath = @"c:\";
        printDocument1.DocumentName = docName;
        using (FileStream stream = new FileStream(docPath + docName, FileMode.Open))
        using (StreamReader reader = new StreamReader(stream))
        {
            documentContents = reader.ReadToEnd();
        }
        stringToPrint = documentContents;
    }

    private void printToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ReadDocument();
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }
    void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        int charactersOnPage = 5;
        int linesPerPage = 10;

        // Sets the value of charactersOnPage to the number of characters 
        // of stringToPrint that will fit within the bounds of the page.
        e.Graphics.MeasureString(stringToPrint, this.Font,
            e.MarginBounds.Size, StringFormat.GenericTypographic,
            out charactersOnPage, out linesPerPage);

        // Draws the string within the bounds of the page.
        e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
        e.MarginBounds, StringFormat.GenericTypographic);

        // Remove the portion of the string that has been printed.
        stringToPrint = stringToPrint.Substring(charactersOnPage);

        // Check to see if more pages are to be printed.
        e.HasMorePages = (stringToPrint.Length > 0);

        // If there are no more pages, reset the string to be printed.
        if (!e.HasMorePages)
            stringToPrint = documentContents;
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:18:25+00:00Added an answer on May 23, 2026 at 12:18 pm

    You haven’t hooked up your printing events. Add this to your form constructor:

    public Form1()
    {
      InitializeComponent();
      printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web application where user require to print a particular form with
I am developing an application which generates barcodes, I want to print them but
I am developing android version of an iPhone application. But, I found that in
When developing an application that sends out notification email messages, what are the best
I am developing an application to install a large number of data files from
I'm developing and application that runs as a Windows service. There are other components
I developing an application in which i want to print the values on a
I'm developing an application ased on zend framework, and the problem that it is
I'm developing an Asp.Net 3.5 application and I need to print some application generated
I am developing a web application using Struts 1.2.7 I want to print a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.