Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2003, 03:09 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Printing Multiple Page Image

Hi,

I am a bit stumped trying to print a fax image (.tif) that has more than one page. I am using the PrintDocument class in C#, however, the first page is only printing. How do I get the rest of the pages to print?

Thanks,

Doug

 
Old September 18th, 2003, 06:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

The process of the printing is such that when
you call print of PrintDocument class or ShowDialog
of PrintPreviewDialog class an even called
PrintPage is fired. In the handler of this event
you have to keep setting the value of
PrintPageEventArgs object's HasMorePages to true
until you have all the pages printed.
For this you have to maintain a count of pages
printed that you increament each time
this handler is called and set the hasmorepages
to false when the count reaches the no of total
pages that I presume you have calculated already.
 
Old September 18th, 2003, 08:00 AM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the quick reply. I do have a counter (outside the PrintPageEventArgs) and I increment it until the page count is reached then set the HasMorePages = false. However, the problem still remains. The first page of the image prints out the same amount as the page counter. I am using the Graphics.DrawImage(objBitmap,ev.Graphics.VisibleCl ipBounds) to draw the image. I assume it must have something to do with the ev.Graphics.VisibleClipBounds argument?

 
Old September 18th, 2003, 02:03 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, with MUCH research and a guiding hand from a fellow developer we have figured out how to do this. The code below explains (note error handling not included)!

using System.Drawing.Imaging;
using System.Drawing.Printing;

private Image objPrintImage;
private FrameDimension objDimension;


public void PrintImage()
{
    objPrintImage = Image.FromFile(@"C:\temp\Sample.tif");
    objDimension = new FrameDimension(new System.Guid());

    PrintDocument objPrintDoc = new PrintDocument();
    objPrintDoc.PrinterSettings.PrinterName = {UNC Printer Path};
    objPrintDoc.PrintPage += new PrintPageEventHandler(this.objPrintDoc_PrintPage);
    if (objPrintDoc.PrinterSettings.IsValid)
    {
        objPrintDoc.Print();
    }
}
private void objPrintDoc_PrintPage(object sender, PrintPageEventArgs ev)
{
    objPrintImage.SelectActiveFrame(FrameDimension.Pag e,intPage);
    intPage++;
    ev.Graphics.DrawImage(objPrintImage, 0, 0);
    if (intPage < objPrintImage.GetFrameCount(FrameDimension.Page))
    {
        ev.HasMorePages = true;
    }

}


 
Old August 20th, 2004, 10:56 AM
Registered User
 
Join Date: May 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to do the same thing using VB.NET. It works fine except that the image prints to the right. It does not print from the top-left corner of the page but is shifted little to the right and bottom.

I tried setting the margins for the printdocument object to (0,0,0,0) but still the same result.

Did you have any such problem while printing the TIFF.

Thanks for any help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing Image In mMFC switchlab Visual C++ 2 December 4th, 2007 10:59 PM
Printing PDF (page x to y) / multiple page seq's robbert XSLT 1 November 13th, 2006 10:27 AM
Background colour/image printing ghari HTML Code Clinic 0 September 21st, 2006 01:05 PM
Printing Multiple Pages raja.tadi VB How-To 0 June 26th, 2006 05:19 PM
Printing multiple pages at a go leo_vinay ASP.NET 1.0 and 1.1 Professional 0 November 3rd, 2005 07:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.