Print Page | Close Window

INFO

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=1164
Printed Date: 17 Dec 25 at 4:47AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: INFO
Posted By: Dario
Subject: INFO
Date Posted: 04 Aug 09 at 11:21PM
HI, How can I setting the FONT style when using the function DrawText?
Thanks and Best Regards



Replies:
Posted By: Dario
Date Posted: 17 Aug 09 at 11:00PM
I try to do a question in different way.....
Is it possible to change the FONT STYLE with the function DrawText?
Thanks


Posted By: Michel_K17
Date Posted: 18 Aug 09 at 12:54AM
Sure. See my sample VB6 code here which shows you how I Bold/Italicize (basically, I use the appropriate font).  Cheers!

Private Function PDF_Apply_Text(Pages As String, Location As String, Layer As String, WebLink As String, JavaScript As String, Text As String, StdFontID As String, TextStyle As String) As Boolean
    
    ' StdFontID, as follows,
    '    0 = Courier
    '    1 = CourierBold
    '    2 = CourierBoldOblique
    '    3 = CourierOblique
    '    4 = Helvetica
    '    5 = HelveticaBold
    '    6 = HelveticaBoldOblique
    '    7 = HelveticaOblique
    '    8 = TimesRoman
    '    9 = TimesBold
    '    10 = TimesItalic
    '    11 = TimesBoldItalic
    '    12 = Symbol        << I am not supporting this for now
    '    13 = ZapfDingbats << I am not supporting this for now
    
    ' Text Style, as follows,
    '   - Underline
    '   [T=255,255,255] - Text Color + RGB
    '   [B=255,255,255] - Highlight (Back) Color + RGB (in Hex)
    
    ' Pages
    '   Case "0" - 1st Page Only
    '   Case "1" - All Pages
    '   Case "2" - Last Page Only
    '   Case "3" - New Page in Front
    '   Case "4" - New Page out back
    '   Case "5" - From 2nd Page up to Last Page
    '   Case "6" - From 1st Page up to Second-to-Last Page

    ' Location
    '   0 = Upper LH
    '   1 = Upper Center
    '   2 = Upper RH
    '   3 = Center
    '   4 = Center (stretched) - already calculated above
    '   5 = Lower LH
    '   6 = Lower Center
    '   7 = Lower RH
    '   8 = Lower Center + Left Offset (for Navigation Buttons)
    '   9 = Lower Center + Right Offset (for Navigation Buttons)
    
    ' Layer As String
    ' WebLink As String
    ' JavaScript As String
    
    
    Dim Newlayer As Long
    Dim x As Long, y As Long
'    Dim colors(2) As Double
    Dim PageWidth As Double, PageHeight As Double
    
    ' Trap Errors
    On Error GoTo Error_Handler
       
    ' Find the number of fonts in the document
    k = oPDF.FindFonts
    
    If k > 0 Then
        ' Get the Font Name
        '   WARNING: Font names are different than in the reference manual!
        '            Added "-" (hyphen) separator to match what is in document
        If StdFontID = 0 Then Temp = "Courier"
        If StdFontID = 1 Then Temp = "Courier-Bold"
        If StdFontID = 2 Then Temp = "Courier-BoldOblique"
        If StdFontID = 3 Then Temp = "Courier-Oblique"
        If StdFontID = 4 Then Temp = "Helvetica"
        If StdFontID = 5 Then Temp = "Helvetica-Bold"
        If StdFontID = 6 Then Temp = "Helvetica-BoldOblique"
        If StdFontID = 7 Then Temp = "Helvetica-Oblique"
        If StdFontID = 8 Then Temp = "Times-Roman"
        If StdFontID = 9 Then Temp = "Times-Bold"
        If StdFontID = 10 Then Temp = "Times-Italic"
        If StdFontID = 11 Then Temp = "Times-BoldItalic"
'        If StdFontID = 12 Then Temp = "Symbol        << I am not supporting this for now"
'        If StdFontID = 13 Then Temp = "ZapfDingbats << I am not supporting this for now        if stdfontid ="
       
        ' Check to see if any of the fonts match the font planned
        For i = 1 To k
            ' Get the next font
            rtn = oPDF.FontID(i)
            rtn = oPDF.SelectFont(rtn)
            ' See if we have a match
            If Temp = oPDF.FontName Then GoTo FontSelectionCompleted
        Next i
    End If
NoFontsFound:
    
    ' Add the appropriate standard font to the document
    oPDF.SelectFont oPDF.AddStandardFont(Val(StdFontID))
    
