【发布时间】:2015-01-29 13:19:31
【问题描述】:
我在使用 iTextSharp 和 C# 时遇到了一个小问题。
上下文: 我下载PDF并将它们合并成一个巨大的。
问题: 在每一页上,前几厘米都是白色的,而我导入的 pdf 在该白色块之后开始。
每一页的结尾都是正确的。没有重叠或丢失的对象/文本 - 您会假设它必须处理更少的空间。我认为它可能会被垂直拉伸。
所以导入工作正常,但它总是在每一页的顶部添加几厘米的白色。 这感觉就像一个最高利润。但我似乎无法修复它。
有什么想法吗?
感谢您的帮助。非常感谢。
public void method()
{
// needed variables for the pdf-merging part
fs = new FileStream(Variables.destinationFile, FileMode.Create);
writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.SetPageSize(PageSize.A4);
doc.SetMargins(0f, 0f, 0f, 0f);
pdfContent = writer.DirectContent;
byte[] result;
int numPages;
foreach (Tuple<string, string, int> currentTuple in someArray)
try
{
result = client.DownloadData(new Uri(adress + currentTuple.Item1 + ".pdf"));
// read and add the pages to the output file
reader = new PdfReader(result);
numPages = reader.NumberOfPages;
for (int i = 1; i < numPages + 1; i++)
{
doc.NewPage();
page = writer.GetImportedPage(reader, i);
pdfContent.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
catch (Exception e)
{
}
}
doc.Close();
writer.Close();
fs.Close();
}
附言为什么它总是删除我的“你好”? :)
【问题讨论】:
标签: c# pdf itextsharp