---
title: "Setting Up a Server to Convert Webpages into PDFs with WEB2PDF"
date: 2023-10-19T09:31:30.000Z
author: Z.SHINCHVEN
tags: [docker, puppeteer, web2pdf, pdf]
canonical: https://atlassc.net/2023/10/19/setting-up-a-server-to-convert-webpages-into-pdfs-with-web2pdf
---
## Introduction

Converting webpages into PDFs is a common requirement for preserving the layout and content of webpages. In this blog post, we will walk you through the process of setting up a server using the [WEB2PDF](https://github.com/ShinChven/web2pdf) project which leverages Docker and Puppeteer for this purpose.

## Prerequisites

1. Docker and Docker Compose installed on your system.

Steps:
1. Pull the WEB2PDF Docker image from Docker Hub using the command:
```bash
docker pull shinchven/web2pdf
```
2. Create a `docker-compose.yml` file with the following content to set up the service:
```yaml
version: '3.5'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    image: shinchven/web2pdf
    container_name: web2pdf
    restart: always
    ports:
      - "3040:3030"
    volumes:
      - ./output:/usr/src/app/public/output
```
3. Navigate to the directory containing the `docker-compose.yml` file and run the command to start the service:
```bash
docker-compose up -d
```
## Usage

- To convert a webpage to PDF, you can use either the GET or POST HTTP methods as shown below:
```bash
curl "http://localhost:3040/generate-pdf?url=https://www.google.com&filename=google.pdf"
```
or
```bash
curl -X POST -F "url=https://www.google.com" -F "filename=google.pdf" http://localhost:3040/generate-pdf
```

This setup will allow you to easily convert webpages into PDFs by sending a simple HTTP request to the server.

## Parameters

The service accepts several parameters to customize the output:

| Parameter | Description | Default Value |
| --- | --- | --- |
| `url` | The URL of the web page to convert into a PDF. | (none) |
| `filename` | The name of the output PDF file. | A UUID |
| `pdfOptions` | Options to pass to the Puppeteer's `pdf` method. | `undefined` |
| `redirect` | If set to `true`, the service will redirect to the generated PDF file. | `false` |

Please note that the `url` parameter is required. If no `filename` is provided, a UUID will be used as the file name. The `pdfOptions` parameter can be used to pass any additional options to the Puppeteer's `pdf` method. If `redirect` is set to `true`, the service will redirect to the generated PDF file instead of returning a JSON response.
