Page Orientation

6 posts, 1 answers
  1. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 21 Feb 2019 Link to this post

    Hi,

    I need help to setup page orientation to landscape due to size of the contents in cells. 

    Here is my code.

    public RadFlowDocument CreateDocument(ref RadFlowDocument document, List<LetterGenerateData> initltr, string pathlogo)
    {
        RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
        Stream stream = File.Open(pathlogo, FileMode.Open);

        using (stream)
        {
            Telerik.Windows.Documents.Media.ImageSource image = new Telerik.Windows.Documents.Media.ImageSource(stream, "png");
            editor.InsertImageInline(stream, "png", new System.Windows.Size(168, 48));
        }

        var codeFont = new ThemableFontFamily(new System.Windows.Media.FontFamily("Arial"));
        editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
        editor.CharacterFormatting.FontWeight.LocalValue = FontWeights.Bold;
        editor.CharacterFormatting.FontSize.LocalValue = 12.0;
        editor.InsertText("Statement");
        document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
        editor.TableFormatting.StyleId = BuiltInStyleNames.TableGridStyleId;

        var table = editor.InsertTable();
        var headerrow = table.Rows.AddTableRow();
        headerrow.RepeatOnEveryPage = true;
        var hcell1 = headerrow.Cells.AddTableCell();

        hcell1.Blocks.AddParagraph().Inlines.AddRun("Name").FontWeight = FontWeights.Bold;
        var hcell2 = headerrow.Cells.AddTableCell();
        hcell2.Blocks.AddParagraph().Inlines.AddRun("Profession").FontWeight = FontWeights.Bold;
        var hcell3 = headerrow.Cells.AddTableCell();
        hcell3.Blocks.AddParagraph().Inlines.AddRun("Age").FontWeight = FontWeights.Bold;
       
        foreach (var item in initltr)
        {
            var row = table.Rows.AddTableRow();
            var cell1 = row.Cells.AddTableCell();
            var cell2 = row.Cells.AddTableCell();
            var cell3 = row.Cells.AddTableCell();
            cell1.Blocks.AddParagraph().Inlines.AddRun(item.Name).FontSize = 9;
            cell2.Blocks.AddParagraph().Inlines.AddRun(item.Profession).FontSize = 9;
            cell3.Blocks.AddParagraph().Inlines.AddRun(item.Age).FontSize = 9;
        }

        return document;
    }

    Much appreciated.

     

  2. Answer
    Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    176 posts

    Posted 26 Feb 2019 Link to this post

    Hello Khawar,

    The PageOrientation property is part of the Section class. So in order to set the page orientation, you need first to create a section, then rotate it and then add the table in the section. Here you can read more about the Sections at the bottom of the article you will find the information about the section rotation.

    I have updated your code in order to place the table in Section with Landscape orientation.

    RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
    Stream stream = File.Open(pathlogo, FileMode.Open);
     
    using (stream)
    {
        Telerik.Windows.Documents.Media.ImageSource image = new Telerik.Windows.Documents.Media.ImageSource(stream, "png");
        editor.InsertImageInline(stream, "png", new System.Windows.Size(168, 48));
    }
     
    var codeFont = new ThemableFontFamily(new System.Windows.Media.FontFamily("Arial"));
    editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
    editor.CharacterFormatting.FontWeight.LocalValue = FontWeights.Bold;
    editor.CharacterFormatting.FontSize.LocalValue = 12.0;
    editor.InsertText("Statement");
    document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
    editor.TableFormatting.StyleId = BuiltInStyleNames.TableGridStyleId;
     
    var section = editor.InsertSection();
    var table = section.Blocks.AddTable();
    section.Rotate(PageOrientation.Landscape);
    var headerrow = table.Rows.AddTableRow();
    headerrow.RepeatOnEveryPage = true;
    var hcell1 = headerrow.Cells.AddTableCell();
     
    hcell1.Blocks.AddParagraph().Inlines.AddRun("Name").FontWeight = FontWeights.Bold;
    var hcell2 = headerrow.Cells.AddTableCell();
    hcell2.Blocks.AddParagraph().Inlines.AddRun("Profession").FontWeight = FontWeights.Bold;
    var hcell3 = headerrow.Cells.AddTableCell();
    hcell3.Blocks.AddParagraph().Inlines.AddRun("Age").FontWeight = FontWeights.Bold;
     
    foreach (var item in initltr)
    {
        var row = table.Rows.AddTableRow();
        var cell1 = row.Cells.AddTableCell();
        var cell2 = row.Cells.AddTableCell();
        var cell3 = row.Cells.AddTableCell();
        cell1.Blocks.AddParagraph().Inlines.AddRun(item.Name).FontSize = 9;
        cell2.Blocks.AddParagraph().Inlines.AddRun(item.Profession).FontSize = 9;
        cell3.Blocks.AddParagraph().Inlines.AddRun(item.Age).FontSize = 9;
    }
     
    return document;

    I hope I was able to help.

    Regards,
    Nikolay Demirev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 20 Nov 2019 in reply to Nikolay Demirev Link to this post

    Hi,

    I have a question, Is there any possibility to print or view landscape in portrait layout? I mean same as landscape but sideways in portrait orientation. Contents on the landscape view should appear in sideways with portrait orientation. Reason for this question, is a requirement from business to preview all page in portrait manner so that there isn't any landscape page in portrait view. 

    Your help is greatly appreciated.

  4. Dimitar
    Admin
    Dimitar avatar
    2838 posts

    Posted 25 Nov 2019 Link to this post

    Hi Khawar,

    If I understand correctly you want to rotate the page contents as well, this way you will have a portrait page with a (vertical) landscape content. Am I correct? I am afraid that this is not possible and the Document Processing library does not contain any API for this. Which control are you using for the Print Preview (perhaps this is possible with the UI controls)?

    I am looking forward to your reply.

    Regards,
    Dimitar
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Khawar
    Khawar avatar
    12 posts
    Member since:
    Jan 2018

    Posted 25 Nov 2019 in reply to Dimitar Link to this post

    Hi Dimitar, 

    You are absolutely right. I just need to rotate the contents and save in a PDF format. I m using RadFlowDocument API for this purpose. If you have any possible solution then please let me know. your help is greatly appreciated.

    Thanks!

  6. Dimitar
    Admin
    Dimitar avatar
    2838 posts

    Posted 26 Nov 2019 Link to this post

    Hello Khawar,

    If you are using a PDF you can rotate the page after the document is exported. You will need to convert the document to RadFixedDocumet. Here is an example:

    var flowProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
    var doc = flowProvider.Export(document);
    
    var fixedProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
    var fixedDocument = fixedProvider.Import(doc);
    
    fixedDocument.Pages[1].Rotation = Telerik.Windows.Documents.Fixed.Model.Data.Rotation.Rotate90;
    
    using (FileStream fs = new FileStream(@"D:\rotated.pdf", FileMode.OpenOrCreate))
    {
        fixedProvider.Export(fixedDocument, fs);
    }
    

    Let me know how this works for you.

    Regards,
    Dimitar
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top