Solved

Create a Tiff level 4 image from Ascii text file?

Posted on 1998-06-18
21
472 Views
Last Modified: 2008-02-01
How can I create a level 4 Tiff image from an ascii text file using VB 5?
0
Comment
Question by:dk02151
  • 9
  • 8
  • 4
21 Comments
 
LVL 4

Expert Comment

by:zsi
ID: 1463733
I'll tell you how if you tell me why...   :)
0
 

Author Comment

by:dk02151
ID: 1463734
I need to take text from our mainframe and convert them into Tiff images for use with FileNet.
0
 
LVL 4

Expert Comment

by:zsi
ID: 1463735
IBM mainframe?  If so, you can use IBM's APF and then convert the resultant file to a TIFF.

You can also look into Accusoft's ImageGear98, which may be able to convert between the two.  It is an excellent package, but it is expensive.
0
 

Author Comment

by:dk02151
ID: 1463736
It appears that we may not have APF on our mainframe. I looked at ImageGear98, and it is not what we want. What we are looking to do is to take billing files from the mainframe and parse them into indivdual bills and convert them to images using a VB program that runs in the background. The images will then be submitted to FileNet where our users will then be able to retrieve them. We would like to be able to find some resources that would help us write a VB custom control to do this.
0
 
LVL 7

Expert Comment

by:tward
ID: 1463737
All you would need to find is a Print Driver to Do it, then just send it to the Print Driver.

We make TIFF's here but usually by Scanning them....  I have taken text and made a TIFF out of it with an OCX called LeadTools.
0
 

Author Comment

by:dk02151
ID: 1463738
Downloading LeadTools demo. I would be interested in how you you converted text to images with LeadTools.
0
 
LVL 7

Expert Comment

by:tward
ID: 1463739
I load a blank saved TIFF (white) that I have here, and since you can get the hDC of the Tiff you can output text to it via the TextOut API call.  It's going to be kind of hard to understand without the whole project....  But Here is some of the code:

      Lead1.Load gBlankTiFFFilename, 0, 0, 1
     
      MakeTIFF.Label1.Caption = "Outputing Text Progress:"
      DoEvents
     
      LeadDC = Lead1.GetBitmapDC
      Call OutputText(LeadDC)
      Lead1.ReleaseBitmapDC
     
      Lead1.BackErase = False
      Lead1.ForceRepaint
      Lead1.BackErase = True

Public Function OutputText(ByVal LeadHDC As Long)
   
  Dim font As LOGFONT
  Dim stextout As String
  Dim nlen, nxtext, nytext, hfont As Long
  Dim status, prevfont, ret As Long
  Dim fontsize As Long
  Dim Position As Long
  Dim InnerCounter As Long
  Dim Temp As String
  Dim Counter As Long
 
  InnerCounter = 1
  Counter = 0
 
  If MakeTIFF.TIFFText.FontItalic = True Then
     
    font.lfItalic = 1
       
  Else
       
    font.lfItalic = 0
       
  End If
     
  If MakeTIFF.TIFFText.FontBold = True Then
     
    font.lfWeight = 900
       
  Else
       
    font.lfWeight = 100
       
  End If
     
  font.lfEscapement = Val(frmSetup.txtEscapement.Text)
  font.lfFaceName = frmSetup.cmbFont.Text & vbNullChar
  font.lfHeight = Val(frmSetup.txtHeight.Text)
  font.lfWidth = Val(frmSetup.txtWidth.Text)
  hfont = CreateFontIndirect(font)
  prevfont = SelectObject(LeadHDC, hfont)
   
  Temp = MakeTIFF.TIFFText.Text
   
  Do While InnerCounter <= Len(MakeTIFF.TIFFText.Text)

    Position = InStr(InnerCounter, Temp, vbCrLf) 'FindChar)
     
    If Position <> 0 Then
       
      stextout = CStr(Mid(Temp, InnerCounter, Abs(InnerCounter - Position))) & vbNullChar
     
    Else
       
      stextout = CStr(Mid(Temp, InnerCounter, Abs(InnerCounter - Len(MakeTIFF.TIFFText.Text)) + 1)) & vbNullChar
      Position = Len(MakeTIFF.TIFFText.Text) + 1
   
    End If
     
    Select Case frmSetup.cmbRotate.Text
     
           Case "0 Degrees"
                            If frmSetup.txtEscapement.Text = -900 Then
                               
                              nytext = Val(frmSetup.txtStartY.Text)
                              nxtext = Val(frmSetup.txtStartX.Text) - (font.lfHeight * Counter)
                             
                            ElseIf frmSetup.txtEscapement.Text = 900 Then
                             
                                  nytext = Val(frmSetup.txtStartY.Text)
                                  nxtext = Val(frmSetup.txtStartX.Text) + (font.lfHeight * Counter)

                            ElseIf frmSetup.txtEscapement.Text = 0 Then
                               
                              nxtext = Val(frmSetup.txtStartX.Text)
                              nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
                             
                            Else
                               
                              nxtext = Val(frmSetup.txtStartX.Text)
                              nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
                             
                            End If
           
           Case "90 Degrees"
                            nxtext = Val(frmSetup.txtStartX.Text)
                            nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
           
          Case "180 Degrees"
                            If frmSetup.txtEscapement.Text = -900 Then
                               
                              nytext = Val(frmSetup.txtStartY.Text)
                              nxtext = Val(frmSetup.txtStartX.Text) - (font.lfHeight * Counter)
                           
                            ElseIf frmSetup.txtEscapement.Text = 900 Then
                             
                                  nytext = Val(frmSetup.txtStartY.Text)
                                  nxtext = Val(frmSetup.txtStartX.Text) + (font.lfHeight * Counter)

                            ElseIf frmSetup.txtEscapement.Text = 0 Then
                               
                                  nxtext = Val(frmSetup.txtStartX.Text)
                                  nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
                             
                            Else
                               
                                nxtext = Val(frmSetup.txtStartX.Text)
                                nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
                             
                            End If
           
          Case "270 Degrees"
                            nxtext = Val(frmSetup.txtStartX.Text)
                            nytext = font.lfHeight * (Val(frmSetup.txtStartY.Text) + Counter)
     
    End Select
 
    nlen = Len(stextout) - 1
    status = TextOut(LeadHDC, nxtext, nytext, stextout, nlen)
     
    InnerCounter = Position + 2
    Counter = Counter + 1
     
    DoEvents
     
  Loop
 
  hfont = SelectObject(LeadHDC, prevfont)
  Call DeleteObject(hfont)

