Change orientation of one page

6 posts, 1 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 04 Jul 2012 Link to this post

    Hi,

    Is it possible to change the orientation of just one of the pages in a document or must all pages be arranged with the same orientation?

    Thanks,

    Rob
  2. Mi
    Mi avatar
    16 posts
    Member since:
    Apr 2011

    Posted 05 Jul 2012 Link to this post

    Hi Rob,

    it should be possible.

    Normally the default orientation is set via the SectionDefaultPageOrtientation property of the RadDocument object. But you can set the PageOrientation property of the current section.

    In Code it looks something like this:

    var newSection = new Telerik.Windows.Documents.Model.Section ();
    doc.Sections.Add (newSection);
    newSection.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape;

    But I don't know how the RadRichTextBox-Control handles this.

    Hope this helps.

    Mike

  3. UI for WPF is Visual Studio 2017 Ready
  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 05 Jul 2012 Link to this post

    Hello Robert,

    PageOrientation is a property of the document element Section. You can read more about how different sections can be added to the document in this article.

    When it comes to the page orientation, you can use the PageOrientation property of the section directly, if you are creating the document in code-behind, or the ChangePageOrientationCommand otherwise. The command alters the current section's settings.

    Therefore, if you split your document into multiple sections you can use the UI or the API to change the orientation of the currently selected sections or  the single section where the caret is positioned at.

    this.radRichTextBox.ChangeSectionPageOrientation(PageOrientation.Landscape);

    Don't hesitate to contact us if you have other questions.

    Kind regards,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 09 Jul 2012 Link to this post

    Hmm, I can't seem to get it to work.

    My application imports several template documents and merge them together. Some template documents have been saved as Landscape and others as Portrait. However, when importing the documents they all resort to the same orientation.

    I need to some way to merge documents of differing orientation, and for the orientation of each page to stay as they were originally intended.

    I've attached an image of what my document looks like after all templates have been merged. Note in the image that the page titled "Extras Pricing" should be Landscape. The template this page is drawn from is landscape, but it's importing as portrait.

    Here's my import document code / loop.

    public PrintPreviewWindow(RadDocument document, List<Customer> customerDetails, TemplatePrintingGroupTypes printGroup)
    {
        InitializeComponent();
     
        //Download Template Documents
        ObservableCollection<PrintPriviewDocumentTemplate> printTemplates = GetDocumentTemplates(printGroup.ID);
     
        //Spec Document
        RadDocument documentSpec = (RadDocument)document.CreateDeepCopy();
     
        //Loop count for templates.
        int count = 0;
     
        //Loop through Downloaded Document Templates and add RTB
        foreach (PrintPriviewDocumentTemplate item in printTemplates)
        {
            //Convert DB Document into RadDocument (exclude spec document)
            RadDocument docTemplate = new RadDocument();
            if (item.TemplateID == 9)
            {
                docTemplate = documentSpec;
            }
            else
            {
                docTemplate = Import.ImportXAMLString(item.Document);
            }
     
            //Set Document MailMerge Data Source
            docTemplate.MailMergeDataSource.ItemsSource = customerDetails;
            docTemplate.ChangeAllFieldsDisplayMode(FieldDisplayMode.Result);
     
            //Merge Template Document with current document
            this.radRichTextBox.Document.CaretPosition.MoveToFirstPositionInDocument();
     
            if (count == 0)
            {
                this.radRichTextBox.Document = docTemplate;
            }
            else
            {
                this.radRichTextBox.Document.InsertFragment(new DocumentFragment(docTemplate));
                this.radRichTextBox.Document.InsertInline(new Span(FormattingSymbolLayoutBox.PAGE_BREAK));
     
                this.radRichTextBox.Document.CaretPosition.MoveToFirstPositionInDocument();
            }
     
            count++;
        }
    }

    Thanks for your help,

    Rob
  6. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 12 Jul 2012 Link to this post

    Hello Rob,

    Overall, it is not quite clear which page settings should be applied on copy/paste. For example, if you copy a page in Landscape mode and paste it in a Portrait-orientation page, what behavior would you expect?

    This is one of the reasons why the page size and page orientation of the last section in the document are not copied. In the case when there is only one section in the document, that means that the page size and orientation are not copied at all.

    In your case, when you merge documents, instead of inserting a page break, you could insert a section break between them and copy the page size and orientation of all sections in the following way:

    this.radRichTextBox.InsertSectionBreak();
     
    this.radRichTextBox.InsertFragment(new DocumentFragment(docTemplate));
    this.radRichTextBox.ChangeSectionPageSize(docTemplate.Sections.Last.PageSize);
    this.radRichTextBox.ChangeSectionPageOrientation(docTemplate.Sections.Last.PageOrientation);
    this.radRichTextBox.MoveToFirstPositionInDocument();

    I hope this helps.


    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  7. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 12 Jul 2012 Link to this post

    Thanks Iva, it works a treat!
    Yet again, you solve my problems.

    All the best,

    Rob
Back to Top
UI for WPF is Visual Studio 2017 Ready