Printing a dotCMS form

32 views
Skip to first unread message

Mark Orciuch

unread,
Mar 25, 2021, 1:42:03 PM3/25/21
to dotCMS User Group
Hello,

I would like to utilize dotCMS form to collect data (to avoid creating custom pages and writing JS code to handle everything; many forms are needed). One challenge that I am running into is printing. Using the browser print function cuts off portion of the form. Is there any creative way to print content collected via dotCMS form?  I know that I could probably create form content detail page and format it anyway I want (wait, there is no Detail Page property for Forms). 

But how could I open the content and have a Print Preview workflow step that would send the user to the detail page.

If I could merge the content field values with existing PDF document and print it, that would be a bonus.

Many thanks in advance for any tips or techniques that you could share.

Mark Pitely

unread,
Mar 25, 2021, 1:51:18 PM3/25/21
to dot...@googlegroups.com
I don't think there is any reason at all you couldn't make a PDF file served that parses velocity; I've done it with csvs and, well, jpegs (don't ask).
I'm pretty sure I did this at least once before, but I can't find the code easily. I will look.
It would be exactly the same way you mix/serve html/velocity. Just need to get the headers and formats right. (blank template):
#if (!$EDIT_MODE)
$response.setContentType("text/csv")
$response.addHeader("Content-Disposition", "attachment;filename=myfilename.csv")
$response.addHeader("Access-Control-Allow-Origin", "*")
#set ($puller=$dotcontent.pull("+structureName:building",0,"modDate desc"))
#foreach($con in $puller)
"$con.title", "$con.longTitle","$con.buildingCode"
#end
#end

But having a nice print.css should obviate this method! This isn't really a code issue.

M

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/fd2f7f7c-d75e-458a-ba31-688b05cb6346n%40googlegroups.com.

Mark Orciuch

unread,
Mar 25, 2021, 2:49:36 PM3/25/21
to dotCMS User Group
Hi Mark,

Thanks for your reply! Not sure how to make PDF file served that parses velocity. I would have to be able to read an existing AcroForm PDF and then merge it with content field values, all this from Velocity. Wouldn't this require using a plugin? 

Also, how could I integrate this in the content editor? For example, the user would search and open the content and then have a workflow link Print like shown in the attached screenshot.
Image 6.png

Mark Pitely

unread,
Mar 25, 2021, 3:03:54 PM3/25/21
to dot...@googlegroups.com
You make an advanced template that just has a simple container that just parses velocity content (or webpagecontent, it doesn't actually matter)
You then make an htmlpage /myfolder/mypage.pdf that uses that template and runs the code I have above, instead of <html>></html>
(well, that example code is for CSV, but you can look up the correct header).
dotCMS can serve *arbitrary* files in this manner. To the browser there is absolutely nothing but headers and text. PDF/HTML/CSV, etc.

The line about EDIT_MODE is necessary, because otherwise you won't be able to edit it in the browser.

Mark Pitely

Mark Pitely

unread,
Mar 25, 2021, 3:09:15 PM3/25/21
to dot...@googlegroups.com
Here, I made one on the dotCMS site (well, it will be there for 24 hours)

M

Stefan Schinkel

unread,
Mar 25, 2021, 3:17:42 PM3/25/21
to dot...@googlegroups.com
I would stay far far away from Advanced Templates to be frankly honest. It kills the NoCode editor experience in a heartbeat. There are other options. Checking in ternally and will share here...



--
Spring '21 Updates

Stefan Schinkel


200 Portland Street, Suite 3.158
Boston MA 02114

Mark Pitely

unread,
Mar 25, 2021, 3:22:44 PM3/25/21
to dot...@googlegroups.com
An 'advanced template' that just parses a vtl file isn't really 'advanced'.I guess I meant don't use a themed template.
I just picked 'blank template' from the site, and then used a piece of Rich Text to make the code.
There are many ways to make this work, my example was meant to demonstrate a solution rather than show best practices.
I wouldn't use Rich Text for my content, either, in a real example, but it works.

M

Stefan Schinkel

unread,
Mar 25, 2021, 3:39:32 PM3/25/21
to dot...@googlegroups.com
Mark, I did actually meant to use a Theme-based template and do the PDF conversion via a JS

Mark Orciuch

unread,
Mar 25, 2021, 5:05:44 PM3/25/21
to dotCMS User Group
Hi Stefan,

Thanks, I am looking forward to see any alternatives.

Mark Orciuch

unread,
Mar 25, 2021, 5:09:59 PM3/25/21
to dotCMS User Group
Mark,

It finally dawned on me what you're proposing. I put together quick test page with this code:

#if (!$EDIT_MODE)
$response.setContentType("application/pdf")
$response.addHeader("Content-Disposition", "attachment;filename=test.pdf")
$response.addHeader("Access-Control-Allow-Origin", "*")
#foreach($con in $dotcontent.pull("+contentType:calendarEvent",10,"modDate desc"))
$con.title
#end
#end

However, as expected, the generated file is not a valid PDF file. I would Velocity tool that would generate valid PDF file. Or I am still missing something.

Mark Orciuch

unread,
Mar 25, 2021, 5:10:53 PM3/25/21
to dotCMS User Group
Hi Stefan,

Thanks! Is there any example on how to do this that you can point me to?

Reply all
Reply to author
Forward
0 new messages