iTextSharp的横向文档 [英] iTextsharp landscape document

查看:1037
本文介绍了iTextSharp的横向文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用iTextSharp的创建PDF风景,但它仍然显示画像。我使用下面的代码与旋转:

I am trying to create Landscape PDF using iTextSharp but It is still showing portrait. I am using following code with rotate:

Document document = new Document(PageSize.A4, 0, 0, 150, 20);
FileStream msReport = new FileStream(Server.MapPath("~/PDFS/") + "Sample1.pdf", FileMode.Create);

try
{
    // creation of the different writers
    PdfWriter writer = PdfWriter.GetInstance(document, msReport);

    document.Open();

    PdfPTable PdfTable = new PdfPTable(1);
    PdfTable.SpacingBefore = 30f;


    PdfPCell PdfPCell = null;

    Font fontCategoryheader = new Font(Font.HELVETICA, 10f, Font.BOLD, Color.BLACK);

    for (int i = 0; i < 20; i++)
    {
        PdfPCell = new PdfPCell(new Phrase(new Chunk("Sales Manager: ", fontCategoryheader)));
        PdfPCell.BorderWidth = 0;
        PdfPCell.HorizontalAlignment = Element.ALIGN_LEFT;

        if (i % 2 == 0)
            PdfPCell.BackgroundColor = Color.LIGHT_GRAY;

        PdfPCell.PaddingBottom = 5f;
        PdfPCell.PaddingLeft = 2f;
        PdfPCell.PaddingTop = 4f;
        PdfPCell.PaddingRight = 4f;
        PdfTable.AddCell(PdfPCell);
    }

    document.Add(PdfTable);
    document.NewPage();

}
catch (Exception ex)
{
    Console.Error.WriteLine(ex.Message);
}

finally
{
    // we close the document 
    document.Close();
}

请提出解决方案。

感谢。

推荐答案

试试这个

Document Doc = new Document(new Rectangle(288f, 144f), 10, 10, 10, 10);
Doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());

您可能还需要这个扩展一个表来最大宽度。

you might also need this to expand a table to max width.

var _pdf_table = new PdfPTable(2); // table with two  columns
PdfPCell hc = new PdfPCell();
_pdf_table.WidthPercentage = 100; //table width to 100per
_pdf_table.SetTotalWidth(new float[] { 25, iTextSharp.text.PageSize.A4.Rotate().Width - 25 });// width of each column

问候。

这篇关于iTextSharp的横向文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