Structure:
- HtmlToPdf.Console - .NET Core Console application that converts HTML to PDF.
- Dockerfile.windows - the Dockerfile for running HtmlToPdf.Console under Windows containers
- Dockerfile.linux - the Dockerfile for running HtmlToPdf.Console under Linux containers
- Clone the current repository or download as the archive file:
git clone https://github.com/iron-software/tutorials.git
- Change the current folder to this tutorial context by the next command
cd .\tutorials\IronPdf\Docker\HtmlToPdf
- Switch the Docker to Windows containers: Use the menu item 'Switch to Windows containers...' from the Docker Desktop or the next command
"C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchWindowsEngine
- Build the Docker image based on Windows Core Server:
docker build --rm -t htmltopdf.windows -f Dockerfile.windows .
- Run the Docker image
Replace the place holder
%PDF-RESULT%
by a path to result folder, e.g.C:\temp\pdf-result
(the path should be exist before run the command).
docker run -v %PDF-RESULT%:c:\pdf-result --rm --user=ContainerAdministrator htmltopdf.windows https://google.com c:\pdf-result\google.com.pdf
The result should be like that:
C:\>docker run --rm --user=ContainerAdministrator -v c:\temp\pdf-result:c:\pdf-result htmltopdf https://google.com c:\pdf-result\google.com.pdf
IronPdf 2020.3.2.0 sample: converts HTML to PDF
Arguments:
html=https://google.com
pdf=c:\pdf-result\google.com.pdf
IronPDF:Chromium initialized (msgid 80010106)
Result saved to: c:\pdf-result\google.com.pdf
- Switch the Docker to Linux containers: Use the menu item 'Switch to Linux containers...' from the Docker Desktop or the next command
"C:\Program Files\Docker\Docker\DockerCli.exe" -SwitchLinuxEngine
- Build the Docker image based on Windows Nano Server:
docker build --rm -t htmltopdf.linux -f Dockerfile.linux .
- Run the Docker image
Replace the place holder
%PDF-RESULT%
by a path to result folder, e.g.C:\temp\pdf-result
(the path should be exist before run the command).
docker run -v %PDF-RESULT%:/pdf-result --rm --user=ContainerAdministrator htmltopdf.linux https://google.com /pdf-result/google.com.pdf
The result should be like that:
C:\>docker run --rm --user=ContainerAdministrator -v c:\temp\pdf-result:/pdf-result htmltopdf https://google.com /pdf-result/google.com.pdf
IronPdf 2020.3.2.0 sample: converts HTML to PDF
Arguments:
html=https://google.com
pdf=/pdf-result/google.com.pdf
IronPDF:Chromium initialized (msgid 80010106)
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig == true
Attempting to automatically install Linux / Docker dependencies. This may take some time on your first run on this machine.
...
Linux / Docker dependency installation success
Result saved to: /pdf-result/google.com.pdf