我在我们的应用程序中使用PDFsharp来读/写PDF。我正在尝试获取要在元数据窗口中显示的页面的纸张大小。我使用下面的代码来做同样的事情:
// read PDF document into memory
var pdfDocument = PdfReader.Open(pdfPath);
// if PDF document has more than one page, then try to get the page size from first page
if (pdfDocument.Pages.Count > 0)
{
var pageSize = pdfDocument.Pages[0].Size.ToString();
} // if但每次它返回'Undefined‘时,我甚至尝试为MS Word创建A4页面文档。但是它仍然返回'Undefined‘。
我也从HTML创建了一个PDF,但页面大小也是未定义的。
static void Main(string[] args)
{
// create PDF config to generate PDF
var config = new PdfGenerateConfig()
{
PageSize = PageSize.Letter,
PageOrientation = PageOrientation.Landscape
};
// load the HTML file
var html = System.IO.File.ReadAllText(@"C:\Users\mohit\Desktop\Temp\Ekta\Test.html");
// generate the PDF
var pdf = PdfGenerator.GeneratePdf(html,
PageSize.Letter);
// get the paper size of first page
var size = pdf.Pages[0].Size;
// save the pdf document
pdf.Save(@"C:\Users\mohit\Desktop\Temp\Ekta\A13.pdf");
Console.ReadKey();
}发布于 2016-10-13 16:24:22
您必须使用的属性是Width和Height。如果不想以磅为单位显示大小,请将其转换为毫米或英寸。
由于可以指定A4或Letter,因此属性Size是为新页面设置标准页面大小的便捷方法。不会为导入的PDF文件设置该选项。
https://stackoverflow.com/questions/40001960
复制相似问题