This is a migrated thread and some comments may be shown as answers.

Change orientation of one page

5 Answers 268 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 04 Jul 2012, 11:46 PM
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

5 Answers, 1 is accepted

Sort by
0
Mi
Top achievements
Rank 1
answered on 05 Jul 2012, 08:56 AM
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

0
Martin Ivanov
Telerik team
answered on 05 Jul 2012, 08:59 AM
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 >>

0
Robert
Top achievements
Rank 1
answered on 09 Jul 2012, 11:17 PM
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
0
Accepted
Iva Toteva
Telerik team
answered on 12 Jul 2012, 03:54 PM
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 >>

0
Robert
Top achievements
Rank 1
answered on 13 Jul 2012, 12:41 AM
Thanks Iva, it works a treat!
Yet again, you solve my problems.

All the best,

Rob
Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Mi
Top achievements
Rank 1
Martin Ivanov
Telerik team
Robert
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or