Skip to content

Commit 7f28d80

Browse files
committed
Improve readme
1 parent 164df18 commit 7f28d80

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

.img/PDFoutput.png

27.2 KB
Loading

.img/SwaggerInterface.png

47.2 KB
Loading

.img/docker-debug-toolbar.png

2.98 KB
Loading

README.md

+85-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,99 @@
1-
# Using ABCpdf 13+ in a Linux Container
1+
# ABCpdf in a Linux Container
22

3-
With Linux support now added for version 13 of ABCpdf we have put together an example project to show how to run ABCpdf as a containerized microservice.
3+
Linux has been supported since version 13 of ABCpdf. Here is an example project to show how to run ABCpdf as a containerized microservice using a Docker image based on Ubuntu 22.04 LTS. This allows in-container debugging in Visual Studio 2022 and later. You may use this as a template for your own ABCpdf-powered microservice.
44

5-
## Project Notes
5+
This project was initially generated using the ASP.NET Core Web API template using Visual Studio 2022 with the default options of Docker and OpenAPI support enabled. It uses the minimal API model to expose a test endpoint.
66

7-
This project was initially generated using the ASP.NET Core Web API template using Visual Studio 2022 with the default options of Docker and OpenAPI support enabled.
7+
## Building and Running the Application
88

9-
### Linux Runtime Container considerations
9+
### Pre-requisites
1010

11-
ABCpdf uses Windows and Linux native code - that's what makes it so fast. This means that the native ABCpdf modules have some prerequisite linux libraries. We have made some Ubuntu 22.04 based docker images with all the needed libraries over at
12-
[Docker Hub](https://hub.docker.com/repository/docker/abcpdf/ubuntu-22.04-aspnet).
11+
* Visual Studio 2022 or Later
12+
* [Docker Desktop](https://www.docker.com/) or [Docker Community Edition](https://docs.docker.com/engine/install/)
1313

14-
### Further Reading
14+
### Running the Application
15+
16+
Clone the APCpdfLinuxContainer repository and open the solution in Visual Studio 2022.
17+
18+
Select Docker from the Debugging toolbar dropdown if it isn't already selected. You may be prompted to start Docker Desktop which you should do - it has to be running to run the project in a container.
19+
20+
!["Docker Debug Toolbar"](.img/docker-debug-toolbar.png)
1521

16-
Please refer to [the latest ABCpdf linux documentation](https://www.websupergoo.com/helppdfnet/default.htm?page=source%2f2-getting_started%2f6-platforms.htm) for further information.
22+
The first time the solution is opened and Docker debugging is selected you will have to wait some time while Visual Studio performs the background task of "Warming up Docker debugging". This is performing a preliminary build of the Dockerfile including pulling the required images from Docker Hub. To see what it is doing and when it has finished check the "Output" tab and "Container Tools" from the dropdown.
1723

18-
**NB: You will need to paste in your Professional License key into the Program.cs file as indicated below:**
24+
**Be prepared for this to take 5 or more minutes the first time.** This is the only time you have to wait this long as the build is cached making the subsequent development workflow very fast.
25+
26+
While you wait you should find your ABCpdf license key and paste it into the Program.cs file where indicated near the top of the file.
1927

2028
```C#
2129
if(!XSettings.InstallLicense("[-- PASTE YOUR LICENSE CODE HERE --]")) {
2230
throw new Exception("License failed installation.");
2331
}
2432
```
33+
34+
Once the Dockerfile has been built as indicated in the Container Tools Output window you can run the application from the debug toolbar as Docker:
35+
36+
This will spin up a container to run the application launch your default browser to the OpenAPI swagger page.
37+
38+
### Trying It Out
39+
40+
The Swagger UI will show one GET endpoint of `/htmltopdf/` which simply implements [AddImageHtml()](https://www.websupergoo.com/helppdfnet/default.htm?page=source%2f5-abcpdf%2fdoc%2f1-methods%2faddimagehtml.htm) on the text.
41+
42+
Expand the section for this endpoint and click the "Try it out" button and enter some HTML like the following.
43+
44+
```html
45+
<p><strong>Hello</strong> <em>world</em> &#128578;
46+
```
47+
48+
!["Swagger Interface"](.img/SwaggerInterface.png)
49+
50+
Now you should see the byte array contents of a PDF document displayed as text in the "Response Body" text area which is not very useful!
51+
52+
To actually view the generated PDF copy the link in the "Request URL" and paste it into the address bar of your browser. It will be something like the following but with a randomly generated port:
53+
54+
```bash
55+
http://localhost:5521/htmltopdf?htmlString=%3Cb%3EHello%3C%2Fb%3E%20%3Cem%3Eworld%3C%2Fem%3E
56+
```
57+
This should load up a PDF in the browser as follows:
58+
!["PDF Test OUtput"](.img/PDFoutput.png)
59+
60+
### Language Support
61+
62+
Out of the box the Docker image we use has support for a number of language character sets. You may test this with the application using the following Ukrainian, Arabic and Hebrew language examples:
63+
64+
```html
65+
Here are some examples you could use to highlight the use of different languages and even emojis using the default abcpdf repository image:
66+
<p><strong>Привіт</strong> <em>Світ</em></p>
67+
<p><strong>مرحبا</strong> <em>بالعالم</em></p>
68+
<p><strong>שלום</strong> <em>עולם</em></p>
69+
```
70+
71+
### Installing Additional Languages
72+
73+
For other languages you may need to install additional language pack resources in the Dockerfile. So for Japanese, Chinese and Korean you would need to add the following commands to the runtime Dockerfile:
74+
75+
```Dockerfile
76+
FROM abcpdf/ubuntu-22.04-aspnet:8.0 AS base
77+
WORKDIR /app
78+
EXPOSE 8080
79+
EXPOSE 8081
80+
RUN apt-get update
81+
# Japanese
82+
RUN apt-get install -y language-pack-ja install japan*
83+
# Chinese
84+
RUN apt-get install -y language-pack-zh* chinese*
85+
# Korean
86+
RUN apt-get install -y language-pack-ko install korean*
87+
```
88+
89+
Other languages may be similarly installed. See [the Ubuntu packages site](https://packages.ubuntu.com/search?keywords=language-pack) to find your desired language pack.
90+
91+
## ABCpdf Runtime Docker Images
92+
93+
The .NET 8.0 runtime image used in this project is [abcpdf/ubuntu-22.04-aspnet:8.0](https://hub.docker.com/repository/docker/abcpdf/ubuntu-22.04-aspnet/general) which is based on Ubuntu 22.04 LTS. This image includes the requisite libraries required by the linux-native components of ABCpdf as well as a basic set of fonts.
94+
95+
The Dockerfiles used to create the Docker Hub Docker images are [available here](https://github.com/ABCpdf-Team/ABCpdf-Dockerfiles/tree/main/Runtimes/Ubuntu/22.04). You may use these to roll-your-own image.
96+
97+
### Further Reading
98+
99+
Please refer to [the latest ABCpdf linux documentation](https://www.websupergoo.com/helppdfnet/default.htm?page=source%2f2-getting_started%2f6-platforms.htm) for further information.

0 commit comments

Comments
 (0)