问题:
合并多个 PDF 文档时,每个页面都被视为整页,即使只有少量内容,导致合并后出现垂直空白
解决方案:
public class PdfVeryDenseMergeTool { // ... (rest of the class) protected Rectangle PageSize; protected float TopMargin; protected float BottomMargin; protected float Gap; protected Document Document; protected PdfWriter Writer; protected float YPosition = 0; public PdfVeryDenseMergeTool(Rectangle size, float top, float bottom, float gap) { // ... (rest of the constructor) } public void Merge(MemoryStream outputStream, List<PdfReader> inputs) { // ... (rest of the method) } }
public class PageVerticalAnalyzer : IRenderListener { // ... (rest of the class) public List<float> VerticalFlips = new List<float>(); // ... (rest of the methods) }
public void TestMergeDocuments() { PdfVeryDenseMergeTool tool = new PdfVeryDenseMergeTool(iTextSharp.text.PageSize.A4, 18, 18, 10); List<byte[]> Files = new List<byte[]>(); // ... (code to load files) using (MemoryStream ms = new MemoryStream()) { List<PdfReader> files = new List<PdfReader>(); foreach (byte[] ba in Files) { files.Add(new PdfReader(ba)); } tool.Merge(ms, files); // ... (save the file using ms.GetBuffer()) } }
以上是如何在 C# 中合并 PDF 时消除多余的空格?的详细内容。更多信息请关注PHP中文网其他相关文章!