PowerShell 依赖项的组合可能会出现问题,因为它们需要是及时知道工作组,7.1.14 被吹捧为轻型解决方案所以请参阅下面的 TL;DR 编辑或其他 cmets,并以可能与普通用户不同的管理员身份运行。因此,请仔细执行这些步骤,因为有些步骤可能会降低您当前的设置。
最重要的是使用项目目录并注意您的提示位于该文件夹中,以确保您没有在默认的 PowerShell 目录中运行。我使用目标目录为“空白/空”的快捷方式,因此默认为当前工作文件夹。
第一次检查:-
project folder>[Net.ServicePointManager]::SecurityProtocol
应该返回 Tls12 或 Tls13 我们需要它是 1.2 所以请记下你的是否设置为 Tls13 并运行此行。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
我们可能需要更改包提供程序,因此首先检查 nuget 是否包含 https://www.nuget.org/api/v2/:-
> Get-PackageSource
Name ProviderName IsTrusted Location
---- ------------ --------- --------
nuget.org NuGet False https://www.nuget.org/api/v2/
PSGallery PowerShellGet False https://www.powershellgallery.com/api/v2
如果没有,您可以将其添加为
Register-PackageSource nuget.org https://www.nuget.org/api/v2/ -ProviderName NuGet
现在您应该能够按如下方式安装 dll
Install-Package -Name "itext7" -ProviderName NuGet -RequiredVersion 7.1.14 -Destination . -SkipDependencies
Install-Package -Name Portable.BouncyCastle -ProviderName NuGet -RequiredVersion 1.8.9.0 -Destination . -SkipDependencies
Install-Package -Name Common.Logging -ProviderName NuGet -RequiredVersion 3.4.1.0 -Destination . -SkipDependencies
Install-Package -Name Common.Logging.Core -ProviderName NuGet -RequiredVersion 3.4.1.0 -Destination . -SkipDependencies
仔细检查您的文件夹结构是否正确
请注意脚本的顺序和位置对于正确加载至关重要
Add-Type -Path (Join-Path $PSScriptRoot ".Common.Logging.Core.3.4.1lib
et40Common.Logging.Core.dll")
Add-Type -Path (Join-Path $PSScriptRoot ".Common.Logging.3.4.1lib
et40Common.Logging.dll")
Add-Type -Path (Join-Path $PSScriptRoot ".Portable.BouncyCastle.1.8.9lib
et40BouncyCastle.Crypto.dll")
Add-Type -Path (Join-Path $PSScriptRoot ".itext7.7.1.14lib
et40itext.io.dll")
Add-Type -Path (Join-Path $PSScriptRoot ".itext7.7.1.14lib
et40itext.layout.dll")
Add-Type -Path (Join-Path $PSScriptRoot ".itext7.7.1.14lib
et40itext.kernel.dll")
$pdfDocuFilename = (join-path $PSScriptRoot "My1st.pdf")
$pdfWriter = [iText.Kernel.Pdf.PdfWriter]::new($pdfDocuFilename)
$pdfdocument = [iText.Kernel.Pdf.PdfDocument]::new($pdfWriter)
$pdfdocument.AddNewPage()
$pdfdocument.Close()
这将产生一个空文件,但证明一切正常,您可以开始运行其他示例,例如 S_G 建议的示例,因此在加载 Add-Type 块后将我的空白示例替换为
[string] $DEST = "HelloWorld.pdf"
$pdfWriter = [iText.Kernel.Pdf.PdfWriter]::new($DEST)
$pdf = [iText.Kernel.Pdf.PdfDocument]::new($pdfWriter)
$document = [iText.Layout.Document]::new($pdf)
$document.Add([iText.Layout.Element.Paragraph]::new("Hello World! from Powershell"))
$pdf.Close()
... 祝你好运。
-
以上版本适用于固定时间点当用户博客证实 7.1 混音没有太多冲突时,目标是生成一组在其中工作的独立文件网络40环境,但时间在推移,您应该确保您使用的是更新的混音。然而,一切都在 7.1.15 中发生了变化由于现在 Net 4.5 和现在的 4.6.1 需要更多的依赖项列表,尽管 packages/itext7/7.2.1 本身仍然适用
packages/Portable.BouncyCastle/1.8.9 + 和通用日志记录仍然是 3.4.1