Skip to content

Commit

Permalink
Refactor to enable any key name in the request and update readMe file
Browse files Browse the repository at this point in the history
  • Loading branch information
Charchit26 committed Aug 3, 2021
1 parent 1b89ef1 commit 994d3d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Run `npm install`
Run `node index.js`

## API
Papyrus exposes just one `POST` endpoint for pdf generation: `/pdf`. The webpage to be printed is provided as the
request body param `webURL`.
Papyrus exposes some `POST` endpoints for pdf generation:

1. `/pdf`: The webpage to be printed is provided as the request body param `webURL`.

Sample request:

Expand All @@ -27,6 +28,15 @@ curl --location --request POST 'localhost:3000/pdf' --header 'Content-Type: appl
```
The pdf is written to the file `download.pdf`.

2. `/html2pdf`: The webpage to be printed is provided as an HTML file with any key.

Sample request:

```shell
curl --location --request POST 'localhost:3000/html2pdf' \
--form 'file=@"/path/to/file/Or/Use/sample.html/from/this/repo"' > download.pdf
```

## Disclaimer

The project could use a lot of improvements, some of which are mentioned in the issues. Feel free to add feature
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ app.post('/pdf', (req, res) => {
});
});

app.post('/html2pdf', multer().single('file'), (req, res) => {
app.post('/html2pdf', multer().any(), (req, res) => {
console.log("Generating pdf...");

fs.writeFileSync("temp.html", req.file.buffer, 'utf8');
var content = fs.readFileSync("temp.html");
fs.writeFileSync("temp.html", req.files[0].buffer, 'utf8');
var content = fs.readFileSync("temp.html", "utf-8");
pdfGenerator.generateFromHTML(content, 'webpage.pdf')
.then(result => {
console.log("Success: " + result);
Expand Down

0 comments on commit 994d3d2

Please sign in to comment.