[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Batch printing and annotating TIF files

Posted on 2006-11-07
16
Medium Priority
?
462 Views
Last Modified: 2012-06-27
What is the most efficient way to batch annotate and print group 4 tiff image files in VB.NET 2005.

I have multiple images in a folder that I need to add a couple lines of text at the top of the page then print the image in native size on a specific printer.

Can you give me code examples that will do this in the most efficient manner?
0
Comment
Question by:jimtxas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 4
16 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951389
When you say native size do you mean full/actual size ?
What if the images are smaller or larger than the paper size in the printer ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951393
Are any of the tiffs multi-page ?
0
 

Author Comment

by:jimtxas
ID: 17951417
yes... actual size...  i do not want to adjust page size based on printer and no multipage tiffs...
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 15

Expert Comment

by:ozymandias
ID: 17951430
OK. So if you have a tif image that is A3 you want it printed across 4 pages of A4 ?

Are all the tifs A4 portrait, i.e. are these scans or faxes of a4 pages ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951441
The annotatoin should be pretty straight forward.
You load the tif image and then get a graphics object from the tif and use the DrawSyring method of the Graphics object to write the text onto the tif image.

The printing can get a bit tricky though.

If you were happy for the printing to just be the best fit of the image onto the paper available in the selected printer then it shouldn't be too hard.
0
 

Author Comment

by:jimtxas
ID: 17951474
if it's legal size paper and letter is in the tray, just print on the letter paper as legal size (understanding that the bottom would be cut off)

On the annotation, please provide the code needed to load an image from a file path, annotate, then send to printer...

0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951693
I don't have an example of a class4 tif I can test with.
Can you email me one to : ozymandias[at]chainreactors[dot]co[dot]uk.

Also, any idea what you want printed at the top ?
How many lines of text etc ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951805
Here is the code. It works with Group 3 tiffs but I cannot test with group 4.

First here's a class that is a PrintDocument that holds a tif :

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

      public class TifDocument : System.Drawing.Printing.PrintDocument
      {

            protected Image _Image = null;
            

            public TifDocument(string pathToTif) : base()
            {
                  Bitmap b = new Bitmap(pathToTif);
                  this._Image = this.ConvertToRGB(b);
                  this.PrintPage += new PrintPageEventHandler(TifDocument_PrintPage);
                  
            }

            protected Bitmap ConvertToRGB(Bitmap original) {
                  // .NET does not support class 4 tiff files or any Bitonal (one-bit-per-pixel)
                  // image formats, so we have to cheat a bit
                  // code nicked from http://www.codeproject.com/cs/media/BitonalImageConverter.asp
                  Bitmap newImage = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb);
                  newImage.SetResolution(original.HorizontalResolution, original.VerticalResolution);
                  Graphics g = Graphics.FromImage(newImage);
                  g.DrawImageUnscaled(original, 0, 0);
                  g.Dispose();
                  return newImage;
            }

            private void TifDocument_PrintPage(object sender, PrintPageEventArgs e) {
                  Graphics g = e.Graphics;
                  if (this._Image != null){
                        g.DrawImage(this._Image, e.PageBounds);
                  }
                  g.DrawString("This is a line of text added at the top of the document.",new Font("Arial", 14f), Brushes.Black, e.PageBounds.Left + 10, e.PageBounds.Top + 10);
                  e.HasMorePages = false;
            }
      }
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951808
Here's an example of how to print a tif :

TifDocument doc = new TifDocument(@"c:\temp\test.tif");
PrintDialog pd = new PrintDialog();
pd.Document = doc;
if(pd.ShowDialog() == DialogResult.OK){
      doc.Print();
}

and here's how to print preview it :

TifDocument doc = new TifDocument(@"c:\temp\test.tif");
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = doc;
ppd.ShowDialog();
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951811
The text you wanted added is added by the class when the document is printed as an overlay.
The actual tif image itself is not modified.
0
 

Author Comment

by:jimtxas
ID: 17953214
any chance you got this in VB?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17954378
Here is the same class in VB. My VB is a bit rusty I'm afraid but it seems to work fine :

Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Printing

Public Class TifDocument
    Inherits System.Drawing.Printing.PrintDocument

    Protected _Image As Image

    Public Sub New(ByVal pathToTif As String)

        Dim b As Bitmap = New Bitmap(pathToTif)
        Me._Image = Me.ConvertToRGB(b)

    End Sub



    Protected Function ConvertToRGB(ByVal original As Bitmap) As Image

        ' .NET does not support class 4 tiff files or any Bitonal (one-bit-per-pixel)
        ' image formats, so we have to cheat a bit
        ' code nicked from http://www.codeproject.com/cs/media/BitonalImageConverter.asp
        Dim newImage As Bitmap = New Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb)
        newImage.SetResolution(original.HorizontalResolution, original.VerticalResolution)
        Dim g As Graphics = Graphics.FromImage(newImage)
        g.DrawImageUnscaled(original, 0, 0)
        g.Dispose()
        ConvertToRGB = newImage

    End Function

    Private Sub TifDocument_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles MyBase.PrintPage
        Dim g As Graphics = e.Graphics
        If Not Me._Image Is DBNull.Value Then
            g.DrawImage(Me._Image, e.PageBounds)
        End If
        g.DrawString("This is a line of text added at the top of the document.", New Font("Arial", 14.0F), Brushes.Black, e.PageBounds.Left + 10, e.PageBounds.Top + 10)
        e.HasMorePages = False

    End Sub
End Class
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 2000 total points
ID: 17954386
And these should work in VB :

Dim doc As TifDocument = new TifDocument(@"c:\temp\test.tif")
Dim pd As PrintDialog = new PrintDialog()
pd.Document = doc
If pd.ShowDialog() Is DialogResult.OK Then
     doc.Print()
End If

and here's how to print preview it :

Dim doc As TifDocument = new TifDocument(@"c:\temp\test.tif")
Dim ppd As PrintPreviewDialog = new PrintPreviewDialog()
ppd.Document = doc
ppd.ShowDialog()
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17959001
Did this work OK for you ?
0
 

Author Comment

by:jimtxas
ID: 17962696
haven't had a chance to try it yet... will very soon.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question