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

Page Orientation

5 Answers 924 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Khawar
Top achievements
Rank 1
Khawar asked on 21 Feb 2019, 04:46 PM

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.

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 26 Feb 2019, 09:15 AM
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.
0
Khawar
Top achievements
Rank 1
answered on 20 Nov 2019, 04:35 PM

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.

0
Dimitar
Telerik team
answered on 25 Nov 2019, 12:26 PM

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.
0
Khawar
Top achievements
Rank 1
answered on 25 Nov 2019, 12:56 PM

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!

0
Dimitar
Telerik team
answered on 26 Nov 2019, 06:27 AM

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.
Tags
WordsProcessing
Asked by
Khawar
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Khawar
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or