landscape orientation

0 Answers 22 Views
PdfProcessing
Alexandre
Top achievements
Rank 1
Alexandre asked on 11 May 2022, 03:02 PM

I need pdf landscape orientation.

I export document, then change size:

pdf = pdfFlowProvider.ExportToFixedDocument(doc);
pdf.Pages[0].Size = new Size(1056, 816);

Problem that I have lot of space on the right side, probably because I exported document first.

But I can't change page size before this, because I don't have pages.

How to fix this?

Svilen
Telerik team
commented on 12 May 2022, 12:25 PM

Hey, Alexandre,

I'd be happy to help here.

Since I know you already discovered the use of RadFixedPage's Rotation property, I assume this case is a bit different. In order for me to best assist, I would need to better understand the specific case you are facing.

Do you mind sharing some more details on your goal and screenshots of the space on the right you mentioned? Additionally, if you are able to share a small example project, which compiles, I could see the context of the snippet you sent. 

I stand by for your input, ready to help.

Regards,
Svilen
Progress Telerik

Alexandre
Top achievements
Rank 1
commented on 12 May 2022, 01:36 PM | edited

Hi Svilen,

I can share code:

var htmlDocument = new HtmlFormatProvider();
string html = File.ReadAllText("test.html");
var doc = htmlDocument.Import(html);
var pdfFixedProvider = new PdfFormatProvider();
var pdfFlowProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
var pdffixed = pdfFlowProvider.ExportToFixedDocument(doc);
pdffixed.Pages[0].Size = new Size(1056, 816);                
var settings = new PdfExportSettings
    {
        ComplianceLevel = PdfComplianceLevel.PdfA1B
     };
pdfFixedProvider.ExportSettings = settings;

var result = pdfFixedProvider.Export(pdffixed);
File.WriteAllBytes("test.pdf", result);

Please see attached project.

Svilen
Telerik team
commented on 16 May 2022, 11:25 AM

Hey, Alexandre,

Thank you for sharing your code.

You need to change the page orientation on the RadFlowDocument before exporting it to a PDF file. Here is how to do so:

var doc = htmlDocument.Import(html);

foreach (var section in doc.Sections) { section.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape; }

Please let me know if this helps.

Regards,
Svilen

Progress Telerik

Alexandre
Top achievements
Rank 1
commented on 16 May 2022, 01:07 PM

no, result is the same.

Because we do change orientation after importing html.

And we can't do it before because sections don't exist yet.

If we could specify orientation when we create RadFlowDocument it could probably solve the problem.

But we can't?

Alexandre
Top achievements
Rank 1
commented on 16 May 2022, 02:48 PM | edited

but actually PageOrientaion for RadFlowDocument doesn't work at all.

I tried the following code, without converting RadFlowDocument to RadFixedDocumet (we need RadFixedDocumet because PdfComplience).

This code doesn't change orientation:

var htmlDocument = new HtmlFormatProvider(); string html = File.ReadAllText("Form.html"); var doc = htmlDocument.Import(html); foreach (var section in doc.Sections) { section.PageOrientation = PageOrientation.Landscape; } var pdfFlowProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider(); using (Stream output = File.OpenWrite("result.pdf")) { pdfFlowProvider.Export(doc, output); }

Svilen
Telerik team
commented on 17 May 2022, 01:00 PM

Hello, Alexandre,

Please accept my apologies for misleading you. 

The proper way to rotate a section's page orientation is the following:

section.Rotate(PageOrientation.Landscape); // The parameter is the orientation you want the section to have

Our help article also states that the Section.PageOrientation property is used to determine the size of the paper to use when printed with a printer and does not reflect the document's visualization. Alas, those did not prevent me from making this mistake myself. I apologize once more.

We have a public feedback item for implementing a more straightforward API for doing this here: WordsProcessing: Introduce more convenient API for setting a Section's page orientation. Please note that as mentioned in the link, the Rotate() method is useful only for rotating already created sections, and to create a section with specified page size and margins the user should set all Section's PageSize, PageMargin, and PageOrientation properties. If you agree with this suggestion you can upvote the public item and you will be notified when the feature is complete.

Regards,
Svilen
Progress Telerik

Alexandre
Top achievements
Rank 1
commented on 17 May 2022, 01:20 PM

Thank you, it works!

Question: should I remove the following line:

pdffixed.Pages[0].Size = new Size(1056, 816);     
because it looks like it works without it.
Svilen
Telerik team
commented on 17 May 2022, 03:45 PM

Hey, Alexandre,

Yes, you can remove it. The Rotate() method takes care of the PageSize and PageMargin properties.

Regards,
Svilen
Progress Telerik

No answers yet. Maybe you can help?

Tags
PdfProcessing
Asked by
Alexandre
Top achievements
Rank 1
Share this question
or