DrawText and Unit of Measure...
DrawText and Unit of Measure...
Howdy,
We have an application that we are converting to use GdPicture that takes "legacy" reports from a file and converts them so they can be faxed (Tiff) or emailed (Pdf).
We are using the DrawText method to accomplish the burning of the text on the GdPicture Image...
There is a FontSetUnit(UnitMode) method to control the FontSize being used.
But we can not find a method to control the Unit of Measurement for X and Y co-ordinates of the DrawText method.
We would prefer to use inches if possible.
The question is...
What Unit of Measurement should be used for the X and Y co-ordinates.
Is it Pixels, Points, Inches, etc or does the "FontSetUnit" control that as well.
Also if we are wanting to create an 8.5 x 11 inch image...
I assume we need to use the (Resolution x 8.5) and (Resolution x 11) to set the Width and Height using the CreateNewGdPictureImage(Width, Height, BitLevel, Background) method.
Thanks for any help anyone can provide!
Rick Naff
Old Dominion Data Systems
We have an application that we are converting to use GdPicture that takes "legacy" reports from a file and converts them so they can be faxed (Tiff) or emailed (Pdf).
We are using the DrawText method to accomplish the burning of the text on the GdPicture Image...
There is a FontSetUnit(UnitMode) method to control the FontSize being used.
But we can not find a method to control the Unit of Measurement for X and Y co-ordinates of the DrawText method.
We would prefer to use inches if possible.
The question is...
What Unit of Measurement should be used for the X and Y co-ordinates.
Is it Pixels, Points, Inches, etc or does the "FontSetUnit" control that as well.
Also if we are wanting to create an 8.5 x 11 inch image...
I assume we need to use the (Resolution x 8.5) and (Resolution x 11) to set the Width and Height using the CreateNewGdPictureImage(Width, Height, BitLevel, Background) method.
Thanks for any help anyone can provide!
Rick Naff
Old Dominion Data Systems
Re: DrawText and Unit of Measure...
Hello,
So could somebody please give some input on the above so we can finish up the conversion?
Rick Naff
So could somebody please give some input on the above so we can finish up the conversion?
Rick Naff
-
- Posts: 352
- Joined: Tue Sep 27, 2011 11:47 am
Re: DrawText and Unit of Measure...
Hi,
The unit is in Pixels.
Also your assumption about image creation is absolutely correct. You need to multiply the Horizontal and Vertical Resolutions by their respective dimensions.
Best,
Sami
The unit is in Pixels.
Also your assumption about image creation is absolutely correct. You need to multiply the Horizontal and Vertical Resolutions by their respective dimensions.
Best,
Sami
Re: DrawText and Unit of Measure...
Thanks Sami,
That is what we needed (although it would be nice for that to be spelled out somewhere in the documentation)...
We shall probably just have all the measurements including Font Size in pixels, so all the conversions are consistent.
So we should use similar conversions for the Font Size and X/Y co-ordinates? Assuming 6 Cpi and 6 Lpi...
Resolution / 6 = Font Size
Resolution / 6 = X and Y increments
Thanks a bunch!
Rick Naff
That is what we needed (although it would be nice for that to be spelled out somewhere in the documentation)...
We shall probably just have all the measurements including Font Size in pixels, so all the conversions are consistent.
So we should use similar conversions for the Font Size and X/Y co-ordinates? Assuming 6 Cpi and 6 Lpi...
Resolution / 6 = Font Size
Resolution / 6 = X and Y increments
Thanks a bunch!
Rick Naff
-
- Posts: 352
- Joined: Tue Sep 27, 2011 11:47 am
Re: DrawText and Unit of Measure...
Hi,
>>So we should use similar conversions for the Font Size and X/Y co-ordinates? Assuming 6 Cpi and 6 Lpi...
>>Resolution / 6 = Font Size
>>Resolution / 6 = X and Y increments
I do not understand, do you have your current measurement of FontSize in inches?
If your X,Y (ie Left and Top) positions are in Inches, you need to follow the same logic: Resolution X Position
If there is something I am not following please tell me.
Best,
Sami
>>So we should use similar conversions for the Font Size and X/Y co-ordinates? Assuming 6 Cpi and 6 Lpi...
>>Resolution / 6 = Font Size
>>Resolution / 6 = X and Y increments
I do not understand, do you have your current measurement of FontSize in inches?
If your X,Y (ie Left and Top) positions are in Inches, you need to follow the same logic: Resolution X Position
If there is something I am not following please tell me.
Best,
Sami
Re: DrawText and Unit of Measure...
Hey Sami,
Yes, the previous toolkit allowed everything to be in inches. We are converting "legacy" reports from a Unix Server...
Left, Top, Right and Bottom margins in inches
Characters per inch --- either 10, 12 or 16.5
Lines per inch --- either 6 or 8
As we populate the image with the text from the report file, we "increment" the horizontal and vertical positions of the text on the image accordingly.
Since in GdPicture the only Unit of Measurement we can control by inch is Font Size:
For consistency it is easier to convert everything to pixels based on the Resolution --- usually 200 or 300 dpi. Hence...
FontSizePixels = Resolution / 10 --- or 12 or 16.5 Characters Per Inch
VerticalSizePixels = Resolution / 6 --- or 8 Lines Per Inch
MarginPixels = Resolution x Margin --- in Inches
I think I have a grip on it and actually using the pixels gives us a bit finer control of the text size and increments...
We shall see sometime today
Thanks for your interest Sami!
Rick Naff
Yes, the previous toolkit allowed everything to be in inches. We are converting "legacy" reports from a Unix Server...
Left, Top, Right and Bottom margins in inches
Characters per inch --- either 10, 12 or 16.5
Lines per inch --- either 6 or 8
As we populate the image with the text from the report file, we "increment" the horizontal and vertical positions of the text on the image accordingly.
Since in GdPicture the only Unit of Measurement we can control by inch is Font Size:
For consistency it is easier to convert everything to pixels based on the Resolution --- usually 200 or 300 dpi. Hence...
FontSizePixels = Resolution / 10 --- or 12 or 16.5 Characters Per Inch
VerticalSizePixels = Resolution / 6 --- or 8 Lines Per Inch
MarginPixels = Resolution x Margin --- in Inches
I think I have a grip on it and actually using the pixels gives us a bit finer control of the text size and increments...
We shall see sometime today
Thanks for your interest Sami!
Rick Naff
Re: DrawText and Unit of Measure...
Howdy,
An update on this...
I was NOT able to get the FontSetUnit (UnitMode_Pixels) in combination with the DrawText method to work.
I also tried using FontSetUnit (UnitMode_Inches) with the same results.
Both of the above yielded a Font Size that was way too small (only going half way across the page).
We are using VB6 and COM/ActiveX.
Fortunately the default FontUnit when creating the GdPicture object is in Points...
Using this method, everything works fine with a bit of tweaking on the Margins and Point Sizes.
The resulting Tiff Image sizes are perfect!
Converting the Tiff to a PDF using GdPictureimaging yields an 8.5 x 11 Pdf which is also perfect!
So the end result is we are using Pixels for the Horizontal and Vertical co-ordinates and the Font Size is in Points.
I am wondering if there might be some sort of problem with GdPicture's implementation of the FontSetUnit method...
We are currently using GdPicture Version 10.2.18.
Any additional help on the above is appreciated.
Rick Naff
An update on this...
I was NOT able to get the FontSetUnit (UnitMode_Pixels) in combination with the DrawText method to work.
I also tried using FontSetUnit (UnitMode_Inches) with the same results.
Both of the above yielded a Font Size that was way too small (only going half way across the page).
We are using VB6 and COM/ActiveX.
Fortunately the default FontUnit when creating the GdPicture object is in Points...
Using this method, everything works fine with a bit of tweaking on the Margins and Point Sizes.
The resulting Tiff Image sizes are perfect!
Converting the Tiff to a PDF using GdPictureimaging yields an 8.5 x 11 Pdf which is also perfect!
So the end result is we are using Pixels for the Horizontal and Vertical co-ordinates and the Font Size is in Points.
I am wondering if there might be some sort of problem with GdPicture's implementation of the FontSetUnit method...
We are currently using GdPicture Version 10.2.18.
Any additional help on the above is appreciated.
Rick Naff
Last edited by OddsInc on Fri Jun 13, 2014 12:58 pm, edited 1 time in total.
Re: DrawText and Unit of Measure...
Hello All,
Just wondering if anyone at GdPicture has looked into the Unit of Measure issue mentioned above?
And while I have your attention...
This might be better placed in the PDF section.
But it's come up in the project mentioned above and I shall ask my question here.
Below is the code we are using to do the Tiff and Pdf creation mentioned above...
This results in Image files where the "Text" is NOT selectable to copy/paste via GdViewer or Acrobat Reader.
This is fine for most documents we want to exchange via email.
However there are situations where we want the ability to select/copy/paste the text from the resulting image...
We don't need OCR or indexing, just the ability to select/copy/paste (especially in Adobe Reader).
How could the following code be modified to allow for that?
Have also attached a sample of the resulting images...
Any help is appreciated and Happy Father's Day to all!
Rick Naff
Just wondering if anyone at GdPicture has looked into the Unit of Measure issue mentioned above?
And while I have your attention...
This might be better placed in the PDF section.
But it's come up in the project mentioned above and I shall ask my question here.
Below is the code we are using to do the Tiff and Pdf creation mentioned above...
This results in Image files where the "Text" is NOT selectable to copy/paste via GdViewer or Acrobat Reader.
This is fine for most documents we want to exchange via email.
However there are situations where we want the ability to select/copy/paste the text from the resulting image...
We don't need OCR or indexing, just the ability to select/copy/paste (especially in Adobe Reader).
How could the following code be modified to allow for that?
Have also attached a sample of the resulting images...
Any help is appreciated and Happy Father's Day to all!
Rick Naff
Code: Select all
Function Format_Document(msFilePath As String, msFileBase As String, msDocsIden As String, msAttachName As String, mlDocsType As DocumentFormat, mnResolution As Integer) As Long
On Error GoTo ZZProc_Error
Dim mlStatus As Long
Dim mnImageId0 As Long
Dim mnImageId1 As Long
Dim mnImpFile As Integer
Dim mbNewLine As Boolean
Dim mbNewPage As Boolean
Dim mnPage As Integer
Dim mnFont As Integer
Dim mnTopMargin As Single
Dim mnBottomMargin As Single
Dim mnLeftMargin As Single
Dim mnLpi As Single
Dim mnFontSize As Single
Dim mnWidth As Long
Dim mnHeight As Long
Dim mnCurrentX As Single
Dim mnCurrentY As Single
Dim mnTextColor As Long
Dim mnBackground As Long
Dim mcChar As String
Dim msImpLine As String
Dim msImageName As String
mnImageId0 = 0
mnImageId1 = 0
mnPage = 0
' Convert Image Size to Pixels
mnWidth = mnResolution * 8.5
mnHeight = mnResolution * 11
' 10 Characters Per Inch in Points
mnFontSize = 11.5
' Convert 6 Lines Per Inch to Pixels
mnLpi = mnResolution / 6
' Convert Margins to Pixels
mnTopMargin = mnResolution * .25
mnBottomMargin = mnResolution * .25
mnLeftMargin = mnResolution * .25
' Initalize/Create GdPicture
Dim oImaging1 As New GdPictureImaging
Dim mnImageStatus As GdPictureStatus
Dim msImageStatus As String
msImageName = sTempPath & "\" & msDocsIden & ".tif"
' Set Font Style to Bold
Dim mnFontStyle As FontStyle
mnFontStyle = FontStyle.FontStyle_FontStyleBold
' Black Text with White Background
mnTextColor = oImaging1.ARGB(255, 0, 0, 0)
mnBackground = oImaging1.ARGB(255, 255, 255, 255)
' Open Input Text File and Start reading
mnImpFile = Open_ImpFile(msFilePath & "\" & msFileBase)
mcChar = Read_ImpChar(mnImpFile)
Format_NewPage:
msImageStatus = "Create Image"
mnImageId0 = oImaging1.CreateNewGdPictureImage(mnWidth, mnHeight, 24, mnBackground)
If (mnImageId0 = 0) Then GoTo ZZProc_ImageError
msImageStatus = "Set Horizontal Res"
mnImageStatus = oImaging1.SetHorizontalResolution(mnImageId0, mnResolution)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
msImageStatus = "Set Vertical Res"
mnImageStatus = oImaging1.SetVerticalResolution(mnImageId0, mnResolution)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
mnCurrentX = mnLeftMargin
mnCurrentY = mnTopMargin
mnPage = mnPage + 1
mbNewPage = False
Do Until EOF(mnImpFile)
msImpLine = ""
mbNewLine = False
Do Until (EOF(mnImpFile) And mcChar = "")
Select Case mcChar
Case vbCr
mcChar = Read_ImpChar(mnImpFile)
If (mcChar <> vbLf) Then Exit Do
Case vbLf
mcChar = Read_ImpChar(mnImpFile)
mbNewLine = True
Exit Do
Case vbFormFeed
If (msImpLine > "") Then Exit Do
mcChar = Read_ImpChar(mnImpFile)
mbNewPage = True
Exit Do
Case Else
msImpLine = msImpLine & mcChar
mcChar = Read_ImpChar(mnImpFile)
End Select
Loop
msImageStatus = "Draw Text"
mnImageStatus = oImaging1.DrawText(mnImageId0, msImpLine, mnCurrentX, mnCurrentY, mnFontSize, mnFontStyle, mnTextColor, sFontName, True)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
mnCurrentX = mnLeftMargin
If (mbNewPage = True) Then Exit Do
If (mbNewLine = True) Then mnCurrentY = mnCurrentY + mnLpi
Loop
msImageStatus = "Convert To 1Bpp"
mnImageStatus = oImaging1.ConvertTo1Bpp(mnImageId0)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
msImageStatus = "Add Page To Tiff"
If (mnPage > 1) Then
mnImageStatus = oImaging1.TiffAddToMultiPageFile(mnImageId1, mnImageId0)
Else
mnImageStatus = oImaging1.TiffSaveAsMultiPageFile(mnImageId0, msImageName, TiffCompression.TiffCompression_TiffCompressionCCITT4)
mnImageId1 = mnImageId0
End If
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
mnImageStatus = oImaging1.ReleaseGdPictureImage(mnImageId0)
mnImageId0 = 0
If (mbNewPage = True) Then GoTo Format_NewPage
Format_EndDoc:
msImageStatus = "Finalize Multi-Page Tiff"
mnImageStatus = oImaging1.TiffCloseMultiPageFile(mnImageId1)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
mnImageStatus = oImaging1.ReleaseGdPictureImage(mnImageId1)
mnImageId1 = 0
If (mlDocsType <> DocumentFormat.DocumentFormat_DocumentFormatPDF) Then GoTo Format_Finish
Format_EndPdf:
msImageStatus = "Open Tiff Image"
mnImageId1 = oImaging1.CreateGdPictureImageFromFile(msImageName)
If (mnImageId1 = 0) Then GoTo ZZProc_ImageError
msImageStatus = "Save As Pdf Image"
mnImageStatus = oImaging1.PdfCreateFromMultipageTIFF(mnImageId1, msAttachName, False, msDocsIden, sCompany, "", "", MESSENGER_CAPTION)
If (mnImageStatus <> GdPictureStatus_OK) Then GoTo ZZProc_ImageError
mnImageStatus = oImaging1.ReleaseGdPictureImage(mnImageId1)
mnImageId1 = 0
Format_Finish:
mlStatus = True
GoTo ZZProc_Exit
ZZProc_ImageError:
' Get GdPicture Status and Descriptive Error Message
mnImageStatus = oImaging1.GetStat()
Call Err.Raise((vbObjectError + mnImageStatus), msImageStatus, GdPicture_GetError(mnImageStatus))
GoTo ZZProc_Error
ZZProc_Error:
' Log Errors Using Our Logging Function
Log_CurrentError FORMATDOCUMENT_CAPTION
mlStatus = False
GoTo ZZProc_Exit
ZZProc_Exit:
On Error Resume Next
If (mnImpFile > -1) Then mnImpFile = Close_ImpFile(mnImpFile)
If (mnImageId0 <> 0) Then mnImageStatus = oImaging1.ReleaseGdPictureImage(mnImageId0)
If (mnImageId1 <> 0) Then mnImageStatus = oImaging1.ReleaseGdPictureImage(mnImageId1)
oImaging1.Dispose
Format_Document = mlStatus
End Function
- Attachments
-
- 132 Characters Per Line
- Msg01_20140613_0711503.tif (37.72 KiB) Viewed 8000 times
-
- 96 Characters Per Line
- Msg01_20140613_0711452.tif (35.47 KiB) Viewed 8000 times
-
- 80 Characters Per Line
- Msg01_20140613_0711381.tif (36.19 KiB) Viewed 8000 times
Re: DrawText and Unit of Measure...
Hello All,
So I haven't noticed much activity lately...
Other than the "junk" being put on here by "forum spammers".
Could someone please help with the above...
If the basics were spelled out somewhere in the documentation or on the forum, then I would not be asking.
Thanks for any help provided...
Rick Naff
So I haven't noticed much activity lately...
Other than the "junk" being put on here by "forum spammers".
Could someone please help with the above...
If the basics were spelled out somewhere in the documentation or on the forum, then I would not be asking.
Thanks for any help provided...
Rick Naff
Re: DrawText and Unit of Measure...
Hello Rick,
I've read this ticket 5 times but I do do understand what the problem is. Your previously said that you found a solution on 5th June and some day after you providing a code snippet that we can not use.
From my side I do not see any problem with the GdPicture text drawing method.
So if the problem persists please try to explain what you are doing (illustrated by a code snippet that we can use "as is"), what you've obtained and what you've expected to obtain.
Kind regards,
Loïc Carrère
I've read this ticket 5 times but I do do understand what the problem is. Your previously said that you found a solution on 5th June and some day after you providing a code snippet that we can not use.
From my side I do not see any problem with the GdPicture text drawing method.
So if the problem persists please try to explain what you are doing (illustrated by a code snippet that we can use "as is"), what you've obtained and what you've expected to obtain.
Kind regards,
Loïc Carrère
Re: DrawText and Unit of Measure...
Thanks Loic and hope you had a good weekend!
The "work around" solution was to use Points for the Unit of Measure for the DrawText method...
Could not get Pixels or Inches to work as indicated above.
The font size was too small no matter what value was used.
So am using Points for the font and Pixels for the X/Y co-ordinates.
For consistency I wanted to use Pixels for all of them. But it works, so I am going with it.
I was reporting what I found on the Unit of Measurement as a possible problem for you to investigate.
For my most recent question, all I really want to know is...,
How do I create a PDF that allows the copy/paste of "selected" text in Adobe Reader.
As opposed to it selecting the whole page/image when you click on it.
Sorry you could not use my snippet of code as is
It was meant as a reference as to what I would be starting with.
I am not asking for you write the code for me, just looking for the PDF methods to do the above.
If I can take an existing TIFF and convert it to a PDF and accomplish that, then great.
If I have to use GdPicturePDF to create/populate/save, then so be it.
Thanks again for any help you can provide...
Rick Naff
The "work around" solution was to use Points for the Unit of Measure for the DrawText method...
Could not get Pixels or Inches to work as indicated above.
The font size was too small no matter what value was used.
So am using Points for the font and Pixels for the X/Y co-ordinates.
For consistency I wanted to use Pixels for all of them. But it works, so I am going with it.
I was reporting what I found on the Unit of Measurement as a possible problem for you to investigate.
For my most recent question, all I really want to know is...,
How do I create a PDF that allows the copy/paste of "selected" text in Adobe Reader.
As opposed to it selecting the whole page/image when you click on it.
Sorry you could not use my snippet of code as is
It was meant as a reference as to what I would be starting with.
I am not asking for you write the code for me, just looking for the PDF methods to do the above.
If I can take an existing TIFF and convert it to a PDF and accomplish that, then great.
If I have to use GdPicturePDF to create/populate/save, then so be it.
Thanks again for any help you can provide...
Rick Naff
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest