Main Menu

PDF Class

Started by Richard Kelly, May 10, 2014, 07:49:15 AM

Previous topic - Next topic

Richard Kelly

I have been working on a PDF class for my applications. I thought commercial products a bit pricey when I don't need all the fancy bells and whistles to use PDF's as my reports delivery format.

I have support for text, multiline text boxes, lines, ellispes, rectangles with any combination of rounded corners and images with all the base line primitives for these objects and associated attributes - i.e. text centering, right/left/center alignment, underlining, rotation, scaling, etc. All the basic objects can be inserted into page header and footer objects that auto repeat on each page with automatic page numbering options.

Now I want to build more complex objects on top of the primitives. One of these I'm looking at I call a "Tableframe". Many reports I use are repeating, variable number of rows of detail all with the same number of base columns.

Tableframe attributes:

Height, Width, Background color, outlining options, # columns, column header height/background color/outlining options and an option to automatically repeat on each page.

Each column:

Height, Width, Text, Text and font attributes

Each row has a "bucket" associated with a particular column where you provide the text or image to draw with all the related attributes.

You define the tableframe once and pump in however many rows you want and everthing else is taken care of.

If you were using a tableframe type of object, what other options would you like to see?

Hopefully, in a few weeks, I will upload a FF project that demonstrates everything I can think of that the class can deliver.

See the attachment for a crude example of a few things. It has centered text, underlined text, a rectangle with 3 rounded corners, an ellispe that is a circle and an image that I've twisted and resized for fun. There is no compression yet - it will be one of the last things I add.

Rick

Haakon Birkeland

There is so much people could wish for and I suppose you might add and improve features to such a project until it becomes your day job. 8o)

I'm using QuickPDF, and have been doing so for years now. Thinking of what I use and appreciate the most, I guess it would come down to the function for drawing HTML/formatted text.
Haakon 8o)

Richard Kelly

Quote from: Haakon Birkeland on May 10, 2014, 11:57:40 AM
There is so much people could wish for and I suppose you might add and improve features to such a project until it becomes your day job. 8o)

I'm using QuickPDF, and have been doing so for years now. Thinking of what I use and appreciate the most, I guess it would come down to the function for drawing HTML/formatted text.

I did take a look at QuickPDF and, at $449, thought it a bit too much.

Rick

Richard Kelly

My definition of a multiline text box can give you an idea of the options involved.


TYPE MultiLineTextDescriptor
    Height              AS DOUBLE
    Width               AS DOUBLE
    TextAttributes      AS TextDescriptor
    VerticalAlignment   AS LONG
    VerticalPadding     AS DOUBLE
    HorizontalPadding   AS DOUBLE
    Spacing             AS DOUBLE
    OverflowNewPage     AS LONG
END TYPE

TYPE TextDescriptor
    FontID              AS ASCIIZ * 6
    FontSize            AS LONG
    FontColor           AS LONG
    Angle               AS DOUBLE
    Justify             AS LONG
    Underline           AS LONG
    NewLine             AS LONG
    LineDescriptor      AS LineDescriptor       'Used if text is underlined
END TYPE

TYPE LineDescriptor
    Color               AS LONG
    Width               AS DOUBLE
    Cap                 AS LONG
    Join                AS LONG
    Dash                AS LineDash
    Miter               AS DOUBLE
END TYPE

TYPE LineDash
    Array1              AS ASCIIZ * 15
    Phase               AS DOUBLE
END TYPE
                                                         

Rick

Haakon Birkeland

Debenu have jacked up the price lately so I would probably not have been an initial customer now but I've on board for such a long time and use some "heavier" functions of the library, like CMYK images with masks and vector graphics.

They do by the way offer a free light version.

It will be interesting to follow your development/progress.
Haakon 8o)

Richard Kelly

#5
Quote from: Haakon Birkeland on May 11, 2014, 12:51:08 AM
It will be interesting to follow your development/progress.

Thank you for your encouragement.

I think multiline text boxes are looking OK at this point - I need them since column headers in the tableframe object are multiline text boxes.

