Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Apr 30, 2014 12:39 pm

Hello,

I am trying to create a footer with fixed postions for items patient name, Nhs no , page , mrn and DOB

Similar to what's below, but with a border and centered at the bottom of the page and in the center.

NHS No:123456 Patient Name: This is a test
Page 1 of 3 MRN:1234567
Printed 29 April 2015 DOB: 27/11/2010

My attempted code feels crude , as I was unsure how to construct this within the Spire component. I had to use multiple TextRange fields to apply the format to text items, just seemed that I was doing this wrong.


Code: Select all
private void wordPrint(Document doc, PatientReportFooter footerInfo)
        {
            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 FPatientDetails = FParagraph.AppendText
                    (footerInfo.getFormattedPatientName() + "\t" + footerInfo.getFormattedDOB() + "\t" +footerInfo.getFormattedMRN()
                        + "\t" + footerInfo.getFormattedNHS());

                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 FPrintedDetails = FParagraph.AppendText("Printed " + DateTime.Now.ToLocalTime());


                FPageInfo.CharacterFormat.FontName = "Calibri";
                FPageInfo.CharacterFormat.FontSize = 8;
                FPageInfo.CharacterFormat.Bold = true;
                FPageInfo.CharacterFormat.TextColor = System.Drawing.Color.Black;

                FPageInfo1.CharacterFormat.TextColor = System.Drawing.Color.Black;
                FPageInfo1.CharacterFormat.FontName = "Calibri";
                FPageInfo1.CharacterFormat.FontSize = 8;
                FPageInfo1.CharacterFormat.Bold = true;

                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;

                FPatientDetails.CharacterFormat.FontName = "Calibri";
                FPatientDetails.CharacterFormat.FontSize = 8;
                FPatientDetails.CharacterFormat.Bold = true;
                FPatientDetails.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;

                //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
            {

            }
        }


shaun
 
Posts: 16
Joined: Fri Mar 14, 2014 2:58 pm

Thu May 01, 2014 3:34 am

Hello,

Thanks for your inquiry. There are codes for your reference.
Code: Select all
private static void wordPrint(Document doc, PatientReportFooter footerInfo)
        {
            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("NHS No:");
                TextRange FNHSDetails = FParagraph.AppendText
                    (footerInfo.getFormattedNHS() + "\t");
                TextRange FormattedPatientName = FParagraph.AppendText("Patient Name: ");
                TextRange FPatientDetails = FParagraph.AppendText
                    (footerInfo.getFormattedPatientName() + "\r");

                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);
                FParagraph.AppendText("\t");
                TextRange FormattedMRN = FParagraph.AppendText("MRN: ");
                TextRange FMRNDetails = FParagraph.AppendText
                    (footerInfo.getFormattedMRN() + "\r");

                TextRange FPageInfo4 = FParagraph.AppendText("Printed " );
                TextRange FPrintedDetails = FParagraph.AppendText(DateTime.Now.ToLocalTime().ToString());
                FParagraph.AppendText("\t");
                TextRange FormattedDOB = FParagraph.AppendText("DOB: ");
                TextRange FDOBDetails = FParagraph.AppendText
                    (footerInfo.getFormattedDOB());

                FPageInfo.CharacterFormat.FontName = "Calibri";
                FPageInfo.CharacterFormat.FontSize = 8;
                FPageInfo.CharacterFormat.Bold = true;
                FPageInfo.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
            {

            }
        }

If there are any questions, welcome to get it abck to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu May 01, 2014 8:28 am

Gary

I was hoping to have the position of the text and the data values ( MRN, Patient Name , NHS etc ) fixed. For example like a template where I set the Patient name to be 3cm from the left 1cm from the bottom. I can then have all the fields fixed for all the documents and their position is not dependent upon the length of the variables items I am replacing.

Is this possible with the Spire component.

shaun
 
Posts: 16
Joined: Fri Mar 14, 2014 2:58 pm

Fri May 02, 2014 6:22 am

Hello,

Thanks for further inquiry.
Sorry that at present our product doesn't achieve it.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3046
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc

cron