We help IT Professionals succeed at work.

landscape

1jaws
1jaws asked
on
1,617 Views
Last Modified: 2012-05-09
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

Comment
Watch Question

Shahan AyyubStaff Software Engineer
CERTIFIED EXPERT

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

Author

Commented:
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?)      
Shahan AyyubStaff Software Engineer
CERTIFIED EXPERT

Commented:

Author

Commented:
didnt help me no. :((
Shahan AyyubStaff Software Engineer
CERTIFIED EXPERT

Commented:
What did you get from the link??

Author

Commented:
didnt make the landscape oritentaion.. no error though..
Staff Software Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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?

Author

Commented:
You know what I just discovered that because it is Document.NewPage();
  my title is not showing..!!
Shahan AyyubStaff Software Engineer
CERTIFIED EXPERT

Commented:
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.
 
 

Author

Commented:
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

Author

Commented:
I got it worked!!!  
Shahan AyyubStaff Software Engineer
CERTIFIED EXPERT

Commented:
Okay what did you do ??

Author

Commented:
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/Programming/Languages/C_Sharp/Q_26322308.html

Author

Commented:
and do you have slight idea about this question
https://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26322278.html 

if you like to look at it??

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.