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

vue3-to-pdf

v1.0.8

Published

Export to PDF using vue3 and html2pdf.js

Downloads

1,217

Readme

vue3-to-pdf

  • Export and auto download PDF using vue3 and html2pdf.js.
  • Easy to custom any PDF style because it will be export from real html.
  • Can use custom css style for pdf page using vue style.

Install

npm i vue3-to-pdf

or pnpm

pnpm i vue3-to-pdf

or yarn

yarn add vue3-to-pdf

Register component

import vue3ToPdf from 'vue3-to-pdf'
Vue.use(vue3ToPdf)

Use component

<v-pdf ref="pdf" :options="pdfOptions" :filename="exportFilename">
  <h2>HTML Table</h2>
  <table>
    <tr>
      <th>Company</th>
      <th>Contact</th>
      <th>Country</th>
    </tr>
    <tr>
      <td>Alfreds Futterkiste</td>
      <td>Maria Anders</td>
      <td>Germany</td>
    </tr>
    <tr>
      <td>Centro comercial Moctezuma</td>
      <td>Francisco Chang</td>
      <td>Mexico</td>
    </tr>
    <tr>
      <td>Ernst Handel</td>
      <td>Roland Mendel</td>
      <td>Austria</td>
    </tr>
    <tr>
      <td>Island Trading</td>
      <td>Helen Bennett</td>
      <td>UK</td>
    </tr>
    <tr>
      <td>Laughing Bacchus Winecellars</td>
      <td>Yoshi Tannamuri</td>
      <td>Canada</td>
    </tr>
    <tr>
      <td>Magazzini Alimentari Riuniti</td>
      <td>Giovanni Rovelli</td>
      <td>Italy</td>
    </tr>
  </table>

  <img src="base64 image or url" />

  <!-- You can loop to display page number as you want -->
  <div class="html2pdf__page-number">1</div>

  <!-- Break page pdf -->
  <div class="html2pdf__page-break"></div>
</v-pdf>

...
// Props

pdfOptions = {
  margin: 15,
  image: {
    type: 'jpeg',
    quality: 1,
  },
  html2canvas: { scale: 3 },
  jsPDF: {
    unit: 'mm',
    format: 'a4',
    orientation: 'p',
  },
},
exportFilename: 'my-custom-file.pdf'

...

<style scoped>
  table {
    font-size: 14px;
    text-align: center;
    border: 1px solid #ccc;
    border-collapse: collapse;
    th {
      background: #ddd;
      font-weight: bold;
    }
    td,
    th {
      padding: 8px;
      border: 1px solid #ccc;
    }
  }
  ... Any other styles here;
</style>

Call start download pdf with Options api

this.$refs.pdf.download()

Call start download pdf with Composition api

const pdf = ref(true)
const download = () => {
  pdf.value.download()
}

Call pdf in new tab with Options api

this.$refs.pdf.openInNewTab()

Call pdf in new tab with Composition api

const pdf = ref(true)
const openInNewTab = () => {
  pdf.value.openInNewTab()
}

To break page, use html2pdf__page-break

<div class="html2pdf__page-break"></div>

To add page number, use html2pdf__page-number

<div class="html2pdf__page-number">{{ pageNumber }}</div>

License

The MIT License

Testing Instructions

To run the project and test its workflow, follow these steps:

  1. Navigate to the test folder using the command line interface.
cd test
  1. Install the project dependencies using the following command:
pnpm install
  1. Link the project dependencies by executing:
pnpm link ../
  1. Start the development server to run the tests:
pnpm run dev