FontSelectionCompleted:

    ' Add a space in from & behind of text so that it is not scruntched against edge
    Text = " " & Text & " "
    
    ' Text Alignment
    ' Alignment is automatic based on which corner is selected
        '   0 = Upper LH        << LH Aligned
        '   1 = Upper Center    << Center Aligned
        '   2 = Upper RH        << RH Aligned
        '   3 = Center          << Center Aligned
        '   4 = Center (stretched) - already calculated above   << Center Aligned
        '   5 = Lower LH        << LH Aligned
        '   6 = Lower Center    << Center Aligned
        '   7 = Lower RH        << RH Aligned
        '   8 = Lower Center + Left Offset (for Navigation Buttons) << Not Applicable
        '   9 = Lower Center + Right Offset (for Navigation Buttons) << Not Applicable
    Select Case Location
        Case "0", "5"
            ' Left align if appropriate
            oPDF.SetTextAlign 0
        Case "2", "7"
            ' Right align if appropriate
            oPDF.SetTextAlign 2
        Case Else
            ' Center aligned
            oPDF.SetTextAlign 1
    End Select
    
    If Location <> "4" Then
        ' Set the Text Size (default is 12)
        If InStr(1, TextStyle, "[S=") <> 0 Then oPDF.SetTextSize Int(Mid$(TextStyle, InStr(1, TextStyle, "[S=") + 3, 3))
    
        ' Set Text Underline
        '    0 = None, 1 = Single, 2 = Double, 3 = Strikeout, 4 = Over
        oPDF.SetTextUnderline 0
        If InStr(1, TextStyle, "") <> 0 Then oPDF.SetTextUnderline 1
       
        ' Setup Text Background
        '    0 = None, 1 = Square, 2 = Rounded
        oPDF.SetTextHighlight 1
       
        ' Setup Text Highlight (Background) Color (RGB from 0.0 (none) to 1.0 (max))
        i = InStr(1, TextStyle, "[B=") + 3
        oPDF.SetTextHighlightColor CDbl(Mid$(TextStyle, i, 3)) / 255, CDbl(Mid$(TextStyle, i + 4, 3)) / 255, CDbl(Mid$(TextStyle, i + 8, 3)) / 255
       
        ' Text Color
        i = InStr(1, TextStyle, "[T=") + 3
        oPDF.SetTextColor CDbl(Mid$(TextStyle, i, 3)) / 255, CDbl(Mid$(TextStyle, i + 4, 3)) / 255, CDbl(Mid$(TextStyle, i + 8, 3)) / 255
       
        ' Setup the Text Style
        '    0 = Filled text (default), 1 = Outline text
        oPDF.SetTextMode 0
    
    Else
        ' Center+ Stretched = 60 pts text size, No underline, No background + Outline Text + 50% Transparent
        oPDF.SetTextSize 60
        oPDF.SetTextUnderline 0
        oPDF.SetTextHighlight 0
        oPDF.SetTextMode 1
    End If
    
    ' Save the Text Style for future use, because the style is lost
    ' everytime the page is changed
    oPDF.SaveStyle "MyStyle"
    
    ' Check to see if this is a business card. - IN FRONT
    If Pages = "3" Then
        olog.WriteLog "Apply Text on own page in front"
        rtn = oPDF.SelectPage(1)
        rtn = oPDF.InsertPages(1, 1)
    End If
    
    ' Check to see if this is a business card - AT BACK
    If Pages = "4" Then
        olog.WriteLog "Apply Text on own page at back"
        rtn = oPDF.SelectPage(oPDF.PageCount)
        i = oPDF.PageRotation
        rtn = oPDF.NewPage
        If i <> 0 Then oPDF.RotatePage (90)
    End If
    
    ' Get ready to apply the stamp to the document
    ' Capture the Stamp (Crop Box) - This will remove it.