See attached for an example. I don't think my spacing algorithm is perfect yet although it's close. I'm deep into font ascent/descent considerations which is new to me so I'm a bit slow to understand it all. Other things that can happen with the multiline text box is when the content doesn't fit and then I put as much as I can and return whatever didn't fit to the caller. Additionally, if you pass me a word that itself is wider than the bounding box width, I will clip it to fit.

In the example attached, all the lines are left justified although they could be center or right justified as well.

Rick

Richard Kelly

#6
Been a bit busy with too many competing activities. I have made a decent amount of progress on my PDF class. The attachment gives you a decent look at most of the important stuff. I'm not likely to get the time needed anytime soon to do things font embedding or add shading patterns. Page streams are automatically compressed if zlib is found and bookmark outlines are supported.

Rick

Petrus Vorster

Wow, you made some serious progress.
I would like to see the entire code once this is finished!
-Regards
Peter

Richard Kelly

#8
Quote from: Petrus Vorster on May 27, 2014, 06:30:18 PM
Wow, you made some serious progress.
I would like to see the entire code once this is finished!

The source code isn't likely to change much soon so I've just attached it for your viewing pleasure. I will put together a FF demo with the code that generates the example PDF. I did finish the demo PDF and I updated the attachment in the previous message to add a sample report that pulls a lot of elements together.

If you have zlib, page streams will be compressed, otherwise there is no compression.

Put the two include files whereever FF and/or PB can find them and include once the cPDF.inc which will pull in the fonts include.

The PDF coordinate system puts 0,0 at the bottom left corner and this class moves it to the upper left corner and translates the x,y points you provide to the PDF standard.

The general calling sequence goes something like this (explore the code for lots more)...


LOCAL obj           AS iPDF


obj = CLASS "cPDF"
obj.PDFCreateDocument()

...Load up supported Fonts

obj.PDFFont()

...create a combination of objects

Text

obj.PDFWriteText

Lines

obj.PDFStartLine()
obj.PDFMoveTo()
obj.PDFDrawLine()
obj.RestoreGraphicsState()

Images

obj.AddImage()
obj.PDFWriteImage()

Shapes

obj.PDFRegularPolygon()
obj.PDFEllispe()
obj.PDFRectangle()

end/start pages

obj.PDFEndPage()
obj.PDFStartPage()

...end document

obj.PDFEndDocument

obj = NOTHING


Maybe somebody can engineer an improvement or add extra features. I wrote it from the perspective of generating general business reports in my applications so my focus was on the feature set that advanced that goal.

I have run so many tests I'm dizzy and think things are relatively solid and we all know how software is when the real world gets their hands on it...  ::)

Rick

p.s. Left one character out of the main cPDF.inc file and patched that up.

Richard Kelly

#9
Here is a FF 3.70 project that generates the PDFDemo.pdf file.

Rick

David Warner

Hi Richard,

That is very cool, thanks for sharing.


Jean-pierre Leroy

Hi Richard,

Thanks for this PDF Library.

How it works ? are there any dependencies ?

Currently I'm using libHaru to generate PDF documents.

Regards,
Jean-Pierre

Richard Kelly

Quote from: Jean-pierre Leroy on May 28, 2014, 03:03:29 PM
Hi Richard,

Thanks for this PDF Library.

How it works ? are there any dependencies ?

Currently I'm using libHaru to generate PDF documents.

Regards,
Jean-Pierre

Jose Includes, zlib is optional, otherwise straight PB code

That being said, it's a subset of the PDF 1.7 spec. Although I know how to add other features, it wasn't necessary for my application reporting requirements. My biggest concern is the lack of font embedding. I needed some font information for string alignments and underlining and choose a way to get that into the class and then carefully chose the fonts included after a lot of Mr. Google time. I do know the win32 API's involved and at some point when time is available, I will seriously look at the tricky art of font embedding.

The font information is a blend of AFM 4.1 and what I able to study in MS Word created PDF's. The characters from 32 to 126 were pulled from those MS Word created PDF's as well as most of the font characteristics.

Rick

Richard Kelly

I "forgot" to remove some of my testing code always forced the first page to be letter 8.5x11 in portrait mode. Attachments updated.

Rick

Rolf Brandt

Very impressive piece of work, Rick.

Rolf
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)