End Function

0
 
LVL 4

Expert Comment

by:zsi
ID: 1463740
Have you considered using the Adobe PDF file format instead?  Their product, Acrobat Exchange, includes a printer driver that will create a PDF file automatically.  I have used it extensively to produce on-line account statements and have been very happy with it.  Better yet, it supports graphics in addition to text, so you can have nicer output.  Also, PDF is the de facto standard document format for the Internet.
0
 
LVL 7

Accepted Solution

by:
tward earned 200 total points
ID: 1463741
I didn't think that the Printer Driver let you do a Graphic and Text PDF, I thought it only allowed Graphic??
0
 
LVL 4

Expert Comment

by:zsi
ID: 1463742
tward,

It does let you do both and why did you submit that as an answer?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:tward
ID: 1463743
Messed up!!  Sorry.
0
 

Author Comment

by:dk02151
ID: 1463744
tward:
I have tried your suggestion and I can get some text files to save as Tiff images but some generate an error message when I try to save them. they display ok. Have you ever encountered this before?
0
 
LVL 7

Expert Comment

by:tward
ID: 1463745
What is the Error?  You are using LeadTools?
0
 

Author Comment

by:dk02151
ID: 1463746
I am using leadTolls. The error message is # 20014 "Not able to open file."
0
 
LVL 7

Expert Comment

by:tward
ID: 1463747
Post the Code you are using here and I'll cut it out and see if I can figure it out.
0
 

Author Comment

by:dk02151
ID: 1463748
The text files that I have been able to save as tiff files are the text files created by Windows in the root directory. All others fail. Here is the code that I modified:

Private Sub Form_Load()
    Dim strFilename As String
    Dim LeadDC As Long
    strFilename = "c:\projects\Blank.tif"
    LEAD1.Load strFilename, 0, 0, 1
    DoEvents
    LeadDC = LEAD1.GetBitmapDC
    Call OutputText(LeadDC)
    LEAD1.ReleaseBitmapDC
    LEAD1.BackErase = False
    LEAD1.ForceRepaint
    LEAD1.BackErase = True
End Sub

Private Function OutputText(ByVal LeadHDC As Long)
        Dim font As LOGFONT
        Dim stextout As String
        Dim nlen, nxtext, nytext, hfont As Long
        Dim status, prevfont, ret As Long
        Dim fontsize As Long
        Dim Position As Long
        Dim InnerCounter As Long
        Dim Temp As String
        Dim Counter As Long
        Dim inNum As Integer
        Dim strFont As String
        InnerCounter = 1
        Counter = 0
        font.lfItalic = 0
        font.lfWeight = 900
        font.lfHeight = 20
        font.lfWidth = 10
        hfont = CreateFontIndirect(font)
        prevfont = SelectObject(LeadHDC, hfont)
         
        Temp = MakeTiff.TiffText.Text
         
        Do While InnerCounter <= Len(MakeTiff.TiffText.Text)

           Position = InStr(InnerCounter, Temp, vbCrLf) 'FindChar
           
            If Position <> 0 Then
             
                stextout = CStr(Mid(Temp, InnerCounter, Abs(InnerCounter - Position))) & vbNullChar
             
            Else
             
                stextout = CStr(Mid(Temp, InnerCounter, Abs(InnerCounter - Len(MakeTiff.TiffText.Text)) + 1)) & vbNullChar
     
                Position = Len(MakeTiff.TiffText.Text) + 1
               
            End If
                             
            nxtext = 0
            nytext = font.lfHeight * Counter
           
            nlen = Len(stextout) - 1
            status = TextOut(LeadHDC, nxtext, nytext, stextout, nlen)
           
            InnerCounter = Position + 2
            Counter = Counter + 1
           
            DoEvents
           
        Loop
         
        hfont = SelectObject(LeadHDC, prevfont)
        Call DeleteObject(hfont)
End Function




Private Sub mnuFileSave_Click()
    LEAD1.Save "c:projects\image.tif", FILE_CCITT_GROUP4, 1, 2, False
End Sub

0
 

Author Comment

by:dk02151
ID: 1463749
Tward:
I found the error (a dumb mistake on my part). Thank you for all of your help.
0
 

Author Comment

by:dk02151
ID: 1463750
Tward:
I found the mistake (a dumb error on my part). The program works great. Thank you for your time and efforts!
0
 
LVL 7

Expert Comment

by:tward
ID: 1463751
I hadn't had a chance to look at the source yet, what was the mistake?
0
 

Author Comment

by:dk02151
ID: 1463752
I am embarrassed to admit this one but I forgot one of the back slashes in the path of the output file name. I looked at it a million times and it failed to regester on the old brain.
0
 
LVL 7

Expert Comment

by:tward
ID: 1463753
Those are the hardest to find, just wanted to make sure that if someone looked at the answer and comments here that it would answer everything and not get them to the point that you were at!!!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now