问题
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:

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:
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
来源:https://stackoverflow.com/questions/29848804/how-to-retrieve-crystal-page-setting-programmatically-in-c