成功移植了旧的缩放对齐功能

基本上差不多了
This commit is contained in:
Chenx221 2023-08-27 20:31:25 +08:00
parent 5bb4616a5f
commit 8c1a818260

View File

@ -95,8 +95,17 @@ namespace ConsoleApp1
UpdateProgressBar(currentImageIndex, totalImageCount); UpdateProgressBar(currentImageIndex, totalImageCount);
Image image = new(ImageDataFactory.Create(imageFile)); Image image = new(ImageDataFactory.Create(imageFile));
image.SetAutoScale(true); //image.SetAutoScale(true);
image.SetHorizontalAlignment(HorizontalAlignment.CENTER); //image.SetHorizontalAlignment(HorizontalAlignment.CENTER);
float widthRatio = pdfDocument.GetDefaultPageSize().GetWidth() / image.GetImageWidth();
float heightRatio = pdfDocument.GetDefaultPageSize().GetHeight() / image.GetImageHeight();
float ratio = Math.Min(widthRatio, heightRatio);
image.Scale(ratio,ratio);
// 将图像添加到页面中间
float x = (pdfDocument.GetDefaultPageSize().GetWidth() - image.GetImageScaledWidth()) / 2;
float y = (pdfDocument.GetDefaultPageSize().GetHeight() - image.GetImageScaledHeight()) / 2;
image.SetFixedPosition(x, y);
doc.Add(image); doc.Add(image);
// 在除最后一张图像外的图像后添加空白页面 // 在除最后一张图像外的图像后添加空白页面