Giter Club home page Giter Club logo

Comments (3)

Aymkdn avatar Aymkdn commented on July 25, 2024

Several things here:

  1. <s>, as shown in the documentation, is not a supported tag; I've just added support to <s> in the new release;
  2. "2nd sentence is on line 2 instead of line 3": no, it's not.... if you look at the playground, you'll see it appears on the 3rd line, so my guess is that something is wrong with your code;
  3. "Lists aren't displayed at all": lists are correctly displayed in the playground, so I think something is wrong with your code.

That says, it wasn't possible to change the default margin left for list item 1.2 because I've just discovered that the default style will be stronger than a style class... In the new release, I've introduced an option parameter to the function in order to overwrite the default styles.

For your specific example, the full code will look like that:

// here there is your HTML code
var html = htmlToPdfMake(`<p>Here I am.</p>
<p><br></p>
<p>I'm another sentence two lines down. <s>Some strike through.</s></p>
<p><br></p>
<ul>
    <li>list item 1</li>
    <li class="ql-indent-1">list item 1.2</li>
     <li>list item 2</li>
</ul>
<p><br></p>
<p><br></p>`, {
  defaultStyles:{
    li:'' // remove all the default styles for LI (including the margin)
  }
});

var docDefinition = {
  content: [
    html
  ],
  // define some style classes to provide the margins for your LI
  styles:{
    'html-li':{ // here is the default margin for all LI
      marginLeft:5
    },
    'ql-indent-1':{ // here is the margin to use when we have 'ql-indent-1'
      marginLeft: 15
    }
  }
};

// and finally you can use pdfMake to create the PDF
pdfMake.createPdf(docDefinition);

The above code will return pretty much the below PDFMake code that you can directly copy/paste in the PDFMake Playground:

var dd = {
  content: [{
      text: 'Here I am.',
      style: ['html-p'],
      margin: [0, 5, 0, 10]
    },
    '\n',
    {
      text: [{
          text: 'I\'m another sentence two lines down. ',
          style: ['html-p']
        },
        {
          text: 'Some strike through.',
          style: ['html-s'],
          decoration: 'lineThrough'
        }
      ],
      margin: [0, 5, 0, 10],
      style: ['html-p']
    },
    '\n',
    {
      ul: [{
          text: 'list item 1',
          style: ['html-li']
        },
        {
          text: 'list item 1.2',
          style: ['ql-indent-1', 'html-li']
        },
        {
          text: 'list item 2',
          style: ['html-li']
        }
      ],
      style: ['html-ul'],
      marginBottom: 5
    },
    '\n',
    '\n'
  ],
  styles: {
    'html-li':{ // here is the default margin for all LI
      marginLeft:5
    },
    'ql-indent-1':{ // here is the margin to use when we have 'ql-indent-1'
      marginLeft: 15
    }
  }
}

Here how it looks like:
Capture

Please, not the new version is 1.1.0, so a simple npm update won't update it.
I have updated the documentation too.

from html-to-pdfmake.

SunnysideAaron avatar SunnysideAaron commented on July 25, 2024

Thank you for the thorough response. I'll look into this on my end today

from html-to-pdfmake.

SunnysideAaron avatar SunnysideAaron commented on July 25, 2024

Thank you again. It turns out that it was with our code. We had wrapped our text in another text array, which was fine for text elements but not ul elements. Apparently ul elements can't be part of a text element. I've started work on a solution for that.

from html-to-pdfmake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.