Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDF Generation and Mystery Mania
#21
I see what your are talking about. I will have to do some reading to understand how they work and maybe leverage them. I'm very intrigued.
Reply
#22
I've found a nice simple work around. Courier is a monospaced font so just set 'pdfLoadFont "F1", PDF_FONT_COURIER' and everything lines up nicely. 

It really would be nice to add a 'justify' command though.
Oh look. A sig line :-)
Reply
#23
[Image: pdf-Gen-Test2.jpg]

I think I'm getting the hang of this now


Code: (Select All)

'$Include:'pdfGen.bi'

pdfMediaBox 0, 0, 792, 612
'pdfMediaBox 0, 0, 612, 792
pdfAddPage
'pdfLoadFont "F1", PDF_FONT_TIMES_ROMAN
pdfLoadFont "F1", PDF_FONT_COURIER
pdfSetLeading 11

pdfBeginText
pdfSetFontSize "F1", 11
pdfSetPosition 16, 592


' This bit will be altered to read from a text file

t1$(1) = "A PAT Testing Company                                                                            Tel: 01234 098765"
t1$(2) = "32 Acacia Avenue                                                                                  Fax: 01234 987654"
t1$(3) = "Anothertown                                                                                      www.company.co.uk"
t1$(4) = "A County                                                                                  email sales@company.co.uk"
t1$(5) = "ZX99 1ZX                                                                                                          "
t1$(6) = ""
t1$(7) = "Test Instrument : Seaward Supernova              Serial No : x99-0000                Calibration Date : 05/11/2019"
t1$(8) = "-------------------------------------------------------------------------------------------------------------------"

For i = 1 To 8
    pdfAddText t1$(i)
    pdfNextLine
Next

pdfNextLine
pdfNextLine

' the next 2 lines will vary depending on user input
t2$(1) = "Appliance ID      Tested    Comment                      Vis Earth Ins Load Lkge Lead Flash  User        Result"
t2$(2) = "---------------  ----------  -----------                  --- ----- --- ---- ---- ---- -----  ----        ------"

pdfAddText t2$(1)
pdfNextLine
pdfAddText t2$(2)
pdfNextLine

' There will be a loop here to print the results



pdfEndText

pdfGen "pdfGenTest2.pdf"


Print "FINISHED!!"
'System
'$Include:'pdfGen.bm'
Oh look. A sig line :-)
Reply
#24
Very NICE!!!

I'm glad you found a work around. I spent some time reading about the justify, Its part of a much larger system, and quite frankly its a lot. Probably, may need to refactor some, just to lay the ground work and then get into the weeds of implementing it.

I've added another command that will help with large blocks of text where it spans multiple pages. I will try to post that tomorrow along with an example. 

I also added embedded Author and Creator in the PDF so that you can identify the source.

I really should put this in the GITHUB.
Reply
#25
Still not getting graphic files to load into the pdf but I really like the other things I'm seeing. Not difficult at all to  output vector graphics drawn inside a program to a pdf.
Reply
#26
(03-09-2025, 02:45 PM)James D Jarvis Wrote: Still not getting graphic files to load into the pdf but I really like the other things I'm seeing. Not difficult at all to  output vector graphics drawn inside a program to a pdf.
Could you post a copy of the PDF?
Reply
#27
[Image: image.png]

Here's a shot of the simple vector graphics. They aren't amazing to look at but are exactly what I sent to the pdf.
Reply
#28
LOL! Ok. Are you trying to display bitmaps, png's, or jpg?
Quote:img]data:image/png;base64
Are you using pdfLoadImage? pdfLoadImage loads the image using _loadimage(file,32) , and then transcodes into a character stream, then compresses it with _deflate$(stream) and then encodes it to ASCII85. This is what I have the filters set for in the PDF, if you're using something else the filters will have to be modified. Base64 is not in the list of compatible encodings.

By the way I can't reply to your private messages, apparently you have them disabled.
Reply
#29
I'm using the example you posted. The PNG files do NOT get placed visibly in the PDF. The vectors shown were added to a page.
Reply
#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




Users browsing this thread: 20 Guest(s)