Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDF Generation and Mystery Mania
#11
@James D Jarvis and @Mad Axeman as of this last version I added a command called "pdfMediaBox" that allows you to set the size of the page. According to PDF spec the minimum is 3 x 3 (approximately 0.04 by 0.04 inch) and the maximum is 14,400 x 14,400  (200 by 200 inches).

The defaults are as pointed out are 612 x 792 (A4 paper size). To switch to landscape, simply switch 792 and 612.
'pdfMediaBox 0, 0, 792, 612'

You will need to do this before you add a page. Although, I have not tested it, you should be able to make each page a different size if you wish.

James I looked over your code, I'm not sure if you accomplished what you were trying to do, but all positions are relative. So, if you move to top middle, like 306,750, and you want to move to the next line. You could manually move down by using the pdfSetPosition 0, -30. Or if you have pdfSetLeading set to character height, you can use pdfNextLine.

If you want to print a block of text, you can use pdfAddTextBlock. You set maximum line length in characters, and it will automatically find the last space (I need to add hyphen) and start it on the next line. Of course pdfSetLeading has to be set as well.

Quote:I couldn't manage to get an image to load on the page but the text manipulation is working fine.

Quite frankly I'm not surprised. I apologize. I was so focused on making sure the encoding into the pdf was correct, I did not spend much time on the gathering of pixel data from the file. When it worked, I was so happy, I had to share it. This weekend if not sooner I'm going try to get the image stuff in a much better state.

Here is updated list of commands.

Code: (Select All)
SUB pdfAddPage
SUB pdfLoadFont (nm AS STRING, fnt AS STRING)
SUB pdfSetPosition (x AS LONG, y AS LONG)
SUB pdfAddText (s AS STRING)
SUB pdfAddTextBlock (l AS LONG, s AS STRING)
SUB pdfBeginText
SUB pdfEndText
SUB pdfNextLine
SUB pdfSetRenderMode (m AS LONG)
SUB pdfSetGrayScaleStroke (g AS SINGLE)
SUB pdfSetGrayScaleNonStroke (g AS SINGLE)
SUB pdfSetStrokeWidth (sw AS LONG)
SUB pdfSetCharacterSpacing (s AS SINGLE)
SUB pdfSetWordSpacing (s AS SINGLE)
SUB pdfSetHorizontalScaling (s AS LONG)
SUB pdfSetLeading (l AS SINGLE)
SUB pdfSetRise (l AS LONG)
SUB pdfRotateText (x AS LONG, y AS LONG, deg AS SINGLE)
SUB pdfSetMatrix (a AS SINGLE, b AS SINGLE, c AS SINGLE, d AS SINGLE, e AS SINGLE, f AS SINGLE)
SUB pdfSetImageMatrix (a AS SINGLE, b AS SINGLE, c AS SINGLE, d AS SINGLE, e AS SINGLE, f AS SINGLE)
SUB pdfPutImage (nm AS STRING)
SUB pdfSetFontSize (nm AS STRING, sz AS LONG)
SUB pdfBeginPath (x AS LONG, y AS LONG)
SUB pdfAppendLine (x1 AS LONG, y1 AS LONG)
SUB pdfAppendBezier123 (x1 AS LONG, y1 AS LONG, x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG)
SUB pdfAppendBezier23 (x2 AS LONG, y2 AS LONG, x3 AS LONG, y3 AS LONG)
SUB pdfAppendBezier13 (x1 AS LONG, y1 AS LONG, x3 AS LONG, y3 AS LONG)
SUB pdfClosePath
SUB pdfRectangle (x AS LONG, y AS LONG, w AS LONG, h AS LONG)
SUB pdfStrokePath
SUB pdfCloseStrokePath
SUB pdfFillPath
SUB pdfFillEO
SUB pdfFillStroke
SUB pdfFillStrokeEO
SUB pdfCloseFillStroke
SUB pdfCloseFillStrokeEO
SUB pdfEndPath
SUB pdfSetColorStroke (r AS SINGLE, g AS SINGLE, b AS SINGLE)
SUB pdfSetColorNonStroke (r AS SINGLE, g AS SINGLE, b AS SINGLE)
SUB pdfPushGraphicsStack
SUB pdfPopGraphicsStack
SUB pdfMediaBox (x AS LONG, y AS LONG, x1 AS LONG, y1 AS LONG)
SUB pdfLoadImage (f AS STRING, nm AS STRING)
SUB pdfGen (filename AS STRING)
Reply
#12
You've got nothing to apologize for. You've produced a very useful set of routines. Decades ago I used to do some coding for EPS documents so some of this makes quick sense to me. I've also dabbled with just producing simple pdf compatible output myself but came nowhere remotely close to this. Once again... it's great,  and thank you.
Reply
#13
Really grateful for what you have done. I've only had a very quick play due to work but I'm looking forward to getting to grips with things on the weekend. I'll let you know how I get on :-)
Oh look. A sig line :-)
Reply
#14
First all, Thank you for the support.

