Declined
Last Updated: 15 Sep 2021 09:53 by KKL
KKL
Created on: 20 Jun 2021 09:33
Category: RichTextEditor
Type: Bug Report
1
RadRichTextEditor: Horizontal centering on page not working correctly

When I have an InlineImage in a horizontally centered paragraph, PrintPreview presents the image unevenly on the page. There should be the same space on left and right, as the page padding is the same all around. See the arrows indicated below:


4 comments
KKL
Posted on: 15 Sep 2021 09:53
Thank you for this - that fixed the problem!
KKL
Posted on: 08 Sep 2021 09:10
Thank you - this works!
ADMIN
Dimitar
Posted on: 06 Sep 2021 14:04

Hello,

The problem lies in the difference between the size of A4 that System.Drawing.Printing.PrinterSettings returns and the one that Telerik.WinForms.Documents.Model.PaperTypeConverter.ToSize(PaperTypes.A4) returns. The first one returns a non-ISO size for A4 - Height=1169 Width=827, where as we are returning Height=1123 Width=793, which is a standard ISO size for A4 at 96 DPI. It seems that System.Drawing.Printing.PrinterSettings is returning the size at 100 DPI, which leads to the difference. 

In this case, the paper size in RadPrintDocument is set to the size of PrinterSettings:
    
var ps = new PrinterSettings();
var sizeA4 = ps.PaperSizes.Cast<PaperSize>().First(size => size.Kind == PaperKind.A4);
var printDocumentSettings = new RadPrintDocument();
if (sizeA4 != null) printDocumentSettings.DefaultPageSettings.PaperSize = sizeA4;

Afterward setting  the page size to the A4 that we return:
lbsection.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);

And uses that size to calculate the size of the image:
  
var imageSize = ResizeKeepAspect(pictureBox1.Image.Size, (int)lbsection.PageSize.Height - 40, (int)lbsection.PageSize.Width - 40);
This difference in the two sizes leads to the supposed Margin problem.

Workaround:
You can use the same size - either the one that comes from System.Drawing.Printing.PrinterSettings or ours.
Use System.Drawing.Printing.PrinterSettings for the PageSize:
var ps = new PrinterSettings();
var sizeA4 = ps.PaperSizes.Cast<PaperSize>().First(size => size.Kind == PaperKind.A4);
   ...
lbsection.PageSize = new Telerik.WinControls.RichTextEditor.UI.Size(sizeA4.Width, sizeA4.Height);
---OR---

Use Telerik.WinForms.Documents.Model.PaperTypeConverter.ToSize(PaperTypes.A4) for the Paper Size: 
var sizeA4 = PaperTypeConverter.ToSize(PaperTypes.A4);
printDocumentSettings.DefaultPageSettings.PaperSize = new PaperSize("Custom Paper Size A4", (int)sizeA4.Width, (int)sizeA4.Height);

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ADMIN
Nadya | Tech Support Engineer
Posted on: 21 Jun 2021 15:28

Hello, Kevin,

Thank you for the provided project. I was able to observe the same undesired behavior with the image alignment. I have logged this on our feedback portal by making this thread public. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik Points.

Currently, due to the specifics of the issue, I am not able to suggest a workaround. Please excuse us for the inconvenience caused. 

I hope this helps. If you have any other questions please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.