# xc-print

> Print utility service

Latest version **1.0.6** (published 2021-11-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install xc-print
pnpm add xc-print
yarn add xc-print
bun add xc-print
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-11-24 |
| First published | 2021-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 5.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sergey Chikuyonok |
| Maintainers | arihersh |

## Links

- npm: https://www.npmjs.com/package/xc-print
- Repository: https://github.com/Xcential-Corporation/xc-print
- Homepage: https://github.com/Xcential-Corporation/xc-print#readme
- Issues: https://github.com/Xcential-Corporation/xc-print/issues
- npm.io page: https://npm.io/package/xc-print

## Dependencies (9)

- [cpy](https://npm.io/package/cpy.md) ^8.1.0
- [del](https://npm.io/package/del.md) ^5.1.0
- [temp](https://npm.io/package/temp.md) ^0.9.1
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [busboy](https://npm.io/package/busboy.md) ^0.3.1
- [prince](https://npm.io/package/prince.md) ^1.9.5
- [express](https://npm.io/package/express.md) ^4.17.1
- [commander](https://npm.io/package/commander.md) ^5.1.0
- [puppeteer](https://npm.io/package/puppeteer.md) ^3.0.4

## Recent versions

- 1.0.6 (latest) — 2021-11-24

## README

# Server for XML to PDF converter

Provides REST API for converting XML to PDF.

## Usage

> Before initial start or after any update, run `npm install` to update dependencies

To start HTTP server, run

```sh
npm start
```

This command will compile TypeScript sources and start HTTP server at http://localhost:9000.

The server provides following endpoints:

### POST `/convert/pdf`

Converts given XML file to PDF, applying stylesheet transforms. A request must be sent as form-data with the following fields:

* `xmlFile`: XML file to convert. Must be sent a string (file contents) or `Buffer` (file binary).
* `cssFile` (optional): list of file paths or file binaries with CSS styles that must be applied to XML file. If sent as string, it will be treated as file path relative to `./css` folder of current repo, if sent as file binary, will be stored into temp dir first. In order to pass multiple CSS files, add `[]` at the end of each field entry, e.g. `cssFile[]=...&cssFile[]=...`.
* `cssText` (optional): Inline CSS stylesheet to apply to XML.
* `xsltFile` (optional): an XSLT file to apply to XML, either relative path to repo’s `./xslt` dir for file binary.
* `engine` (optional): engine to use to generate PDF. Supported values are `prince` (default) and `puppeteer`.

Endpoint will return PDF file binary on success or error if failed.

Usage example with `curl`:

```sh
curl -F 'xmlFile=@./116hr6201ih-116hr6201enr-compare.xml' \
   -F 'cssFile[]=uslm.css' \
   -F 'cssFile[]=uslm-reports.css' \
   -F 'cssFile[]=comparison-print.css' \
   --output result.pdf http://localhost:9000/convert/pdf
```

## Restricting access to third-parties

By default, xc-print service handles all incoming requests. In order to restrict access to unauthorized third-parties, you must provide service a list of _secret keys_.

Secret key is just a random string, long enough to complicate brute forcing. If secrets are provided, all incoming HTTP requests must contain `Authentication` HTTP header with one of the secret keys.

A workflow with secret keys is following:

* Create `secrets.json` file somewhere outside of this repo. The file should contain an array for keys, for example `["secret1", "secret2"]`. Use online services like https://www.uuidgenerator.net to generate random strings.
* Start xc-print service with `-s` command-line option which points to `secrets.json` file:

```sh
npm start -- -s path/to/secrets.json
```

When service starts, you should see log “Server started at http://localhost:9000 **with secrets**”.
* Give third-party one of the secret keys.
* All incoming requests should have `Authentication` HTTP header to pass validation:

```sh
curl -F 'xmlFile=@./116hr6201ih-116hr6201enr-compare.xml' \
   -F 'cssFile[]=uslm.css' \
   -F 'cssFile[]=uslm-reports.css' \
   -F 'cssFile[]=comparison-print.css' \
   -H 'Authentication: secret1' \
   --output result.pdf http://localhost:9000/convert/pdf
```

To add or revoke keys, simply edit `secrets.json` file and and restart service.

## CLI options

Service supports the following CLI options:

* `-p, --port` – HTTP port for server, default is 9000.
* `-s, --secrets` – path to JSON file with secret keys. If specified, all incoming HTTP requests should contain `Authentication` HTTP header with one of the secret keys.

Example:

```sh
npm start -- -p 8901 -s path/to/secrets.json
# Server started at http://localhost:8901 with secrets
```

## Fonts: Linux does not have MS Fonts by default

Linux servers have a limited set of fonts by default. In order to use any MS Fonts they must be installed on the server
+ http://mscorefonts2.sourceforge.net/

`$sudo yum install curl cabextract xorg-x11-font-utils fontconfig`

Then: `$sudo rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm`

## Debugging

In order to debug errors, start server with `DEBUG=*` env variable: it will provide log from different server sub-systems:

```sh
DEBUG=* npm start
```

## Docker

The local Dockerfile can be used to build the image (`docker build ./`). To run:

`podman run  -d -t -i -p 9000:9000  -v "xcprintlicense:/app/vendor/prince/license"  docker.io/xcential/xcprint:latest&`

---
_Source: https://npm.io/package/xc-print · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
