我有一些代码需要3个不同的PDF字节数组并将其合并。这段代码很棒。(某些人)遇到的问题是,即使PDF仅包含4英寸的内容,每个PDF仍被视为整页(如果打印的话),因此垂直留有7英寸的空白。然后,中间文档被放入,并且末尾可能有也可能没有垂直空白。然后,页脚也会放在自己的页面上。
这是代码:
byte[] Bytes = rv.LocalReport.Render("PDF", null, out MimeType, out Encoding, out Extension, out StreamIDs, out Warnings);
List<byte[]> MergeSets = // This is filled prior to this code
// Append any other pages to this primary letter
if (MergeSets.Count > 0) {
MemoryStream ms = new MemoryStream();
Document document = new Document();
PdfCopy copy = new PdfCopy(document, ms);
document.Open();
PdfImportedPage page;
PdfReader reader = new PdfReader(Bytes); // read the generated primary Letter
int pages = reader.NumberOfPages;
for (int i = 0; i < pages; ) {
page = copy.GetImportedPage(reader, ++i);
copy.AddPage(page);
} // foreach of the pages in the Cover Letter
// Now append the merge sets
foreach (byte[] ba in MergeSets) {
reader = new PdfReader(ba);
pages = reader.NumberOfPages;
for (int i = 0; i < pages; ) {
page = copy.GetImportedPage(reader, ++i);
copy.AddPage(page);
} // foreach of the pages in the current merge set
} // foreach of the sets of data
document.Close();
ServerSaved = SaveGeneratedLetter(ms.GetBuffer(), DateTime.Now.Year, hl.LetterName, SaveName);
} // if there is anything to merge
当我合并每个页面以剪切/删除/擦除每个pdf末尾的垂直空白时,有没有一种方法可以使它显示为一个无缝文档?
茅侃侃
跃然一笑
相关分类