Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize margins is not working #2717

Open
jhojanpeinadod opened this issue Apr 23, 2024 · 0 comments
Open

Customize margins is not working #2717

jhojanpeinadod opened this issue Apr 23, 2024 · 0 comments

Comments

@jhojanpeinadod
Copy link

I have an issue with this code. When I set margins like 10 - 20 - 30 - 40 for example, it takes the top margin on the first page, but on subsequent pages, it doesn't take the top margin into account. The bottom margin is never reflected, it always remains the same regardless of the footer.

My goal is to allow the user to define margins for the entire document.

Could you help me with this?

var docDefinition: any = {
info:{
title: Estudio ${this.patient.patient_study_accesion_number} - ${this.patient.patient_name},
},
header: [],

  content:[
    {
      stack: [
        htmlToPdfmake(comments,{
        defaultStyles:{
          b: {bold:true},
          strong: {bold:true},
          u: {decoration:'underline'},
          s: {decoration: 'lineThrough'},
          em: {italics:true},
          i: {italics:true},
          h1: {fontSize:24, bold:true, margin: [0, 0, 0, 0]},
          h2: {fontSize:22, bold:true, margin:0},
          h3: {fontSize:20, bold:true, margin:0},
          h4: {fontSize:18, bold:true, margin:0},
          h5: {fontSize:16, bold:true, margin:0},
          h6: {fontSize:14, bold:true, margin:0},
          a: {color:'blue', decoration:'underline'},
          strike: {decoration: 'lineThrough'},
          p: {margin:[0, 0, 0, 0]},
          ul: {margin:0},
          li: {margin:0},
          table: {margin:0},
          th: {bold:true, fillColor:'#EEEEEE'},
        },
      }),
    ],
    margin: [this.margin_left, this.margin_top, this.margin_right, 50]
    }

    
  ],
  pageBreakBefore: function(currentNode: any, followingNodesOnPage:any, nodesOnNextPage:any, previousNodesOnPage:any) {
    return currentNode.headlineLevel === 1 && followingNodesOnPage.length === 0;
 }
};

if(this.hasHeader){
  docDefinition.pageMargins = [20, 90, 20, 30 ];
  docDefinition.header.push(
    {
      margin:[20,20,20,0],
      table:{
        widths: ['*'],
        body:[
          [
            {
              columns:[
                {
                  alignment: 'left',
                  table: {
                      widths: ["55%", "75%", "20%", "10%" ],
                      padding: 0,
                      body: [
                        [
                          { text: `Estudio`, bold: true, fontSize: 10, border: WITHOUT_BORDER, margin:[-10,0,0,0] },
                          { text: this.patient.patient_study_name, bold: false, fontSize: 10, border: WITHOUT_BORDER },
                        ],
                        [
                          { text: `Paciente`, bold: true, fontSize: 10, border: WITHOUT_BORDER, margin:[-10,0,0,0] },
                          { text: this.patient.patient_name, bold: false, fontSize: 10, border: WITHOUT_BORDER },
                        ],
                        [
                          { text: `Fecha del estudio`, bold: true, fontSize: 10, border: WITHOUT_BORDER, margin:[-10,0,0,0] },
                          { text: this.formatDate(this.patient.patient_study_date_create), bold: false, fontSize: 10, border: WITHOUT_BORDER },
                        ],
                      ]
                    }
                },
                {
                  alignment: 'right',
                  image: imageDataUrl,
                },
              ],
              border: BOTTOM_BORDER
            }
          ]
        ],
      },
    },
  ) 
}

if(this.hasFooter){
  docDefinition.footer = function(currentPage: any, pageCount: any) {
    return { text: `Página ${currentPage.toString()} de ${pageCount.toString()}`, alignment: 'center', fontSize: 8, margin:[0,10,0,0] };
  }
}
@jhojanpeinadod jhojanpeinadod changed the title Margins not working Customize margins is not working Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant