From 2b81bd6f2461aa2d96c0dd7f78989eac68274780 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 27 Aug 2023 20:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=BE=97=E5=88=B0=E4=B8=80=E5=AE=9A=E7=BC=93=E8=A7=A3?= =?UTF-8?q?=20=E4=BD=86=E4=B8=8D=E6=8E=92=E9=99=A4=E6=BD=9C=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj | 1 + ConsoleApp1/ConsoleApp1/Program.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj index ff17da3..d0f1e74 100644 --- a/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj @@ -35,6 +35,7 @@ 1.0.0.2 7.0 ConsoleApp1.Program + AnyCPU diff --git a/ConsoleApp1/ConsoleApp1/Program.cs b/ConsoleApp1/ConsoleApp1/Program.cs index 1948dee..0df1cd5 100644 --- a/ConsoleApp1/ConsoleApp1/Program.cs +++ b/ConsoleApp1/ConsoleApp1/Program.cs @@ -8,8 +8,6 @@ using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; -using iText.Kernel.Geom; -using iText.Layout.Properties; namespace ConsoleApp1 { @@ -95,8 +93,8 @@ namespace ConsoleApp1 UpdateProgressBar(currentImageIndex, totalImageCount); Image image = new(ImageDataFactory.Create(imageFile)); - //image.SetAutoScale(true); - //image.SetHorizontalAlignment(HorizontalAlignment.CENTER); + + // 合适的缩放 float widthRatio = pdfDocument.GetDefaultPageSize().GetWidth() / image.GetImageWidth(); float heightRatio = pdfDocument.GetDefaultPageSize().GetHeight() / image.GetImageHeight(); float ratio = Math.Min(widthRatio, heightRatio); @@ -108,6 +106,9 @@ namespace ConsoleApp1 image.SetFixedPosition(x, y); doc.Add(image); + GC.Collect(); + //image = null; + // 在除最后一张图像外的图像后添加空白页面 if (currentImageIndex < totalImageCount - 1) { @@ -118,6 +119,7 @@ namespace ConsoleApp1 } // 关闭文档 + //doc.Close(); //这里会导致内存无法自动回收 pdfDocument.Close(); pdfWriter.Close();