'    oLog.WriteLog "Capture the Stamp"
'    hCaptStamp = oPDF.CapturePageEx(oPDF.PageCount, 1)
    
    ' Calculate Start & End Pages
    ' Default pages setup so that we do not run
    i = 1: j = 0
    Select Case Pages
        Case "0", "3"
            ' 1st Page Only
            i = 1: j = 1
            
        Case "1"
            ' All Pages
            i = 1: j = oPDF.PageCount
            
        Case "2", "4"
            ' Last Page Only
            i = oPDF.PageCount: j = oPDF.PageCount
            
        Case "5"
            ' From 2nd Page up to Last Page
            If oPDF.PageCount > 1 Then i = 2: j = oPDF.PageCount
            
        Case "6"
            ' From 1st Page up to Second-to-Last Page
            If oPDF.PageCount > 1 Then i = 1: j = oPDF.PageCount - 1
            
    End Select
    
    ' Apply Text to each page selected
    For k = i To j
    
        olog.WriteLog "Apply Text to Page" & Str$(k)
       
        ' Get info about the next page (using cropbox size (2))
        rtn = oPDF.SelectPage(k)
        olog.WriteLog "PDF.SelectPage(k) - Apply Text to Page" & Str$(k)
       
        ' Substitute Page Number if needed
        Temp = Replace(Text, "<#>", Trim$(Str$(k)))
       
       
'        pagewidth = oPDF.GetPageBox(2, 2)
'        pageheight = oPDF.GetPageBox(2, 3)
       
        ' Re-apply the text style (gets lost everytime the next page is selected)
        oPDF.ApplyStyle ("MyStyle")
       
        ' Apply No Transparency.
        ' Cannot save this as part of Text Style, so it must be applied here.
        rtn = oPDF.SetTransparency(0)
       
        ' Create a new layer if stamp goes underneath
        If Layer = "#FALSE#" Then
            Newlayer = oPDF.Newlayer
            rtn = oPDF.SelectLayer(Newlayer)
        End If
       
        ' Transfer the Stamp onto that page
        ' Position as follows:
        '   0 = Upper LH
        '   1 = Upper Center
        '   2 = Upper RH
        '   3 = Center
        '   4 = Center (stretched) - already calculated above
        '   5 = Lower LH
        '   6 = Lower Center
        '   7 = Lower RH
        '   8 = Lower Center + Left Offset (for Navigation Buttons)
        '   9 = Lower Center + Right Offset (for Navigation Buttons)
       
        ' Check for page rotation.
        If oPDF.PageRotation = 0 Then
            ' Set origin to Upper LH
            rtn = oPDF.SetOrigin(1)
            PageHeight = oPDF.PageHeight
            PageWidth = oPDF.PageWidth
        Else
            ' Set origin to Lower LH (before page is rotated for viewing)
            rtn = oPDF.SetOrigin(0)
            ' In this rotation, X&Y are reversed, Height is Width & Vice versa
            PageHeight = oPDF.PageWidth
            PageWidth = oPDF.PageHeight
        End If
    
        Select Case Location
            Case "0" ' Upper LH
               x = 0
               y = 0 + oPDF.GetTextBound(2)
            Case "1" ' Upper Center
               x = PageWidth / 2
               y = 0 + oPDF.GetTextBound(2)
            Case "2" ' Upper RH
               x = PageWidth
               y = 0 + oPDF.GetTextBound(2)
            Case "3" ' Center
               x = PageWidth / 2
               y = (PageHeight + oPDF.GetTextAscent) / 2
            Case "4" ' Center
               ' Stretch the Text to smallest of PageWidth or PageHeight
               If PageWidth > PageHeight Then '(PageWidth > PageHeight And oPDF.PageRotation = 0) Or (PageWidth < PageHeight And oPDF.PageRotation <> 0) Then
                    oPDF.SetTextSize (PageHeight / oPDF.GetTextWidth(Temp)) * oPDF.GetTextSize * 1.2
               Else
                    oPDF.SetTextSize (PageWidth / oPDF.GetTextWidth(Temp)) * oPDF.GetTextSize * 1.3
               End If
               ' Calculate X/Y position before rotation
               x = PageWidth / 2
               y = (PageHeight + oPDF.GetTextAscent) / 2
               ' Apply trigonometry because ctr of Rotation is located at Baseline
               ' instead of center of character. Displace Ctr of rotation
               ' accordingly, so that text is centered on page
               ' X = X + dX where dX = H.cos45 and H = GetTextAscent/2
               ' Y = Y - dY where dY = H - dX
               x = x + 0.354 * oPDF.GetTextAscent
               y = y - 0.146 * oPDF.GetTextAscent
               ' Apply Transparency (because the Text Colour is ignored so grey is black)
               ' Cannot save this as part of Text Style, so it must be applied here.
               rtn = oPDF.SetTransparency(50)
              
            Case "5" ' Lower LH
               x = 0
               y = PageHeight + oPDF.GetTextBound(4)
            Case "6" ' Lower Center
               x = PageWidth / 2
               y = PageHeight + oPDF.GetTextBound(4)
            Case "7" ' Lower RH
               x = PageWidth
               y = PageHeight + oPDF.GetTextBound(4)
