Print Page | Close Window

HTMLTextBox ending y calculation

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1760
Printed Date: 08 Nov 25 at 4:42PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: HTMLTextBox ending y calculation
Posted By: rdmstrs
Subject: HTMLTextBox ending y calculation
Date Posted: 07 Mar 11 at 10:33PM
I am sure this is easier than I am making it. I am dynamically making an HTMLTextBox that can be on 1 page or infinite pages everything for that is working great, however I need to add some text and an image after the last box. I am having the toughest time calculating the y pos at the end of the box. I am using the line count and then multiplying that by my best guess at font height, however it is very inconsistent. Any ideas? I am working in vb.net with the activeX



Replies:
Posted By: rdmstrs
Date Posted: 07 Mar 11 at 10:37PM
I went back to the documentation after posting this just to make sure I didn't miss a function that returns text height and there it was. I will try it again using that.


Posted By: rdmstrs
Date Posted: 07 Mar 11 at 10:46PM
That didn't do the trick either.


Posted By: Rowan
Date Posted: 08 Mar 11 at 10:21AM
Can you post the code that you've got so far? Perhaps we'll be able to provide some tips on how to improve it.


Posted By: rdmstrs
Date Posted: 09 Mar 11 at 5:09PM

Here is the code, thanks for any help.

    Public Sub CreateDoc()
        Dim PDFLibrary As QuickPDFAX0723.PDFLibrary
        PDFLibrary = CType(CreateObject("QuickPDFAX0723.PDFLibrary"), QuickPDFAX0723.PDFLibrary)
        If PDFLibrary.UnlockKey("Unlock Key") = 1 Then
            PDFLibrary.AddImageFromFile(Application.StartupPath & "\Images\1.jpg", 0)
            PDFLibrary = WriteHeader(PDFLibrary)
            Dim Content As String = PDFLibrary.DrawHTMLTextBox(40, 635, 540, 570, Text(PDFLibrary))
            Dim LastPgContent As String = Content
            Dim hTBWidth As Double = PDFLibrary.GetHTMLTextWidth(540, Text(PDFLibrary))
            Dim hTBLineCount As Long = PDFLibrary.GetHTMLTextLineCount(hTBWidth, Text(PDFLibrary))
            Dim TextHeight As Double = PDFLibrary.GetHTMLTextHeight(540, Text(PDFLibrary))
            Dim MultiPg As Boolean = False
            PDFLibrary = WriteFooter(PDFLibrary)
            Do Until Content = ""
                PDFLibrary.NewPage()
                PDFLibrary = WriteHeader(PDFLibrary)
                If PDFLibrary.GetHTMLTextLineCount(540, Content) < 49 Then
                    LastPgContent = Content
                End If
                Content = PDFLibrary.DrawHTMLTextBox(40, 635, 540, 570, Content)
                PDFLibrary = WriteFooter(PDFLibrary)
                MultiPg = True
            Loop
            If MultiPg Then
                hTBWidth = PDFLibrary.GetHTMLTextWidth(540, LastPgContent)
                hTBLineCount = PDFLibrary.GetHTMLTextLineCount(hTBWidth, LastPgContent)
                TextHeight = PDFLibrary.GetHTMLTextHeight(540, LastPgContent)
            End If
            Dim y As Double = 1
            y = hTBLineCount * (TextHeight / hTBLineCount)
            PDFLibrary = WriteSig(PDFLibrary, y, 40)
            For i = 1 To PDFLibrary.PageCount
                PDFLibrary.SelectPage(i)
                PDFLibrary.DrawHTMLText(480, 775, 250, "<font size=""3""><b>Page " & i & " of " & PDFLibrary.PageCount & "</b></font>")
            Next
#If DEBUG Then
            PDFLibrary.SaveToFile("C:\Docs\Doc.pdf")
            'Dim PrintOp As Integer = PDFLibrary.PrintOptions(0, 0, "Doc")
            'PDFLibrary.PrintDocument("myPrinter", 1, PDFLibrary.PageCount, PrintOp)
#Else
            'Send file to server
#End If
        End If
        PDFLibrary = Nothing
    End Sub
    Function Text(ByVal myPdfLib As QuickPDFAX0723.PDFLibrary) As String
        Dim sText As String = "Some Strings"
        Return sText
    End Function
    Private Function WriteSig(ByVal oPDF As QuickPDFAX0723.PDFLibrary, ByVal y As Double, Optional ByVal left As Integer = 210) As QuickPDFAX0723.PDFLibrary
        Dim Last As String = "Last"
        If Last = "LastName" Or Last = "Other Lastname" Then
            oPDF.AddImageFromFile(Application.StartupPath & "\Images\Sig.jpg", 0)
            oPDF.DrawImage(left, (725 - y), 150, 45)
            Dim Sig As String = ""
            Sig = "Name<br>Title"
            oPDF.DrawHTMLTextBox(left, (725 - y) - 50, 375, 75, Sig)
        End If
        Return oPDF
    End Function
    Private Function WriteHeader(ByVal oPDF As QuickPDFAX0723.PDFLibrary) As QuickPDFAX0723.PDFLibrary
        oPDF.DrawImage(450, 750, 126, 94)
        oPDF.DrawLine(32, 760, 580, 760)
        oPDF.DrawLine(32, 645, 580, 645)
        oPDF.DrawHTMLText(480, 640, 250, "<font size=""6""><b>Title</b></font>")
        Return oPDF
    End Function
    Private Function WriteFooter(ByVal oPDF As QuickPDFAX0723.PDFLibrary) As QuickPDFAX0723.PDFLibrary
        oPDF.DrawLine(32, 45, 580, 45)
        Dim sFooter As String = "Address"
        oPDF.DrawHTMLText(32, 35, 548, "<p align=""center"">" & sFooter & "</Align>")
        Return oPDF
    End Function
 


Posted By: rdmstrs
Date Posted: 19 May 11 at 10:12PM
I was right, I was definitely making this more difficult than necessary. Just wanted to post what finally worked. getHTMLTextHeight does give you the correct amount of space taken and you simply subtract it from the top of your HTMLTextbox and there is your y value. I wasn't passing the correct html to the function when I tried testing it previously.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk