Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDF Generation and Mystery Mania
#30
Here's the code. Just added a page and the simple drawing test to another page. the PNG files do not display. 

Code: (Select All)
'Simple PDF with Image Example
'$Include:'pdfGen.bi'

'Always Add page, you need a page to work on
pdfAddPage
'Always Load a Font, "F1" is it Identifier
'Only the built in fonts work, for now
pdfLoadFont "F1", PDF_FONT_TIMES_ROMAN
pdfLoadFont "F2", PDF_FONT_HELVETICA
pdfLoadFont "F3", PDF_FONT_HELVETICA_BOLD
'Load some Images, "Im1" and "Im2" are the identifiers
pdfSetImageDevice PDF_IMAGE_DEVICE_GRAY
pdfLoadImage "IMG.png", "Im1"
pdfSetImageDevice PDF_IMAGE_DEVICE_RGB
pdfLoadImage "img2.png", "Im2"
'Push the current graphic state to the stack
pdfPushGraphicsStack
'Set the Matrix to 100% scale in the X,Y and Translate to 245 ,340
pdfSetImageMatrix 100, 0, 0, 100, 245, 340
'Draw the Image "Im1"
pdfPutImage "Im1"
'Return the graphics state
pdfPopGraphicsStack

'Push the current graphic state to the stack
pdfPushGraphicsStack
'Set the Matrix to 200% scale in the X,Y and Translate to 50 ,250
pdfSetImageMatrix 200, 0, 0, 200, 50, 250
'Draw the Image "Im2"
pdfPutImage "Im2"
'Return the graphics state
pdfPopGraphicsStack

'Begin a Text Block, only do text stuff here
pdfBeginText
'Set font "F1" to size 36
pdfSetFontSize "F1", 36
'Move relative from 0,0 to 200,650. All positions are relative.
'To reset the position back to 0,0 end the text block and begin a new one.
pdfSetPosition 200, 650
'Draw some text
pdfAddText "Image Example"
'End the text block. Always end the text block!
pdfEndText


'Next Page
pdfAddPage

pdfPushGraphicsStack
'Begin a Text Block, only do text stuff here
pdfBeginText
'Set font "F1" to size 36
pdfSetFontSize "F3", 48
pdfSetPosition 200, 414
'Set the width of the outline
pdfSetStrokeWidth .25
'------------------------------------------------------------------------
'
' Text rendering modes
' MODE    DESCRIPTION
'  0      Fill text.
'  1      Stroke text.
'  2      Fill, then stroke text.
'  3      Neither fill nor stroke text (invisible).
'  4      Fill text and add to path for clipping (see above).
'  5      Stroke text and add to path for clipping.
'  6      Fill, then stroke text and add to path for clipping.
'  7      Add text to path for clipping.

pdfSetRenderMode 5
pdfAddText "QB64pe"
pdfEndText
pdfBeginText
pdfSetFontSize "F2", 6
pdfSetPosition 200, 450
pdfSetRenderMode 0
pdfSetLeading 6
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfAddText "QB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64peQB64pe": pdfNextLine
pdfEndText
pdfPopGraphicsStack


pdfAddPage
pdfBeginPath 100, 100
pdfAppendLine 200, 600
pdfStrokePath

w = 8
For x = 300 To 100 Step -50
    dpath$ = Str$(400 - x) + "," + Str$(x) + "," + Str$(300 - x) + "," + Str$(x) + "," + Str$(350 - x) + "," + Str$(400 - x)

    drawpath w, dpath$, "close"
    w = w - 1

Next x

'Generate The PDF
pdfGen "pdfGenTest.pdf"

System
'$Include:'pdfGen.bm'


Sub drawpath (thickness, spath$, closepath$)
    'draws a path
    'thickness is thickenss of path to be drawn in points
    'spath is a sting consisting of pairs of points all sepeated by commas
    'closepath$ is a flag telling the sub to close the endpoints of the path makign it a closed sjape
    '          Yes,Y,Close,Closed,C will all close the path
    SplitString spath$, ",", p$()
    pdfSetStrokeWidth thickness
    pdfBeginPath Val(p$(1)), Val(p$(2))
    For n = 3 To (UBound(p$)) - 1 Step 2
        pdfAppendLine Val(p$(n)), Val(p$(n + 1))
    Next n
    If LCase$(Left$(closepath$, 1)) = "y" Or LCase$(Left$(closepath$, 1)) = "c" Then pdfClosePath
    pdfStrokePath
    pdfSetStrokeWidth 1
End Sub
Sub SplitString (inputString$, delimiter$, wordArray$())
    ' Splits a string into an array of words based on a delimiter.
    ' Parameters:
    '  inputString$: The string to split.
    '  delimiter$:  The character(s) used to separate the words.
    '  wordArray$(): The array to store the resulting words.  *MUST BE DYNAMIC ARRAY*
    '  wordCount%:  The number of words found (returned by the SUB).
    wordCount% = 0
    startPos% = 1
    Do
        psn% = InStr(startPos%, inputString$, delimiter$) ' Find the next delimiter
        If psn% = 0 Then
            ' No more delimiters found, this is the last word
            word$ = Mid$(inputString$, startPos%)
            If Len(_Trim$(word$)) > 0 Then ' Check for empty word (e.g., multiple spaces)
                wordCount% = wordCount% + 1
                ReDim _Preserve wordArray$(wordCount%)
                wordArray$(wordCount%) = word$
            End If
            Exit Do ' Exit the loop
        Else
            ' Delimiter found, extract the word
            word$ = Mid$(inputString$, startPos%, psn% - startPos%)
            If Len(_Trim$(word$)) > 0 Then ' Check for empty word (e.g., multiple spaces)
                wordCount% = wordCount% + 1
                ReDim _Preserve wordArray$(wordCount%)
                wordArray$(wordCount%) = word$
            End If
            startPos% = psn% + Len(delimiter$) ' Move the starting position past the delimiter
        End If
    Loop
End Sub
Reply


Messages In This Thread
PDF Generation and Mystery Mania - by justsomeguy - 03-01-2025, 07:17 PM
RE: PDF Generation and Mystery Mania - by bplus - 03-01-2025, 07:22 PM
RE: PDF Generation and Mystery Mania - by James D Jarvis - 03-09-2025, 05:06 PM



Users browsing this thread: 37 Guest(s)