npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sk-pdf-make

v0.0.14

Published

pdfmake wrapper for Angular7

Downloads

56

Readme

SkPdfMake

pdfmake wrapper for Angular7

Installation

$ npm install sk-pdf-make

Import

import {SkPdfMakeModule} from 'sk-pdf-make';
@NgModule({
  imports: [
    SkPdfMakeModule,
  ]
})
export class AppModule { }

SkPdfMakeModule has SkPdfMakeService added to its providers, so we can use it to generate PDF files.

Examples

Creating PDF file with one empty page

export class AppComponent implements OnInit {

  // inject the service
  constructor(private pdfMakeService: SkPdfMakeService) { }

  ngOnInit() {
    // create document definition
    const dd: DocumentDefinition = {
      content: []
    };
    // create pdf file from specified definition and download it
    this.pdfMakeService.createPdf(dd)
      .subscribe(pdf => pdf.download());
  }

}

Document definition must always have content property.

Below is document definition with some other top-level properties and their default values:

{
  content: [],
  pageSize: PageSize.A4,
  pageOrientation: PageOrientation.PORTRAIT,
  compress: true,
  header: null,
  footer: null
}

Adding paragraphs to the file

const dd: DocumentDefinition = {
  content: [
    {
      text: 'This paragraph is bold',
      bold: true
    },
    {
      text: 'This paragraph is italics',
      italics: true
    },
    {
      text: 'This paragraph is blue',
      color: 'blue',
      fontSize: 16
    },
  ]
}

Paragraph can be array of texts, and each of its items can be styled individually

const dd: DocumentDefinition = {
  content: [
    {
      text: [
        {
          text: 'This ',
          color: 'red'
        },
        {
          text: 'paragraph ',
          color: 'blue'
        },
        {
          text: 'is ',
          color: 'indigo'
        },
        {
          text: 'colorful.',
          color: '#009f00'
        }
      ]
    }
  ]
};

Rendering tables

const dd: DocumentDefinition = {
  content: [
    {
      table: {
        body: [
          ['column 1', 'column 2', 'column 3'],
          ['value 1', 'value 2', 'value 3'],
          ['value 4', 'value 5', 'value 6'],
          ['value 7', 'value 8', 'value 9']
        ]
      }
    }
  ]
};

Customizing table header:

const dd: DocumentDefinition = {
  content: [
    {
      table: {
        body: [
          [
            {text: 'column 1', style: 'tableHeader'},
            {text: 'column 2', style: 'tableHeader'},
            {text: 'column 3', style: 'tableHeader'},
          ],
          ['value 1', 'value 2', 'value 3'],
          ['value 4', 'value 5', 'value 6'],
          ['value 7', 'value 8', 'value 9']
        ]
      }
    }
  ],
  styles: {
    tableHeader: {
      fillColor: '#bcbcbc',
      bold: true
    }
  }
};

Adding header and footer

const dd: DocumentDefinition = {
  content: [],
  header: {
    text: 'Page header goes here',
    style: 'headerStyle'
  },
  footer: (pageIndex, pageCount) => ({
    text: `${pageIndex}/${pageCount}`,
    alignment: Alignment.center
  }),
  styles: {
    headerStyle: {
      fontSize: 16,
      bold: true,
      margin: [0, 10],
      alignment: Alignment.center
    }
  }
}