How to retrieve Crystal page setting programmatica

2019-08-01 07:33发布

I created a Crystal report (.rpt file) in Crystal Designer. I configured Page Setup. I want to retrieve e.g. page orientation, page width, page high programmatically in C#. How to do it? Note that I want to retrieve page settings, no print settings. I don't want to edit page settings, I only need to read it.

===EDIT===

Following figure shows my page setup:

enter image description here

PrintOptions.PageContentWidth and PrintOptions.PageContentHeight in C# have different values.

ReportDocument rp = new ReportDocument();
rp.Load(path_to_my_report_file);
Console.WriteLine(rp.PrintOptions.PageContentHeight);
Console.WriteLine(rp.PrintOptions.PageContentWidth);

Output:

5670
8505

I need to retrieve page width and height to set they in PaperSize (myPaperSize = new System.Drawing.Printing.PaperSize(name, width, height);)

1条回答
甜甜的少女心
2楼-- · 2019-08-01 08:01

ReportDocument.PrintOptions should give you the numbers that you need. For example, for the page width, using members of PrintOptions:

PageContentWidth + PageMargins.leftMargin + PageMargins.rightMargin

However, these values are in TWIPS, where 1440 twips = 1 inch. (I have no idea what the proper capitalization is...)


On the other hand, System.Drawing.Printing.PaperSize uses numbers in hundredths of an inch, so you would have to convert:

[Dimension in hundredths of an inch] = [Dimension in TWIPS] / 1440.0 * 100
查看更多
登录 后发表回答