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

directus-extension-flow2pdf

v1.1.3

Published

This extension allows you to print pdfs from directus flows

Downloads

686

Readme

Flow2Pdf

The flow2pdf extension is a bundle that allows directus to print data from flow results and liquid templates.

Requirements

  • Node.js 18 or higher
  • directus-extension-flow2pdf installed on your Directus instance.

Usage

The extension will add a new interface, endpoint and operation to your directus instance. Find the configurations for each interface type below

Interface Configuration

  • Create a Flow with Webhook trigger and set the method as POST, now copy the id of the Flow. Make sure that the trigger is not asynchronous.
  • Create a Button Links field in the desired collection and choose Flow2PDF as the interface.
  • Create extensions/template directory and add your .liquid template.

Interface Configuration

  • Flow Id: Id of the Flow you will be collecting data from (Note: the last operation of your Flow should return some JSON data ).
  • Behavior: Accepts two values
    • print: To print the document from your printer
    • download: To download the document as PDF
  • Template: the name of your liquid js template stored in extensions/templates directory. The data from your flow will be passed to the liquid file.
  • label: The label of the button
  • Icon: The icon of the button
  • Type: The type of the button. Accepted values are primary, secondary, warning and danger
  • Pdf Options: Options to customize the generated pdf. You should provide a json with the following parameters:

|Name |Type |Default |Description | |------------|----------------|--------------------------------|------------------------------------------------------------------------------------------------------------| |margin |number or array |0 |PDF margin (in jsPDF units). Can be a single number, [vMargin, hMargin], or [top, left, bottom, right]. | |pagebreak |object |{mode: ['css', 'legacy']} |Controls the pagebreak behaviour on the page. See Page-breaks below. | |image |object |{type: 'jpeg', quality: 0.95} |The image type and quality used to generate the PDF. See Image type and quality below.| |enableLinks |boolean |true |If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. | |html2canvas |object |{ } |Configuration options sent directly to html2canvas (see here for usage).| |jsPDF |object |{ } |Configuration options sent directly to jsPDF (see here for usage).|

  • Template: the name of your liquid js template stored in extensions/templates directory. The data from your last operation will be passed to the liquid file.

API endpoint

If you want to print a pdf from you own app (Vuejs, Reactjs, Angular...), you can use the exposed endpoint flow2pdf/print

  • Trigger the flow using the extension sdk Guide to trigger a flow

  • Run a POST request to the following endpoint http://your-directus-instance.com/flow2pdf/print Guide run POST request on custom Directus endpoint

  • The body should match format { "flow_data": { "property1": "value1", "property2": "value2" }, "template": "path to your template" }

    • flow_data should contained the response you received after the flow was triggered
    • template is the path to your liquid file
  • If the request is successful you'll get a response with the following format {"html": "The corresponding html"}

  • You can then use html2pdf.js to transform the html output to a pdf

Extra

  • You can add MARKETPLACE_TRUST="all" option in your directus env variables to be able to browser API/Hybrid extensions within the marketplace section of your directus app.