Hi
I am using the following code to add substitution of merge fields in the header/footer to the reporting feature, which does not substitute the header/footer by default. The code seems to work, but the page margins are not preserved. How do I preserve the page settings? Is this the best approach (it is based on the WPTools 5 approach with super merge)?
Also, I am using this code in a web application, and I get a 'Runtime error 217' whenever I close the ASP.Net development server after running this code. What am I doing wrong?
Code
private static void PrintBandedLetter(string letterFileName,
RTF2PDF.FieldGetTextEvent onFieldGetText, RTF2PDF.ReportStateEvent onReportState,
Stream outputStream)
{
using (RTF2PDF rtf = new RTF2PDF())
{
// Load the header and footer into memo2 so that we can perform mail merge on them.
rtf.Memo2.Clear(false, false);
rtf.Memo2.LoadFromFile(letterFileName, false, "RTF");
rtf.Memo2.ClearBody();
rtf.Memo.Clear(false, false);
rtf.Report.InitTemplate(letterFileName, 2);
rtf.OnFieldGetText += onFieldGetText;
rtf.OnReportState += onReportState;
try
{
// FIXME: is this the correct way to substitute header/footer fields?
rtf.Memo2.MergeText("");
rtf.Report.Command(2);
}
finally
{
rtf.OnFieldGetText -= onFieldGetText;
rtf.OnReportState -= onReportState;
}
rtf.Memo2.ReformatAll(false, false);
rtf.PdfCreator.PDFFile = "memory";
rtf.PdfCreator.FontMode = 0;
rtf.PdfCreator.PrintSecond();
outputStream.Write(rtf.ResultBuffer, 0, rtf.ResultBuffer.Length);
}
}
Alles anzeigen
Thanks
Andrew