I am trying to print a report where I have dynamically add a footer containing the field "FieldTYpe.FieldNumPages". I've found that the value is not populated/rendered during the print. However, if I save the file to disk rather than printing the number of pages is rendered correctly.
I am assuming this is occurring because the document that I've added the footer too does not know the number of pages when I try to print. Is there a way to allow this too occur without me having to save the document to disk then reloading into the Spire component?
Shaun
- Code: Select all
private void renderPrint(Document doc, PatientReportDetails patientDetails)
{
try
{
int i = doc.Sections.Count - 1;
Section lastSection = doc.Sections[0];
//Add Footer
HeaderFooter footer = lastSection.HeadersFooters.Footer;
Paragraph FParagraph = footer.AddParagraph();
//insert page number
TextRange FormattedNHS = FParagraph.AppendText(patientDetails.getFormattedNHS() + "\t");
TextRange FormattedMRN = FParagraph.AppendText(patientDetails.getFormattedMRN() + "\t");
TextRange FormattedPatientName = FParagraph.AppendText(patientDetails.getFormattedPatientName() + "\t");
TextRange FormattedDOB = FParagraph.AppendText(patientDetails.getFormattedDOB() + '\n');
TextRange FPageInfo = FParagraph.AppendText("Page: ");
TextRange FPageInfo1 = FParagraph.AppendField("page number", FieldType.FieldPage);
TextRange FPageInfo2 = FParagraph.AppendText(" of ");
TextRange FPageInfo3 = FParagraph.AppendField("number of pages", FieldType.FieldNumPages);
TextRange FPageInfo4 = FParagraph.AppendText("\t Printed " );
TextRange FPrintedDetails = FParagraph.AppendText(DateTime.Now.ToLocalTime().ToString());
FPageInfo.CharacterFormat.FontName = "Calibri";
FPageInfo.CharacterFormat.FontSize = 8;
FPageInfo.CharacterFormat.Bold = true;
FPageInfo.CharacterFormat.TextColor = System.Drawing.Color.Black;
FPageInfo1.CharacterFormat.FontName = "Calibri";
FPageInfo1.CharacterFormat.FontSize = 8;
FPageInfo1.CharacterFormat.Bold = true;
FPageInfo1.CharacterFormat.TextColor = System.Drawing.Color.Black;
FPageInfo2.CharacterFormat.FontName = "Calibri";
FPageInfo2.CharacterFormat.FontSize = 8;
FPageInfo2.CharacterFormat.Bold = true;
FPageInfo2.CharacterFormat.TextColor = System.Drawing.Color.Black;
FPageInfo3.CharacterFormat.FontName = "Calibri";
FPageInfo3.CharacterFormat.FontSize = 8;
FPageInfo3.CharacterFormat.Bold = true;
FPageInfo3.CharacterFormat.TextColor = System.Drawing.Color.Black;
FPageInfo4.CharacterFormat.FontName = "Calibri";
FPageInfo4.CharacterFormat.FontSize = 8;
FPageInfo4.CharacterFormat.Bold = true;
FPageInfo4.CharacterFormat.TextColor = System.Drawing.Color.Black;
FormattedNHS.CharacterFormat.FontName = "Calibri";
FormattedNHS.CharacterFormat.FontSize = 8;
FormattedNHS.CharacterFormat.Bold = true;
FormattedNHS.CharacterFormat.TextColor = System.Drawing.Color.Black;
FormattedPatientName.CharacterFormat.FontName = "Calibri";
FormattedPatientName.CharacterFormat.FontSize = 8;
FormattedPatientName.CharacterFormat.Bold = true;
FormattedPatientName.CharacterFormat.TextColor = System.Drawing.Color.Black;
FormattedMRN.CharacterFormat.FontName = "Calibri";
FormattedMRN.CharacterFormat.FontSize = 8;
FormattedMRN.CharacterFormat.Bold = true;
FormattedMRN.CharacterFormat.TextColor = System.Drawing.Color.Black;
FormattedDOB.CharacterFormat.FontName = "Calibri";
FormattedDOB.CharacterFormat.FontSize = 8;
FormattedDOB.CharacterFormat.Bold = true;
FormattedDOB.CharacterFormat.TextColor = System.Drawing.Color.Black;
//Set Footer Paragrah Format
FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
FParagraph.Format.Borders.BorderType = Spire.Doc.Documents.BorderStyle.Thick;
FParagraph.Format.Borders.Top.Space = 0.15f;
FParagraph.Format.Borders.Color = System.Drawing.Color.Black;
FParagraph.Format.Borders.Space = 4.0f;
using (PrintDialog dialog = new PrintDialog())
{
doc.PrintDialog = dialog;
PrintDocument printDoc = doc.PrintDocument;
printDoc.PrintController = new StandardPrintController();
printDoc.Print();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}