Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ch99q committed Dec 4, 2019
0 parents commit 13a2873
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# dependencies
node_modules

# logs
npm-debug.log

# yarn & npm
yarn.lock
package-lock.json

# Nuxt build
.nuxt

# Nuxt generate
dist
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.nuxt/
coverage/
dist/
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Nuxt PDF

[![npm](https://img.shields.io/npm/dt/nuxt-pdfsvg?style=flat-square)](https://npmjs.com/package/nuxt-pdf)
[![npm (scoped with tag)](https://img.shields.io/npm/v/nuxt-pdf/latest.svg?style=flat-square)](https://npmjs.com/package/nuxt-pdf)
[![License](https://img.shields.io/npm/l/nuxt-pdf?style=flat-square)](http://standardjs.com)

> Generate PDF files directly from your content on your website, can be used for offline downloadable documentation pages.
## Features

- Create PDF from Vue template
- Automatic PDF Generation
- Customizable Metadata
- Supports (A1, A2, A3, A4, A5)
- Support dynamic routes (Nuxt Generate)
- For **NUXT 2.x** and higher

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Development](#development)
- [License](#license)

## Installation

```shell
npm install nuxt-pdf
```

or

```shell
yarn add nuxt-pdf
```

## Usage

- Add `nuxt-pdf` to the `modules` section of your `nuxt.config.js` file:

```js
modules: ["nuxt-pdf"];
```

- Add a custom configuration with the `pdf` property.

You can see the available options in the example [configuration](#configuration)

```js
// nuxt.config.js

{
modules: [
'nuxt-pdf'
],
pdf: {
// custom configuration
}
}
```

## Configuration

```javascript
// nuxt.config.js

{
pdf: {
/*
* Output folder for generated pdf.
*/
dir: "dist",

/*
* Function options for page.pdf([options])
* Read more: https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagepdfoptions
*/
pdf: {
// Change the format of the pdfs.
format: "A4",

printBackground: true // Include background in pdf.
},

/*
* PDF Meta configuration. (inspired by vue-meta)
*/
meta: {
title: "Default PDF title",
titleTemplate: "Example ─ %s",

author: "Christian Hansen",
subject: "Example",

producer: "Example Inc.",

// Control the date the file is created.
creationDate: new Date(),

keywords: ["pdf", "nuxt"]
},

/*
* PDF generation routes. (expanding nuxt.generate)
*/
routes: [
{
// PDF Filename
filename: "super-awesome-pdf.pdf",

// Output directory for pdf.
// Combined with 'dir' value in options. (default 'dist')
directory: "downloads/",

// Route to content that should be converted into pdf.
route: "/",

// Override global meta with individual meta for each pdf.
meta: {
title: "Super Awesome PDF"
}
}
]
}
}
```

## Development

```bash
$ git clone https://github.com/ch99q/nuxt-pdf.git

$ cd nuxt-pdf

$ yarn
```

## License

[MIT License](./LICENSE)
12 changes: 12 additions & 0 deletions lib/css/a1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page {
format: A1;
size: 594mm 841mm;
margin: 0mm 0mm;
}

@media print {
.page {
width: 594mm !important;
height: 840.75mm !important;
}
}
12 changes: 12 additions & 0 deletions lib/css/a2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page {
format: A2;
size: 420mm 594mm;
margin: 0mm 0mm;
}

@media print {
.page {
width: 420mm !important;
height: 594mm !important;
}
}
12 changes: 12 additions & 0 deletions lib/css/a3.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page {
format: A3;
size: 297mm 420mm;
margin: 0mm 0mm;
}

@media print {
.page {
width: 297mm !important;
height: 420mm !important;
}
}
12 changes: 12 additions & 0 deletions lib/css/a4.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page {
format: A4;
size: 210mm 297mm;
margin: 0mm 0mm;
}

@media print {
.page {
width: 210mm !important;
height: 296.75mm !important;
}
}
12 changes: 12 additions & 0 deletions lib/css/a5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page {
format: A5;
size: 148mm 210mm;
margin: 0mm 0mm;
}

@media print {
.page {
width: 148mm !important;
height: 209.75mm !important;
}
}
25 changes: 25 additions & 0 deletions lib/css/pdf.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@media print {
html,
body {
margin: 0 !important;
padding: 0 !important;
visibility: hidden;
}

.page {
position: relative;
overflow: hidden;

visibility: visible;

padding: 0 !important;
margin: 0 !important;

page-break-after: auto;
page-break-inside: avoid !important;

border: none !important;
border-radius: 0 !important;
box-shadow: none !important;
}
}
15 changes: 15 additions & 0 deletions lib/module.defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
dir: 'dist',
pdf: {
format: 'A4'
},
meta: {
title: '',
titleTemplate: '%s',
subject: '',
author: '',
producer: '',
keywords: []
},
routes: []
}
Loading

0 comments on commit 13a2873

Please sign in to comment.