Build your own dedicated pdf Online compression website with lightweight server

Keywords: Docker server

Today, we need to compress a pdf file. Because pdf involves some personal information, we don't want to use the compression of online websites. I downloaded several offline compression tools, most of which actually need to charge. Although I found a free tool to deal with this later, I thought I might encounter such things later, so I came up with the idea of making an Online pdf compression website. Check the relevant information and see one ghostscript The tool can compress pdf files. A simple version is made based on this tool. I won't tell you how to do it. The final effect is shown in the figure below. You can see that the page is very concise. It supports uploading multiple pdf files at the same time, which is suitable for personal use. If my friends find it useful, order a star for my warehouse. https://hub.docker.com/r/mrlee326/pdfcompress

Let's talk about how to deploy this online pdf compression website on Tencent cloud lightweight server. Interested partners can play it

Purchase Tencent cloud lightweight server

Since you want to deploy on a lightweight server, you need to buy a lightweight server first. Now the lightweight server is doing activities. The configuration of 2-core 4G only costs 74 yuan a year. The details are OK Click this link Yes. As shown in the figure below, click purchase

Then select [region] and [image] to select the region closest to you. We will use Docker to install later. Therefore, directly select [Docker basic image] here. The system can select a familiar one. If it doesn't matter, keep the default.

Then submit the order and pay. After a while, our lightweight server instance will be created successfully. In order to facilitate operation, a terminal needs to be used to connect to the server. This involves some configurations, Official documents It's very clear. You can watch and operate it yourself. The following steps operate on the terminal by default.

Start Docker container

After purchasing the lightweight server, you can start the docker container. The startup command is also very simple, just one line

docker run -d --name pdfcompress  \ 
    --restart=always -p 8082:8082  \ 
   -v /data/pdfcompress/input:/opt/pdfcompress/input  \ 
  -v /data/pdfcompress/output:/opt/pdfcompress/output \
   mrlee326/pdfcompress

Where / opt/pdfcompress/input is the directory used to place the files uploaded by the user, and / opt/pdfcompress/output is the directory used to place the converted files. It is recommended to mount them on the host machine, so as to facilitate the cleaning of files later. If you have the ability, you can write a timed script to clean up expired files.

After startup, you can access our pdf Online compression website through the browser. Currently, there are three options [high quality], [medium quality] and [low quality], corresponding to ghost script's pre press, ebook and screen.

If you want an https certificate, you can use the acme company container to issue the certificate automatically. This operation is also very simple. Only two additional containers need to be started

docker run --detach \
    --name nginx-proxy \
    --publish 80:80 \
    --publish 443:443 \
    --volume certs:/etc/nginx/certs \
    --volume vhost:/etc/nginx/vhost.d \
    --volume html:/usr/share/nginx/html \
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \
    nginxproxy/nginx-proxy
 docker run --detach \
    --name nginx-proxy-acme \
    --volumes-from nginx-proxy \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --volume acme:/etc/acme.sh \
    --env "DEFAULT_EMAIL=mail@yourdomain.tld" \
    nginxproxy/acme-companion

Finally, start pdfcompress. Note that several environment variables virtual are added_ HOST,VIRTUAL_PORT,ETSENCRYPT_HOST. At the same time, pdf.bar.foo needs to be parsed to the ip of the lightweight server in advance.

docker run --detach \
	--restart=always --name pdfcompress \
	-v /data/pdfcompress/input:/opt/pdfcompress/input \
	-v  /data/pdfcompress/output:/opt/pdfcompress/output \
	--env "VIRTUAL_HOST=pdf.bar.foo"  \
	--env "VIRTUAL_PORT=8082"   \
	--env "LETSENCRYPT_HOST=pdf.bar.foo" \
	mrlee326/pdfcompress

Then access it through the browser https://pdf.bar.foo , you can see the small green lock, indicating that our website is safe.

summary

Through the above process, we have our own online pdf compression website, so we don't have to worry about saving our personal information by others. At the same time, if we change the computer, we don't need to reinstall the software.

Posted by vanessa123 on Wed, 15 Sep 2021 16:40:52 -0700