'               Case "8" ' Lower & Center + Left Offset
'                    X = ((PageWidth - oPDF.GetTextWidth(Text)) / 2) - oPDF.GetTextWidth(Text) / 1.5
'                    Y = PageHeight - oPDF.GetTextHeight
'               Case "9" ' Lower & Center + Right Offset
'                    X = ((PageWidth - oPDF.GetTextWidth(Text)) / 2) + oPDF.GetTextWidth(Text) / 1.5
'                    Y = PageHeight - oPDF.GetTextHeight
        End Select
            
        ' Set text rotation to 45 degrees if central/stretched
        i = 0
        If Location = "4" Then i = 45
       
        ' Apply the text to the page
        If oPDF.PageRotation = 0 Then
            rtn = oPDF.DrawRotatedText(x, y, i, Temp)
        Else
            rtn = oPDF.DrawRotatedText(y, x, 90 + i, Temp)
        End If
       
            ' Apply the web link (if not empty)
            If WebLink <> "" Or JavaScript <> "" Then
               ' Calculate Hot spot box
               Select Case Location
                    Case "0", "5"
                        ' Left align: no change to X
                    Case "2", "7"
                        ' Right align. X moves to the left
                        x = x - oPDF.GetTextWidth(Temp)
                    Case Else
                        ' Center aligned. X moves 1/2 way of width
                        x = x - oPDF.GetTextWidth(Temp) / 2
               End Select
               ' Y position moves to top of text box
               y = y - oPDF.GetTextBound(2)
               If WebLink <> "" Then
                    If oPDF.PageRotation = 0 Then
                        rtn = oPDF.AddLinkToWeb(x, y, oPDF.GetTextWidth(Temp), oPDF.GetTextHeight, WebLink, 0)
                    Else
'                        rtn = oPDF.AddLinkToWeb(Y, X, oPDF.GetTextHeight, oPDF.GetTextWidth(Temp), WebLink, 0)
                        rtn = oPDF.AddLinkToWeb(y, x + oPDF.GetTextWidth(Temp), oPDF.GetTextHeight, oPDF.GetTextWidth(Temp), WebLink, 0)
                    End If
               End If
               ' Apply JavaScript link (if requested)
               If JavaScript <> "" Then
                    If oPDF.PageRotation = 0 Then
                        rtn = oPDF.AddLinkToJavaScript(x, y, oPDF.GetTextWidth(Temp), oPDF.GetTextHeight, JavaScript, 0)
                    Else
'                        rtn = oPDF.AddLinkToJavaScript(Y, X, oPDF.GetTextHeight, oPDF.GetTextWidth(Temp), JavaScript, 0)
                        rtn = oPDF.AddLinkToJavaScript(y, x + oPDF.GetTextWidth(Temp), oPDF.GetTextHeight, oPDF.GetTextWidth(Temp), JavaScript, 0)
                    End If
               End If
            End If
       
    Next k
       
Save_Stamped_PDF:

    ' Close Access to stamp file - NO: It was deleted automatically when merged
    
    ' Success
    PDF_Apply_Text = True

    Exit Function
    
Error_Handler:
    ' An unexpected error occured. Log it. (MUST have this line first, or the Err object gets reset).
'    olog.LogError False, Err.Number, Err.Description, Err.LastDllError, "Apply Stamp"
    Resume Next
End Function




-------------
Michel


Posted By: Dario
Date Posted: 21 Aug 09 at 11:03AM
Thanks MICHEL for your replay, but you haven't answer my question...
If I want to draw my custom font or others fonts, it is impossible to do with different style?


Posted By: Ingo
Date Posted: 21 Aug 09 at 11:40AM
Hi Dario!

Did you test it?
What are the results?
If you want to use your own fonts you can add them as file with truetype- or type1-font-format, then select them, then use them.
Please have a look at the relevant functions in the font-section of the online-reference at:
http://www.quickpdflibrary.com/help/quickpdf/Fonts.php

Cheers, Ingo



Posted By: Dario
Date Posted: 21 Aug 09 at 8:59PM
OK, I resolved in different way.
I thought that as there is a command or FontSize or FontType or FONTNAME or SetTextColorCMYK there was also FontStyle ...
Thanks



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