I am using iTextSharp to create a List<PdfReader> _documents
with several PDF documents.
After using merge on this list to create single paged document and send it to the client I see that the PDF looks cut in Adobe Reader.
When I highlight the picture like this I can see it s there :
""https://i.sstatic.net/5rRXe.jpg" alt="此处输入图像描述"/ >
如果我拯救它,它就完全实现。
如果我将 PdfReader
中的一个保存在单PDF文档列表中,而不合并,看起来不错。
""https://i.sstatic.net/7lZsF.jpg" alt="此处的内置图像描述"/ >
合并函数为 :
public void Merge(Stream outputStream)
{
Document newDocument = null;
try
{
newDocument = new Document();
// Set margins and page size for the document
newDocument.SetMargins(50, 50, 50, 50);
// There are a huge number of possible page sizes, including such sizes as
// EXECUTIVE, LEGAL, LETTER_LANDSCAPE, and NOTE
newDocument.SetPageSize(PageSize.A3 );
PdfWriter pdfWriter = PdfWriter.GetInstance(newDocument, outputStream);
newDocument.Open();
PdfContentByte pdfContentByte = pdfWriter.DirectContent;
if (EnablePagination)
{
_documents.ForEach(delegate(PdfReader doc)
{
_totalPages += doc.NumberOfPages;
});
}
int currentPage = 1;
foreach (PdfReader pdfReader in _documents)
{
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
newDocument.NewPage();
PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, page);
pdfContentByte.AddTemplate(importedPage, 0, 0);
if (EnablePagination)
{
pdfContentByte.BeginText();
pdfContentByte.SetFontAndSize(_baseFont, 9);
pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER,
string.Format("{0} of {1}", currentPage++, _totalPages), 520, 5, 0);
pdfContentByte.EndText();
}
}
}
}
finally
{
outputStream.Flush();
if (newDocument != null)
newDocument.Close();
outputStream.Close();
}
}
I suspect it has something to do with newDocument.SetPageSize(PageSize.A3);
but I am not sure and so far I can t find the solution.