我遇到了为客户打印文档的程序有问题。原始文件包含8.5x11格局的页面。我需要打印成11x17小册子。
我可以生成页面 - 大多数顺序正确 - 但我会翻页。
当我需要在输出文档中添加额外的空白页面时,我认为我遇到了问题,所以我从多个PAGES中获得了偶数个SHEETS,这些页面小于每张页面以满足SHEET要求。
4页= 1张。 17页= 4张+ 1页。我需要输出5张纸,第一页和最后一页在SHEET 1的同一侧,
我只需要一点点推动就可以正确地获取数据。
客户端发送一个包含17(或18,22,27)页的文件。我需要确定中间页面位于中间,第一页和最后一页位于外页封面上。
using (PdfReader pdfReader = new PdfReader(rec.DirName + @"\" + rec.FileName + ".pdf"))
using (Document document = new Document(new Rectangle(792, 1224)))
using (PdfWriter pdfWriter = PdfWriter.GetInstance(document,
new FileStream(outputPath + rec.SequenceNumber.ToString("D5") + "_" + outFname[0] + "_" + outFname[1] + ".pdf",
FileMode.Create)))
{
int lastPage = 0;
pdfWriter.CloseStream = false;
document.Open();
var content = pdfWriter.DirectContent;
// Determine the last page and ensure there is an even amount.
if (rec.PageCount > 8 && rec.PageCount <= 12) // pages 9, 10, 11, and 12
{
lastPage = 12;
++_3SheetCount;
}
else if (rec.PageCount > 12 && rec.PageCount <= 16) // pages 13, 14, 15, and 16
{
lastPage = 16;
++_4SheetCount;
}
else if (rec.PageCount > 16 && rec.PageCount <= 20) // pages 17, 18, 19, and 20
{
lastPage = 20;
++_5SheetCount;
}
else if (rec.PageCount > 20 && rec.PageCount <= 24) // pages 21, 22, 23, and 24
{
lastPage = 24;
++_6SheetCount;
}
else if (rec.PageCount > 24 && rec.PageCount <= 28) // pages 25, 26, 27, and 28
{
lastPage = 28;
++_7SheetCount;
}
else if (rec.PageCount >28 && rec.PageCount <=32) // pages 29, 30, 31, and 32
{
lastPage = 32;
++_8SheetCount;
}
// Iterate to the middle sheet.
// Count up from the first page and down from the last page
for (int i = 1, j = lastPage; i <= lastPage / 2; i++, j--)
{
// Front side layout is: | J | I |
// Back side layout is: | I | J |
int iy = (i % 2 == 1) ? 0 : 612;
int jy = (i % 2 == 1) ? 612 : 0;
document.NewPage();
// Add the I page.
content.AddTemplate(pdfWriter.GetImportedPage(pdfReader, i), 0, iy);
// process address block, IMB and 2D
#region Address, 2D, IMB and Permit
if (i == 1)
{
// print mailing address information here
}
#endregion
// if the J page does not exist in the original PDF then leave it blank.
if (j <= pdfReader.NumberOfPages)
content.AddTemplate(pdfWriter.GetImportedPage(pdfReader, j), 0, jy);
++sheetCountTotal;
}
document.Close();
pdfWriter.Close();
}