CFdocument margin not working


Currently I am busy with converting HTML to PDF using the cfdocument function. A lot of stuff works very well and I am pleased with that. But I have some troubles with the margin setting which is important to make the layout more to our clients likings.

It seems that cfdocument isn’t listening to the marginleft, margintop etc. setting. I also tried downgrading the pdf.extension to lower versions, but still not working. It’s weird because in the thread posted below the user said after downgrading to “” that everything was working again. If I do that then I get a corrupted PDF document :frowning: so now I upgraded to “” but then the margins don’t work (same as for

So would be really great if this can be fixed in a newer version. I am hesitant to upgrade/downgrade lucee, because we had a lot of trouble with that in the past (extensions began to fail, websocket etc.)

This thread is related to

Don’t forget to tell us about your stack!

OS: Windows Server 2012 R2 (6.3) 64bit
Java Version: 11.0.6 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.31
Lucee Version: Lucee

Can you please share the test code to replicate your problem?

are you using cfdocumentsection? if yes, Maybe because of this ticket the cfdocument margins are get ignored in pdf LDEV-3935 - cfdocumentsection ignores cfdocument margins attributes

1 Like

Let me share also a more generic point. You said that when you downgraded the extension, you “get a corrupted PDF document”. As you may know, that can happen in various situations regarding browser rendering of such mime types (if that’s where you’re seeing the corruption), when you make some change about serving it on the server side.

A tip is to try the request (after a server-side change) in another browser entirely, or just a private/incognito window. Of course, you could also clear cache, or turn on your browser dev tools and tell it to disable cache for the request–or even more simply, just add a random query string to the url.

Let us know if that helps. I realize that if it does, the next question would be how to deal with users who may have the problem also. But let’s take it one step at a time. :slight_smile:


thanks for the quick reply, I have added a simplified version of the code down below, but yes we use documentsection, so I can also use margin in the documentsection? I will try some things tomorrow and come back to you, thanks for the suggestion!

<cfdocument marginleft="0" margintop="0" marginright="0" marginbottom="0" filename="#download_file_name#" format="pdf" pagetype="#used_page_size#" orientation="#pdf_orientation#" scale="100" localurl="true">
<cfdocumentitem type="header">
<cfdocumentitem type="footer">

Hey, thanks for the suggestion but that’s not it I think. Also the PDF is corrupted in adobe acrobat and I have had more troubles like this. It’s because of mutliple PDF extensions and jar files that don’t work together or try to load the same functions. Btw when I upgraded the PDF extension to “” I saw I had problems generating a PDF from a Docx (other jar file). So only the “” version works well with the other plugins.

I find it hard to understand how I can arrange Lucee that everything loads well, that’s more my fault, but we do have a broad spectrum of functionalities in our project so that’s part of the problem. Also tried to use the javaloader but had difficulties using that. But if these troubles continue I could try to setup a clean small project and only test the jar files in different Lucee versions etc.

Yes, you can use the margin attribute for each cfdocumentsection tag as your wish.

please make try the latest PDF version
some others and a cfdocumentsection margin-related bug were solved in the latest PDF version.



Yes it was because of the documentsection, I placed the header and footer inside here and gave a margin as well, now the whitespace become much less. Thanks again for your help!

1 Like