Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

c# - Whats the correct way to install a font in Windows Container?

I'm running a .net framework api in a windows os over docker. My api generate a PDF document. This PDF does not show any character, because, the windows distribution I'm using does not have fonts installed by default.

So, I decided to try to install the fonts by my self.

This is my dockerfile:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
ADD /bin/Resources/Fonts/Fonts.tar.gz c:/fonts/

COPY /bin/Resources/Fonts/install.ps1 c:/fonts/

RUN powershell "c:fontsinstall.ps1"

it takes a zip, put in the container, and call "install.ps1", a powershell script to install the fonts.

If I enter in the container and manually run install.ps1, everything works. If I try to run install.ps1 throw a docker command, the command run, there's no error in the messages, but, the fonts does not appear in the PDF...like if it was not installed.

when I enter the container and list fonts, everything appear ok, but the fonts dont show in the pdf.

this is my install.ps1 file. It put the fonts in "c:/windows/fonts" and add a registry key to install it.

$fontFolder = "C:Fonts"
$padVal = 20
$pcLabel = "Connecting To".PadRight($padVal," ")
$installLabel = "Installing Font".PadRight($padVal," ")
$errorLabel = "Computer Unavailable".PadRight($padVal," ")
$openType = "(Open Type)"
$regPath = "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionFonts"
$objShell = New-Object -ComObject Shell.Application

if(!(Test-Path $fontFolder))
{
    Write-Warning "$fontFolder - Not Found"
}
else
{
    $objFolder = $objShell.namespace($fontFolder)
    
    Try{
        $destination = "C:WindowsFonts" -join ""
        
        foreach ($file in $objFolder.items())
        {
            $fileType = $($objFolder.getDetailsOf($file, 2))
            if(($fileType -eq "OpenType font file") -or ($fileType -eq "TTF file"))
            {
                $fontName = $($objFolder.getDetailsOf($File, 21))
                $regKeyName = $fontName,$openType -join " "
                $regKeyValue = $file.Name
                Write-Output "$installLabel : $regKeyValue"
                Copy-Item $file.Path  $destination
                Invoke-Command -ScriptBlock { $null = New-ItemProperty -Path $args[0] -Name $args[1] -Value $args[2] -PropertyType String -Force } -ArgumentList $regPath,$regKeyname,$regKeyValue
            }
        }
    }
    catch{
        Write-Warning "$errorLabel"
    }
}

how can I solve this?

question from:https://stackoverflow.com/questions/66058419/whats-the-correct-way-to-install-a-font-in-windows-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...