2

I have created pdf with wxhmltToPdf library by executing this command:

d:\wkhtmltox\bin\wkhtmltopdf.exe" -T 0 -B 0 -L 0 -R 0 --page-width 96 --page-height 65 --dpi 300  "http://myPage.html" test.pdf

The pdf is created and everything is fine just the problem is that pdf has 2 mm of white space at the bottom. I can't get rid of it, I guess it is a bug in library. Even if content is split on more pages it is 2 mm white space at the bottom of each page (and I set all margins to 0).

So, I would like to open this pdf after it is created, cut 2 mm white space at the bottom(so cut first pdf page to 94 mm height from the top) and save as new pdf. Could be done with C# or cmd.

I thought to use iTextSharp library in c#. I can read pdf and save only first page to new pdf:

PdfReader reader = new PdfReader(Server.MapPath(P_InputStream3));
using (Document document = new Document())
{
    using (PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath(P_OutputStream), FileMode.Create)))
    {
        document.Open();
        PdfContentByte cb = writer.DirectContent;
        PdfImportedPage page = writer.GetImportedPage(reader, 1);

        document.NewPage();
        cb.AddTemplate(page, 0, 0);
        document.Add(new Paragraph(DateTime.Now.ToShortDateString()));
        document.Close();
    }
}

But how can I copy only 94 mm of first page to new pdf?

Simon
  • 1,955
  • 5
  • 35
  • 49
  • 1
    There's a good long [example in this answer](http://stackoverflow.com/a/20212172/231316) as well as a [shorter one here](http://stackoverflow.com/a/28277333/231316) that I'd start with. – Chris Haas Feb 29 '16 at 13:50

0 Answers0