PDF文件是横向A4格式,需要在第一页指定位置插入一个条码,发现插入的条码是纵向的,如何处理把条码变成横向?
另外如何检测PDF文件是纵向/横向排版?
static void Main(string[] args)
{
//加载PDF
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(@"test.pdf");
PdfPageBase page= pdf.Pages[0];
//判断PDF页面的排版方向
PdfPageOrientation orientation = JudgeOrientation(page);
//插入条码到PDF第一页
PdfCodabarBarcode barcode = new PdfCodabarBarcode("00:12-3456/7890");
barcode.Draw(page, new PointF(50, 200));
//保存新建PDF
pdf.SaveToFile("结果.pdf", Spire.Pdf.FileFormat.PDF);
}
//判断PDF页面的排版方向
private static PdfPageOrientation JudgeOrientation(PdfPageBase page)
{
PdfPageOrientation orientation;
float width = page.Size.Width;
float height = page.Size.Height;
//对比高宽值进行判断
if (width > height)
{
Console.WriteLine("Landscape");
orientation = PdfPageOrientation.Landscape;
}
else
{
Console.WriteLine("Portrait");
orientation = PdfPageOrientation.Portrait;
}
return orientation;
}
......
page.Canvas.RotateTransform(-90);
barcode.Draw(page, new PointF(-200, 50));
......