I have a document开发者_JAVA技巧 in iTextSharp. I want to set the default 'pagesize' to 'A4', but here we have special pages that needed to be rotated (just these pages) using A4.Rotate()
.
document.setpagesize(A4.Rotate())
for the pages to be rotated.
I'm sorry for my bad english.
Here's an example. It creates a PDF file with 4 pages. Page 1,2 and 4 use A4 portrait mode while page 3 uses A4 landscape mode:
class Program
{
static void Main(string[] args)
{
Document doc = new Document(PageSize.A4);
using (var stream = new FileStream("test.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
var writer = PdfWriter.GetInstance(doc, stream);
doc.Open();
doc.NewPage();
doc.Add(new Paragraph("Page1 (portrait A4)"));
doc.NewPage();
doc.Add(new Paragraph("Page2 (portrait A4)"));
// Set page size before calling NewPage
doc.SetPageSize(PageSize.A4.Rotate());
doc.NewPage();
doc.Add(new Paragraph("Page3 (landscape A4)"));
// Revert to the original page size before adding new pages
doc.SetPageSize(PageSize.A4);
doc.NewPage();
doc.Add(new Paragraph("Page4 (portrait A4)"));
doc.Close();
}
}
精彩评论