The printout of the attached document with a footer causes the final page of the document to have a large header space, page 3.
If I print out this document after printing, the printed document does not have this large space on page 3. However I have noticed that the footer within the printed document and the saved document is also different, one has a border and the other does not.
I have given you sample code to generate this issue.
- Code: Select all
private void runTest()
{
string tempfilename = @"c:\fail_rtf.doc";
string text = System.IO.File.ReadAllText(tempfilename, Encoding.GetEncoding(1252));
try
{
using (Document doc = new Document(tempfilename, FileFormat.Rtf))
{
renderPrint(doc, new PatientReportDetails("nhsnumber","mrn", "dob", "surname", "forename", "gppractice" , 12345));
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
// System.IO.File.Delete(tempfilename);
}
}
private void renderPrint(Document doc, PatientReportDetails patientDetails)
{
try
{
int i = doc.Sections.Count - 1;
Section lastSection = doc.Sections[0];
lastSection.PageSetup.FooterDistance = 10;
//Add Footer
HeaderFooter footer = lastSection.HeadersFooters.Footer;
Table table = footer.AddTable(true);
table.ResetCells(2, 1);
Paragraph FParagraph = table.Rows[0].Cells[0].AddParagraph();
FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
FParagraph.Format.Borders.BorderType = Spire.Doc.Documents.BorderStyle.None;
FParagraph.Format.Borders.Top.Space = 0.15f;
FParagraph.Format.Borders.Color = System.Drawing.Color.Black;
FParagraph.Format.Borders.Space = 4.0f;
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());
//insert page number
FParagraph = table.Rows[1].Cells[0].AddParagraph();
TextRange FormattedUniqueId = FParagraph.AppendText(patientDetails.getFormattedUniqueID() + "\t");
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;
FPrintedDetails.CharacterFormat.FontName = "Calibri";
FPrintedDetails.CharacterFormat.FontSize = 8;
FPrintedDetails.CharacterFormat.Bold = true;
FPrintedDetails.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;
FormattedUniqueId.CharacterFormat.FontName = "Calibri";
FormattedUniqueId.CharacterFormat.FontSize = 8;
FormattedUniqueId.CharacterFormat.Bold = true;
FormattedUniqueId.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.None;
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();
}
doc.SaveToFile(@"c:\printed_doc.rtf");
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
public class PatientReportDetails
{
private string _mrn;
private string _surname;
private string _forename;
private string _nhsNumber;
private string _dob;
private Int64 _uniqueID;
private string _gppractice;
public PatientReportDetails()
{
}
public PatientReportDetails(string nhsnumber, string mrn ,string dob, string surname,string forename, string gppractice )
{
this._gppractice = gppractice;
this._mrn = mrn;
this._nhsNumber = nhsnumber;
this._surname = surname;
this._forename = forename;
this._dob = dob;
}
public PatientReportDetails(string nhsnumber, string mrn, string dob, string surname, string forename, string gppractice , Int64 uniqueId)
{
this._gppractice = gppractice;
this._mrn = mrn;
this._nhsNumber = nhsnumber;
this._surname = surname;
this._forename = forename;
this._dob = dob;
this._uniqueID = uniqueId;
}
public string GPpractice
{
get { return _gppractice; }
set { _gppractice = value; }
}
public Int64 UniqueID
{
get { return _uniqueID; }
set { _uniqueID = value; }
}
public string Surname
{
get { return _surname; }
set { _surname = value; }
}
public string Forename
{
get { return _forename; }
set { _forename = value; }
}
public string DOB
{
get
{
if (string.IsNullOrEmpty(_dob))
{
return "";
}
else
{
return _dob;
}
}
set { _dob = value; }
}
public string NHSNumber
{
get
{
if (string.IsNullOrEmpty(this._nhsNumber))
{
return "";
}
else
{
return _nhsNumber;
}
}
set { _nhsNumber = value; }
}
public string MRN
{
get
{
if (string.IsNullOrEmpty(_mrn))
{
return "";
}
else
{
return _mrn;
}
}
set { _mrn = value; }
}
public string getFormattedDOB()
{
if (this.DOB.Length >= 8)
{
return "DOB: " + this.DOB.Substring(0, 4) + '/' + this.DOB.Substring(4, 2) + '/' + this.DOB.Substring(6, 2);
}
else
{
return "DOB: ";
}
}
public string getFormattedNHS()
{
return "NHS: " + this.NHSNumber;
}
public string getFormattedMRN()
{
return "MRN: " + MRN;
}
public string getFormattedGPPractice()
{
return "GP: " + this.GPpractice;
}
public string getFormattedPatientName()
{
return "Name: " + this.Surname + " ," + this.Forename;
}
public string getFormattedUniqueID()
{
return "Print UniqueID: " + this.UniqueID;
}
}