I made some progress color images. To conserve on the size of the PDF, you can select if the image will be grayscale or RGB. RGB adds a significant amount of data to the image. The default is set for RGB.

Code: (Select All)
pdfSetImageDevice PDF_IMAGE_DEVICE_GRAY ' for Grayscale
pdfSetImageDevice PDF_IMAGE_DEVICE_RGB 'for RGB

pdfSetMediaBox has been fixed. (I hope) You should be able to set each page to its own size, just do it before pdfAddPage

On the second page of the PDF is an example I found in the 1.0 specification that I though was neat.

Let me know if there is still problems with images. I'm using the Ubuntu default PDF viewer, so there may be some differences between implementations.

[Image: Screenshot-from-2025-03-06-18-32-52.png]


Attached Files Image(s)
       

.bi   pdfGen.bi (Size: 9.5 KB / Downloads: 14)
.bm   pdfGen.bm (Size: 32.8 KB / Downloads: 15)
.bas   pdfGenImageTest.bas (Size: 3.08 KB / Downloads: 13)
Reply
#15
I'm using the following sub which I pulled from your prog :-

Code: (Select All)

Sub AddLine (PR As _Byte, t As String)
    If PR Then
        ' Add text that is restricted in length,
        '  starts a new line after x characters.
        '  Will break on space, instead of mid word.
        pdfAddTextBlock 80, t
        ' new line
        pdfNextLine
    End If
End Sub

It's splitting the text at the 80 character point but it's not moving down to a new line. It's over writting the first part of the text. What have I missed??
Oh look. A sig line :-)
Reply
#16
You need to set the leading. It needs to be set for every page, if i remember correctly. Use the pdfSetLeading command. So if you are using Font size of 12 use something like 16.
Reply
#17
That did it. Thanks :-)
Oh look. A sig line :-)
Reply
#18
Is there a way to auto justify both left and right? 
Basically I'm printing 4 lines of text full width on a landscape A4. If I print to screen or printer because the standard font (I assume) uses equal space for all letters all four lines start and end in the same column. I'm assuming the PDF uses different spacing for different size letters (so I would take up less space than O for example) so the right column is jagged. Could
pdfSetCharacterSpacing or SUB pdfSetWordSpacing somehow be used or is there a simple way around this that I can't think of?
Oh look. A sig line :-)
Reply
#19
The short answer is, no. The long answer is there may be a bit of a complicated workaround.

QB has a command called _PRINTWIDTH. If you are on a Windows, or maybe Mac machine, then most likely the Type 1 Fonts that pdfGen uses are built in. You could perhaps, pre-render the text in some appropriate graphics mode, and obtain the _PRINTWIDTH for each line, and interpolate the spacing using pdfSetCharacterSpacing  and/or pdfSetWordSpacing to get the desired alignment.

Normally, I think this is done on the application side. A word processor has that capability built in.

This library is just designed to do the low level lifting of building a PDF.

Code: (Select All)
' Fonts:
'Courier             Symbol
'Courier-Bold        Times-Roman
'Courier-Oblique     Times-Bold
'Courier-BoldOblique Times-Italic
'Helvetica           Times-BoldItalic
'Helvetica-Bold      ZapfDingbats
'Helvetica-Oblique
Reply
#20
I'll have a play around with fonts and see what I can come up with.
It's a pity I have no idea how .bm and .bi files work as I've been trawling though the PDF 1.7 file and found a 'justify' command. I've just got no idea how to implement it. I've looked at your .bm and .bi files and found nothing that seems to connect to what's in the PDF docs Undecided
Oh look. A sig line :-)
Reply




Users browsing this thread: 45 Guest(s)