New daily: WordCram to PDF

WordCram now outputs to PDF. It’ll be in the 0.5 release, but you can grab the new daily build right now (zip or tar) and try it out. The only new code you’ll need is normal Processing PDF stuff, all the WordCram code stays the same. Just import processing.pdf.*, and use size(width, height, PDF, "path/to/output.pdf").

Here’s an example, a PDF word cloud from the Wikipedia page on PDF. Here’s the code to produce it:

import processing.pdf.*;
import wordcram.*;

void setup() {
  size(700, 700, PDF, "wordcram.pdf");
  
  background(255);
  
  new WordCram(this)
    .fromWebPage("http://en.wikipedia.org/wiki/Portable_Document_Format")
    .withColors(#000000, #777777, #ff0000)
    .withFonts("LiberationSans")
    .sizedByWeight(1, 200)
    .withWordPadding(1)
    .angledAt(0)
    .withPlacer(new WordPlacer() {
      public PVector place(Word w, int r, int c, int ww, int wh, int fw, int fh) {
        float xScatter = (1-w.weight);
        float x = map(random(-xScatter, xScatter), -1, 1, 30, fw-ww-30);
        float y = (1-pow(w.weight, 0.25)) * (fh - wh) + 30;
        return new PVector(x, y);
      }
    })
    .drawAll();
}

I’m pretty excited about this. PDF output was one of the first features asked for, and it’s been a goal of mine to finish it. But more importantly, we can now print some really nice, high-res word clouds!

Advertisements
This entry was posted in examples, improvements. Bookmark the permalink.

10 Responses to New daily: WordCram to PDF

  1. Bastian Kennel says:

    I am pretty new to WordCram and already excited.
    One thing I was wondering about: Isn’t WordCram rendering on a “normal” Java2D Graphics?
    If so, we should be easily able to substitute that by Batiks SVGGraphics2D implementation which renders directly to SVG.

  2. Hello Bastian,

    That’s an interesting idea. I know Batiks only from poking around the Geomerative source (if I remember right, it uses Batiks to turn .ttfs into paths), but I’ll take a look. If I can find a way to make it fit with the Processing stuff, I’m all for it.

  3. Sher says:

    Hi, thanks for this, it’s a superb library and very thorough. I have been trying to get the record pdf function to work, I can get it to work in the way described above however, the beginRecord() and endRecord() don’t seem to capture the output. Any advice on this would be much appreciated, thanks!

  4. Sher, you shouldn’t need beginRecord() and endRecord(). Does the above code work for you? Does the PDF example in the download run for you? (You can find it via File > Examples…, then looking under Contributed Libraries > WordCram > OtherExamples > renderToPdf.)

  5. Sher says:

    Thanks for the quick reply. I can get it to output a pdf in this way, yes. I just wanted to output more than one! If I save a png during the loop then I can reloop and save different versions, but I can’t seem to do this with pdfs if that makes sense? Thanks again.

  6. Oh! Ok, that makes sense. Though I’m not sure whether Processing supports the draw-loop for PDF output…

  7. Holger says:

    Hi, great tool! How can I preserve the ability to mark/select text in the PDF?

  8. Thanks! Unfortunately, with WordCram’s design, I don’t think that’s feasible: WordCram renders the words to the PDF as shapes, not as text, so the PDF renderer won’t see the words as text that can be selected.

  9. Pingback: WordCram 0.6.0 released | WordCram.org

  10. The coding of this website is really help them who want to know new information. Mentioned that is new ways are also exist http://pdfburger.com who want to convert pdf to ms word. it is really nice and beautiful concept. and it is completely free to use.

Comments are closed.