Results 1 to 5 of 5

Thread: Printing woes :-(

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Printing woes :-(

    I am trying to add some print functionality to my application which I thought would be easy but am not having much success.

    I need to be able to print images which will include jpg., gif and multi-page tiff files. I was hoping to let windows do all the hard work but for the life of me cant figure it out.

    Any Ideas ?

    Parksie

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Printing woes :-(

    All .NET printing is done the same way. It's a piece of cake for simple stuff and it's extremely powerful and flexible for complex stuff. Create a PrintDocument object, call its Print method and handle its PrintPage event. In the PrintPage event handler you have the full power of GDI+ to print anything you want. In your case its a single call to e.Graphics.DrawImage.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Printing woes :-(

    You lost me a bit should come as no suprise to you :-)

    I am creating a new ImagePrintDocument and I am using the PrintPreviewDialog box and all is well in the world........until I use a multi page tiff file.

    It always displays and prints only the first page which I find most distressing :-(.

    Basically I have no idea how to loop through the pages collection so it looks like more research is required. I shall get my pea sized brain onto it.

    Thanks

    Parksie

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Printing woes :-(

    I'm not really very experienced with image manipulation. Do you know how to access the multiple pages of the TIFF file? If so then printing multiple pages is simply a case of setting one property in the PrintPage event handler. Assuming that you can access a TIFF page by index it would look something like this:
    vb.net Code:
    1. Private pageIndex As Integer = 0
    2.  
    3. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    4.                                      ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    5.     'Get the image to be printed.
    6.     Dim imageToPrint As Image = myTiff.Pages(Me.pageIndex)
    7.  
    8.     'Print the image here.
    9.  
    10.     'Increment the page index.
    11.     Me.pageIndex += 1
    12.  
    13.     'There are no more pages to print if the index has gone beyond the upper bound.
    14.     e.HasMorePages = (Me.pageIndex < myTiff.Pages.Count)
    15.  
    16.     If Not e.HasMorePages Then
    17.         'Reset the page index for the next run.
    18.         Me.pageIndex = 0
    19.     End If
    20. End Sub
    Note that that is almost certainly not valid code, but hopefully it illustrates the point.

    If you don't know how to get at each page of a TIFF then that's another issue, not really related to printing specifically.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Printing woes :-(

    Just had a quick look at the Image class and it has a SelectActiveFrame method. I'm guessing that you'd use that to select a "current page" in a TIFF image, then accessing the Image itself would always access that page. That's just an educated guess mind you. I'd think that there would be examples on the Web.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width