2012-04-06 23 views
16

Estoy tratando de crear Landscape PDF utilizando iTextSharp pero aún se muestra el retrato. Estoy utilizando el siguiente código con rotar:iTextsharp landscape document

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(); 
} 

Por favor, sugiera la solución.

Gracias.

+0

se puede comprobar con rectángulo pageSize = new Rectángulo (150, 20); Documento de documento = nuevo documento (tamaño de página); – Vinay

+0

Verifique la pregunta ya respondida, puede obtener la pista que necesita http://stackoverflow.com/questions/2370427/itextsharp-set-a-document-horizontal-page-a4 –

Respuesta

30

probar este

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

también podría ser necesario ampliar esto a una tabla de anchura máxima.

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 

Saludos.

+0

Hola Shoaib, No, sigue mostrando el mismo tamaño . Con el paisaje, ¿el ancho será mayor que la altura o la dirección del texto se volverá de arriba a abajo o de abajo hacia arriba? – DotnetSparrow

+0

ancho se vuelven más grandes .. no girará el contenido –

+0

código de verificación que acabo de agregar. Por cierto código que compartí está usando itextsharp 4.1 –

3

No hay necesidad de inicializar el documento y restablecer el tamaño de página ...

Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10); 

... hará el truco.

(4.1.6.0)