I have a small Problem using iTextSharp
and C#.
Context: I download PDFs and merge them into one huge.
Problem: On every page the first couple centimeters are just White and the pdf I Import starts after that White chunk.
The end of every page is correct. There is no overlapping or missing objects/text - which you would assume since it has to deal with less space. I think it might get stretched vertically.
So the Import works fine, but it always adds a few centrimeters of White on the top of every page. It feels like a top-margin. But I can't seem to fix it.
Any ideas?
I appreciate your help. Thanks a lot.
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();
}
p.s. why does it always delete my "hi there"? :)