How to turn the page using Itextsharp

Viewed 58

Ifound some example. However, all of the examples use PdfReader. I want to use PDFWriter.

Below is the code I wrote.

private void CreatePdf(string strPdfPath)
{
    FileStream fs = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
    Document document = new Document(PageSize.A4, 45, 45, 80, 80);
    PdfWriter writer = PdfWriter.GetInstance(document, fs);
    document.Open();
    document.AddTitle("This is Title");
    document.AddCreationDate();
    Paragraph content1 = new Paragraph("This is first Page");
    document.Add(content1);

    document.NewPage();
    Paragraph content2 = new Paragraph("This is second Page");
    document.Add(content2);
    writer.Close();
    fs.Close(); 
}

How to rotate the PDF?

1 Answers

You could do both:

 document.open();
// Add some content in portrait
document.setPageSize(PageSize.A4.rotate());
document.newPage();
// Add some content in landscape
document.close();
Related