mdiin / pdf-stamper Goto Github PK
View Code? Open in Web Editor NEWTemplating for PDF files.
License: Eclipse Public License 1.0
Templating for PDF files.
License: Eclipse Public License 1.0
The idea is to add an option to the :aspect
key for image templates that allows images to be scaled 1:1, but where only a piece of the image is shown (i.e. it is cut out). It makes sense to cut from the center of the image.
There is a bug here, when a paragraph is exactly as long as the space given, the following paragraph will be marked as :broken
.
See the example in test/pdf_stamper/manual/overflow_bullets3.clj
On the third page of the result, the top line should contain a bullet.
This could as an example be that even pages are rotated 180 degrees.
Maybe this is not so much a template thing as a page specification thing. If page specifications can say what should happen when they are placed on an even or odd page, things like the following would be possible:
Assuming an implementation where it is a part of the page data specification, these are some interesting things to ask oneself.
A: Simply overflow and drop the knowledge of even/odd special behaviour?
Won't work if it is required that all even pages throughout the document are flipped horizontally.
A: Pass on all even/odd special behaviour?
Can result in the overflow inheriting the "print only on even pages" property, even though it should print on odd pages as well.
A: Only pass on some parts of the even/odd special behaviour?
Requires an up-front specification of which pieces of even/odd behaviour to pass on to the overflow pages.
To allow template writers a little more freedom on the parts they don't care about, we should consider adding default values to all template attributes.
Right now only strings and input streams are handled correctly. Loading a resource from a jar (using clojure.java.io/resource
) yields a URL instance, from which users have to construct an input stream (and remember to close it once the font has been embedded).
To make it easier to use and prevent potential memory leaks in client code, it should be possible to hand a URL instance to pdf-stamper.context/add-font
and have pdf-stamper.context/embed-font
open and close the input stream.
The idea is to enable a ClojureScript implementation from the same sources.
See the bullet tests for examples. Most of the lines overflow their boundaries.
To prevent e.g. a heading from being the last paragraph on a page, it must be possible to specify that it should be put on the same page as the paragraph following it.
To remove potential combinatorial explosion of templates. Use something like this snippet:
(defn- make-templates
"Naming scheme is a keyword with \"holes\" defined by $hole-name$. Example
naming scheme:
:rhubarb$part$
Values inbetween $'s are matched to the :name of individual parts and replaced
as needed. Example with the above naming scheme:
parts = [base-all
{:pdf-stamper/name "part"
:pdf-stamper/optional? true
:pdf-stamper/variants [{:value "flower" :template-part rhubarb-flower}
{:value "roots" :template-part rhubarb-roots}]}]
would yield templates with the names:
[:rhubarbflower :rhubarbroots]
And the appropriate template parts merged together in the order they are
specified in the parts vector."
[naming-scheme parts]
(let [naming-scheme-replacement-map (into {} (map (comp vec reverse)
(re-seq #"\$([^\$]+)\$" naming-scheme)))]
(loop [parts parts
result []]
...)))
Right now, all true type fonts in the context are embedded at the beginning of creating the PDF document. To reduce file size of generated documents it would be a good idea to only embed a font once it is actually requested by a template.
To allow things like multi-column layouts.
i.e. bottom left is origin of PDF, and writing text moves the cursor down. All coordinates are to the bottom left corner of the element.
Pdfbox does not support Unicode in the version used right now. ANSI does have a bullet character, as described in http://www.alanwood.net/demos/ansi.html, with number 149.
We are building a hierarchy of templates, where one template is the base for the rest, and several modifier-templates exist. The modifiers mostly just increment an :x
or :y
value by a fixed amount; necessary because pages can contain different elements that might push some things around.
The template hierarchy is merged together to form the final templates.
In the above use case it would be very useful to specify on e.g. the :x
and :y
values a function to call instead of the regular number. The semantics of specifying that function would be something like this:
:x
:x
In case there is no previous value of :x
, there are two possibilities:
To improve the layouting of multi-line text fields, we need some kind of widow and orphan protection. I propose that it is a part of the template structure.
When a page specifies a template that is not in the context, what should we do? As I see it there are two options:
When adding a template description to the context it should be validated, and if invalid tell the user exactly what is wrong with it.
Would be nice to have coimpile-time if possible, but that should be optional, since clients might want to load templates dynamically or from resources not available at compile time.
There seems to be a bug with the line height, at least on non-parsed text fields.
First page is fine, the following pages contain lists without bullets and with ever-increasing indentation.
To combat boilerplate in the templates it might be an option to add template inheritance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.