PDF打开是横向的 C#获取宽和高确实相反的
这可能是因为PDF文件的页面旋转了90度。在C#中获取PDF文件的宽和高时,您可以使用以下代码来获取正确的值:
using (PdfDocument pdf = PdfDocument.Load(filePath))
{
PdfPage page = pdf.Pages[0]; //假设您要获取第一页的宽和高
int width = page.Width;
int height = page.Height;
if (page.Rotation == PdfPageRotation.Rotate90 || page.Rotation == PdfPageRotation.Rotate270)
{
//如果页面旋转了90度或270度,则交换宽和高的值
int temp = width;
width = height;
height = temp;
}
Console.WriteLine("Width: " + width);
Console.WriteLine("Height: " + height);
}
在上面的代码中,我们首先加载PDF文件并获取第一页。然后,我们获取页面的宽和高,并检查页面是否旋转了90度或270度。如果是这样,我们就交换宽和高的值,以便获取正确的值。最后,我们输出宽和高的值
原文地址: https://www.cveoy.top/t/topic/hhXH 著作权归作者所有。请勿转载和采集!