Link to home
Start Free TrialLog in
Avatar of 1jaws
1jawsFlag for United States of America

asked on

landscape

Using iTextSharp...I am trying do like this to make it landscape oriteantion it is not working..
Document doc = new Document(iTextSharp.text.PageSize.LETTER.Rotate);

Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

       

                doc.Open();

        iTextSharp.text.Rectangle page = doc.PageSize;

Open in new window

Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Could you please try like this:
iTextSharp.text.pdf.PdfPage page =  iTextSharp.text.pdf.PdfPage.LANDSCAPE;
instead of:
       iTextSharp.text.Rectangle page = doc.PageSize;

Avatar of 1jaws

ASKER

Error      1      Cannot implicitly convert type 'iTextSharp.text.pdf.PdfNumber' to 'iTextSharp.text.pdf.PdfPage'      

also I am setting to height and weight... it is complain that too when I take out that line..
Error      2      'iTextSharp.text.pdf.PdfPage' does not contain a definition for 'Width' and no extension method 'Width' accepting a first argument of type 'iTextSharp.text.pdf.PdfPage' could be found (are you missing a using directive or an assembly reference?)      
Avatar of 1jaws

ASKER

didnt help me no. :((
What did you get from the link??
Avatar of 1jaws

ASKER

didnt make the landscape oritentaion.. no error though..
ASKER CERTIFIED SOLUTION
Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1jaws

ASKER

you did it!! it worked..!! thank you so much!!. I am going to ask more question about this shortly.. if you want to take a look?
Avatar of 1jaws

ASKER

You know what I just discovered that because it is Document.NewPage();
  my title is not showing..!!
If you will visit the link you will see the use of:
Document.SetPageSize(PageSize.A4.Rotate());
before:  
Document.NewPage();
We need to rotate the page first and then declare that page. So,Once page is created rotation won't work as described in the link that will giv error.  
I was thinking from your title's point of view so the referenec i posted you didn't work. then I work on general page rotation and I found the helpful article.
 
 
Avatar of 1jaws

ASKER

depending on where I put that code it changes... the way I am sending you now will put it first page empty only shows date displays..than second page it shows my title and the table fine...
but I want to see those on the first page not second...
Document doc = new Document();
       
        PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
        Phrase phrase = new iTextSharp.text.Phrase(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + " GMT", new iTextSharp.text.Font(iTextSharp.text.Font.COURIER, 5));

        doc.Open();     

        iTextSharp.text.Rectangle page = doc.PageSize;       
       
       

        PdfPTable head = new PdfPTable(1);
        head.TotalWidth = page.Width;

        PdfPCell c = new PdfPCell(phrase);
              
        c.Border = iTextSharp.text.Rectangle.NO_BORDER;
        c.VerticalAlignment = Element.ALIGN_TOP;
        c.HorizontalAlignment = Element.ALIGN_CENTER;
       
        head.AddCell(c);
        head.WriteSelectedRows(
            // first/last row; -1 writes all rows
          0, -1,
            // left offset
          0,
            // ** bottom** yPos of the table
          page.Height - doc.TopMargin + head.TotalHeight + 20,
          writer.DirectContent);
        doc.SetPageSize(PageSize.A4.Rotate());
        doc.NewPage(); 
        // add image to document
        iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Request.MapPath("~/GF2images/ogoPDF.jpg"));
        
        logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
        logo.ScalePercent(60f);
        doc.Add(logo);

        // report "title"
        Paragraph p = new Paragraph("Test Title", new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 10f, iTextSharp.text.Font.BOLD));
        p.Alignment = 1;
        doc.Add(p);

        
        // add tabular data
       
        doc.Add(my_table());
        doc.Close();

Open in new window

Avatar of 1jaws

ASKER

I got it worked!!!  
Okay what did you do ??
Avatar of 1jaws

ASKER

go ahead and paste that answer you provided this one. to here if youlike  I will give you points because you have it got it worked for me...
https://www.experts-exchange.com/questions/26322308/header-text-not-showing.html
Avatar of 1jaws

ASKER

and do you have slight idea about this question
https://www.experts-exchange.com/questions/26322278/add-textbox-to-pdf.html 

if you like to look at it??
Avatar of 1jaws

ASKER

I kept putting the code you gave me anywehere I can and test it accordingly...