iTextSharp 文本文件到横向 powershell

iTextSharp text file to powershell in Landscape

我正在尝试在横向模式下使用 powershell 将文本文件转换为 PDF。

目前使用的 iTextSharp 让我在将文本转换为 PDF 方面取得了很好的成绩,但是当添加线条以创建 PDF 时,我无法找到任何东西将其横向放置。

这是我目前使用的。

[System.Reflection.Assembly]::LoadFrom("I:\powershell\itextsharp.dll")
$doc = New-Object itextsharp.text.document
$stream = [IO.File]::OpenWrite("I:\powershell\test.pdf")
$writer = [itextsharp.text.pdf.PdfWriter]::GetInstance($doc, $stream)
$doc.Open()
[IO.File]::ReadAllLines("I:\powershell\test.txt") | foreach {
    $line = New-Object itextsharp.text.Paragraph($_)
    $doc.Add($line)
}
$doc.Close()
$stream.Close()

我找到了一些用于 C# 的东西,Java powershell 什么都没有。

试过这个没有用:

$doc = New-Object iTextSharp.text.Document([iTextSharp.text.PageSize]::LEGAL_LANDSCAPE)

非常感谢。 D

使用 overloaded constructor that takes a Rectangle,明确设置页面大小:

$doc = New-Object itextsharp.text.document(New-Object itextsharp.text.Rectangle(792, 612));