PDF margins not working

2 Answers 44 Views
Drawing API
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Jay asked on 30 Jan 2024, 04:20 PM

I'm trying to set margins when exporting to PDF using the Drawing API and can't get it to work. Here is a dojo. When you click the button to get the PDF, there is no margin around the chart. I'm assuming I'm doing something wrong, but not quite sure what.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 09 Feb 2024, 12:57 PM

Hi Jay,

Thank you for coming back to me.

I investigated further and you are right. Margin is applicable even if paperSize is "auto". The drawDOM syntax shall be a bit different:

          kendo.drawing.drawDOM($("#maindiv"))
            .then(function(root) {
            // Chaining the promise via then
            return kendo.drawing.exportPDF(root, {
              //paperSize: "A4",
              margin: 100,
              //landscape: true
            });
          })
            .done(function(data) {
            // Here 'data' is the Base64-encoded PDF file
            kendo.saveAs({
              dataURI: data,
              fileName: "calendar.pdf"
            });
          });

Updated Dojo: https://dojo.telerik.com/UqEGAVIg

Please let me know if you have any questions.

Regards,

Nikolay

Jay
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 09 Feb 2024, 09:00 PM

Thanks, Nikolay! That works great!
0
Nikolay
Telerik team
answered on 02 Feb 2024, 11:18 AM

Hi Jay,

To have the margins reflected in the PDF you have to set a paperSize:

           kendo.drawing.drawDOM("#maindiv", {
            paperSize: "A4",
            margin: { left: "2cm", top: "2cm", right: "2cm", bottom: "2cm" },
            landscape: true

Dojo demo: https://dojo.telerik.com/eCIgalUB

Regards,
Nikolay
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 06 Feb 2024, 05:44 PM

Hi Nikolay. The documentation for paperSize says when paperSize is "auto", it means the paper size will be just enough to fit the drawing. And then the documentation for margin says when paperSize is "auto", the dimensions are adjusted to include the margin. Taken together, it seems like margin is supported for paperSize "auto". 

Since you're saying it isn't, perhaps the documentation could make it more explicit that margin does not apply when paperSize is "auto".

Tags
Drawing API
Asked by
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Nikolay
Telerik team
Share this question
or