From J Wiki
Jump to: navigation, search

The pdfdraw addon has utilities for drawing to a PDF file or a Publish JPF file.

Much of the code is taken from Plot, and the idea is to support custom report graphics that could not be drawn using Plot.

Unlike Plot, the graphics drawing is at a low level, so some effort is required to develop a pdfdraw graphic. For example, the developer must take care of layout calculations and drawing elements like axes. The main benefit comes when running regular reports that use the same graphic types.

For example, the following shows data in a barchart, with corresponding values below in a grid:



Demo scripts in ~addons/graphics/pdfdraw are:

  • demo1.ijs example of the main drawing functions
  • demo2.ijs generates the above graphic
  • demo3.ijs cover function for a barchart example. Data is generated at random, so each run shows a different graphic.

There is a Publish demo using JPF files generated by pdfdraw. First install the format/publish and demos/publish addons, then:

require 'format/publish'
publish '~addons/demos/publish/master.txt'

Drawing Functions

The addon and demos source is in the Public repository at pdfdraw/source. The source is commented as documentation for the addon.

Code Example

load 'graphics/pdfdraw'

setsize 250 100
pdffill 255 239 223
pdfline 1;255 0 0;10 90 240 90
pdfpoly 1;64 64 64;64 255 192;50 30,30 60,40 80,80 75
pdfrect 0 128 255;150 50 50 20
txt=. 'In the very middle of the court was a table'
pdftext txt;0 0 12 0 0;0;Black;10 20

(buildpdf buf) fwrite f=. jpath '~temp/pdfdraw.pdf'
viewpdf_j_ f

This generates: