How to retrieve Crystal page setting programmatically in C#?

早过忘川 提交于 2019-12-24 10:46:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!