Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now I am trying to create a small application for printing a document(*.txt or *.doc).

I tried using the application with textbox and richtextbox, it prints successfully,
But if the Text length is more than one page. It shows only one page. It Ignores the remaining.

So I would like to save the text in another file.
I also like to select a file from file dialog and the selected file is allowed to print with multiple pages. print preview is also in the current application.

So Could anyone help me out Building the application.

Thanks in advance.
Posted
Updated 23-Jan-12 19:27pm
v2

1 solution

Hi,

Here is a example.
Hope it helps.
private void InvokePrint(object sender, RoutedEventArgs e)
    {
        // Create the print dialog object and set options
        PrintDialog pDialog = new PrintDialog();
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;

        // Display the dialog. This returns true if the user presses the Print button.
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
            XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
            FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
        }
    }
 
Share this answer
 
Comments
adithya.hari 24-Jan-12 2:05am    
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;

Your code contains RoutedEvents, PageRangeSelection and UserPageRangeEnabled. It is not Supported in my application(does not exist in the Current application).
manognya kota 24-Jan-12 2:14am    
what application are you using? WPF or windows or any other ?
manognya kota 24-Jan-12 2:14am    
Can you post the code that you are using to print currently?
adithya.hari 24-Jan-12 2:34am    
private void btnPrint_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
}

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