Symptom
When previewing a report, the defined left margin is shown. When printing this preview to printer (for example Microsoft Print to PDF) or Previewing in the WinForm Viewer this left margin does not use the Conditional formula specified for the Margin in Page Setup.
Environment
Crystal Reports, Developer for Visual Studio ( all SP's)
Resolution
I am checking with R&D, the Formatting formula shoudl be read at runtime without haveing to check for it specifically.
If They agree to fix this it should be out in SP 23.
In the mean time use this to get the values and add to the defualt value.
To resolve this problem you must test for the Formatting formula in code.
To see how this works go to this page and download my printer test app:
https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads
Printing Crystal Reports in .NET - https://blogs.sap.com/2015/08/19/printing-crystal-reports-in-net/
Then in this section look for this part:
private void getPrinterInfoOnOpen(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)
And update it with this code:
// show margins
// values are saved in TWIPS in the RPT file
if (isMetric == 567)
isMetricTwips = 0.0017639;
else
isMetricTwips = 1440;
CrystalDecisions.ReportAppServer.ReportDefModel.PageMarginConditionFormulas PMargCondFormula = new PageMarginConditionFormulas();
CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins pMargins = new CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins();
double CRLeftInt = (rptPRT.PageMargins.Left * isMetricTwips);
if (rptPRT.PageMargins.PageMarginConditionFormulas.Count > 0)
{
try
{
string OffSetString = rptPRT.PageMargins.PageMarginConditionFormulas[CrPageMarginConditionFormulaTypeEnum.crPageMarginConditionFormulaTypeLeft].Text.ToString();
// // This formula must return a number in twip units.
int MyENUM = OffSetString.Length - 51;
string MySTRTemp = OffSetString.Substring(51, MyENUM);
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM);
CRLeft.Text = string.Format("{0:0.000}", (CRLeftInt + (MyENUM / 1440)));
}
catch
{ // if there is no formula catch the exception
CRLeft.Text = string.Format("{0:0.000}", CRLeftInt);
}
}
else
CRLeft.Text = string.Format("{0:0.000}", CRLeftInt);
double CRRightInt = (rptPRT.PageMargins.Right * isMetricTwips);
if (rptPRT.PageMargins.PageMarginConditionFormulas.Count > 0)
{
try
{
string OffSetString = rptPRT.PageMargins.PageMarginConditionFormulas[CrPageMarginConditionFormulaTypeEnum.crPageMarginConditionFormulaTypeRight].Text.ToString();
// // This formula must return a number in twip units.
int MyENUM = OffSetString.Length - 51;
string MySTRTemp = OffSetString.Substring(51, MyENUM);
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM);
CRRight.Text = string.Format("{0:0.000}", (CRRightInt + (MyENUM / 1440)));
}
catch
{ // if there is no formula catch the exception
CRRight.Text = string.Format("{0:0.000}", CRRightInt);
}
}
else
CRRight.Text = string.Format("{0:0.000}", CRRightInt);
double CRTopInt = (rptPRT.PageMargins.Top * isMetricTwips);
if (rptPRT.PageMargins.PageMarginConditionFormulas.Count > 0)
{
try
{
string OffSetString = rptPRT.PageMargins.PageMarginConditionFormulas[CrPageMarginConditionFormulaTypeEnum.crPageMarginConditionFormulaTypeTop].Text.ToString();
// // This formula must return a number in twip units.
int MyENUM = OffSetString.Length - 51;
string MySTRTemp = OffSetString.Substring(51, MyENUM);
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM);
CRTop.Text = string.Format("{0:0.000}", (CRTopInt + (MyENUM / 1440)));
}
catch
{ // if there is no formula catch the exception
CRTop.Text = string.Format("{0:0.000}", CRTopInt);
}
}
else
CRTop.Text = string.Format("{0:0.000}", CRTopInt);
double CRBottomInt = (rptPRT.PageMargins.Bottom * isMetricTwips);
if (rptPRT.PageMargins.PageMarginConditionFormulas.Count > 0)
{
try
{
string OffSetString = rptPRT.PageMargins.PageMarginConditionFormulas[CrPageMarginConditionFormulaTypeEnum.crPageMarginConditionFormulaTypeBottom].Text.ToString();
// // This formula must return a number in twip units.
int MyENUM = OffSetString.Length - 51;
string MySTRTemp = OffSetString.Substring(51, MyENUM);
// this will return false if enum cannot be converted
bool myNum = Int32.TryParse(MySTRTemp, out MyENUM);
CRBottom.Text = string.Format("{0:0.000}", (CRBottomInt + (MyENUM / 1440)));
}
catch
{ // if there is no formula catch the exception
CRBottom.Text = string.Format("{0:0.000}", CRBottomInt);
}
}
else
CRBottom.Text = string.Format("{0:0.000}", CRBottomInt);
Note: CR adds the static text: "// This formula must return a number in twip units."
So I remove that part to get the value, you may have to do more logic to handle any other text the Designer of the Report may have added.
Keywords
Cr for VS, Margins, conditional formatting formula , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem