6

The Drupal 6 project I'm working on involves a custom content type with a bunch of different elements. I'm needing to replicate an existing form -- see screenshot.

Ultimately, I need to take the data stored in the CCK fields attached to this content type, and rebuild them as a table as per the screenshot. It then needs to be savable as a PDF.

measurement sheet example

It seems like there are two ways of doing PDF content of the nature I'm wanting:

  • Views PDF -- cumbersome as heck to configure; requires manually positioning each field.
  • Print -- I can't figure out how to directly access the CCK field variables through its $print object; consequently, I can't rebuild this as a table.

How would one go about taking a lot of CCK fields, formatting them as a table, then making that PDF-able?

Thanks.

Edit: To clarify, I have each row of, say, the FAC table stored as a row in the content type, through a compound/multifield module called "Flexifield". Data isn't stored as per the table; it's stored as a label ("level"), a decimal number and a boolean (above or below grade?). Another boolean toggles between Imperial and Metric for the entire sheet. The columns are generated by converting the number stored to either Imperial or Metric, depending on which the stored measurement is set as. Consequently, I'll ultimately need a way to tweak and restructure the data using PHP. This is why I can't, for instance, just tell the fields to display as a table.

1

I've done exactly this using the Print module.

Basically, you can build a view to display all of the cck data that need, and embed that view into a new page template which you've pointed to using hook_theme from a custom module.

In my case, I created the template named property_report.tpl.php and dropped all of the views that I wanted to pdf into that page. To print a pdf of any content on your website using the Print module, you just build the url like so:

www.example.com/printpdf/nid

  • Do you think it would it be possible to build the content as a Views Bonus Pack Feed and then supply that to the Print module? Mind explaining the part where I would embed the view into a new page template, pointed to by hook_theme? – aendrew Jul 14 '11 at 1:48
  • This ended up being closest to what I did in the end. Instead of using a view at all, I just created a print template for the content type I was wanting PDFs of. Using the $print->node object, I was able to reconstruct the Excel file's structure in HTML and just output all the data as such. Not the most ideal solution (It's not an exact replica), but also easier to implement than some of the other ones. – aendrew Jul 25 '11 at 19:39
2
+50

You have the following options:

  1. If you count with a predefined and fixed layout with always the same lines/columns, go create a PDF form and populate it with the Fill PDF module.
  2. If the columns/lines are dynamically generated by your datas so I'll build an excel version of your datas with PHPExcel and use the save file as PDF. PHPExcel is quite simple to use and I think it's the easiest way to create tabular datas in PDF. Download it and have a look at the examples they're quite intuitives.
  • That's really helpful; I hadn't run across Fill PDF and didn't know you can interface it with PDF forms. I'll give that a shot tomorrow. – aendrew Jul 8 '11 at 6:12
  • I haven't tested it myself because I needed a more custom layout (hence the PHPExcel solution), but FillPDF need a litte configuration as you need to set up a server component in Java to achieve this, the author of the module also propose his own webservice but with a cost (there's a free version though). – tostinni Jul 8 '11 at 13:52
  • Interesting... Quick question about PHPExcel -- my client already has the measurement sheet listed above created as an Excel file. So really, all I'd need to do would be to import that and then fill it with CCK data. Know of any good tutorials for doing that kind of thing? – aendrew Jul 12 '11 at 21:16
  • PHPExcel have some very intuitive examples inside the package. Download it and have a look at examples like 30template.php (use of excel templates) and the basic ones 01simple-download-pdf.php (write excel and save in PDF). Also this one can help stackoverflow.com/questions/3895819/… – tostinni Jul 12 '11 at 23:14
  • Grah, that so almost worked; I've gotten PHPExcel to read in my template, but it totally borks the formatting and I save it as a PDF. :( – aendrew Jul 20 '11 at 5:10
2

Just a shot in the dark, but the Slickgrid module may be of help in this situation. Here is an excerpt about it from the module's project page:

... is an implementation of Michael Leibman's jquery slickgrid plugin, a lightening fast JavaScript grid/spreadsheet.

It defines a slickgrid view style, so all data can be output as an editable grid.

  • Mind explaining a bit better, please? I'm not needing a form for data-entry; I'm needing to print the data that's been stored in CCK fields reformatted into a table. – aendrew Jul 8 '11 at 6:08
1

Certainly looks like some PDF modules are available ... if only in-development.

As an alternative, just fyi, we've done similar display & PDF export of formatted data within a CMS (not Drupal ... yet), where we've split the problem, moving high volume PDF generation to a Tomcat-hosted document processing app.

We query & format data for online display from within the CMS, taking advantage of query-building and display tools (like CCK?) then export data in any available, well-defined XML format. Next, external XSLT transform of the data to XSL-FO format, and finally conversion/generation of PDF using Apache FOP (http://xmlgraphics.apache.org/fop/#intro) running on a Tomcat servlet container (If you already have Solr running on Tomcat, it's convenient ...).

We've done this for transformation of flexible online medical record presentation to strictly-formatted PDF for print and electronic delivery. The fine-grained control of the XML -> XSL-FO transformation, using Xalan, Xerces, etc. results in 'professional quality' output, and offloading to heavier-iron ensures we've never bogged down the CMS.

All depends on what your particular needs are.

  • Thanks for your answer -- that sounds like a pretty sophisticated way of creating this kind of document. Alas, Java is like the one language I haven't done any work in, ever. I'll give this a shot if I can't figure out anything else. – aendrew Jul 8 '11 at 6:14
  • Fwiw, in our setup, you're not fooling with Java much at all ... rather, it's XML config. – r_ofc Jul 8 '11 at 14:27
  • Interesting... The one thing I'd be somewhat worried about it translating all the complex fields I have to data readable by FOP. How do you get content from CCK to FOP? – aendrew Jul 8 '11 at 19:35
  • If (?) I understand your question ... content, not just layout template, is exported with the XML 'from' CCK-painted display.; the susbequent XSLT transform from 'whatever' XML to XSL-FO simply reorgs the wrapper. I know for D6 there was an export capability in module drupal.org/project/importexportapi. It's N/A for D7 -- and I haven't yet figured out how XML export's managed in D7. I'm guessing it may be directly embedded in CCK or core capabilities now -- simply don't know yet. – r_ofc Jul 8 '11 at 20:00
  • there is a module drupal.org/project/xml_export for d7 to export in xml which can be further transfered to FOP. – kiranking Oct 19 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.