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 Jun 25, 2014 12:39 pm

Hello

When reading in a rtf file that's in Letter format the Spire.Doc component treats it as A4. The consequence of this is that some of the border text is missing from the printed report. The file we are reading in is called fail_rtf.rtf

I have tried changing the format of the spire document to Letter but this only affects the saved document and not the in memory document.

The code I have included reads in the fail_rtf.rtf file (Letter format), prints the file using spire.Doc and saves the file using spire.Doc as c:\printed_doc.rtf . If you now look at the printed document, the border is missing. Opening the file printed_doc.rtf in word and looking at the pagelayout you will see the format as A4 and the printpreview removes the border as with the printed document.

I tried to address this issue by forcing the Spire.Doc to treat the fail_rtf.rtf as Letter format using

lastSection.PageSetup.PageSize = PageSize.Letter;

The printed document is still being treated as A4 with the border missing but the saved file printed_asletter.rtf has been saved in letter format and the print preview in word is correct with no border missing.

If it was the case that all are documents were letter, I would code around this issue. However, this is not the case and is a issue.

Please see the test code below. It reads in the test file and prints normally in memory and saves the file. It then forces the document in memory to be letter format then saves it.



Code: Select all
 private void runTest()
        {
            string tempfilename = @"c:\fail_rtf.rtf";

            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", "shouldbeletter", "forename", "gppractice" , 12345));
                }

                using (Document doc = new Document(tempfilename, FileFormat.Rtf))
                {
                    renderPrintForceLetter(doc, new PatientReportDetails("nhsnumber", "mrn", "dob", "force letter", "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
            {

            }
        }


        private void renderPrintForceLetter(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;




                lastSection.PageSetup.PageSize = PageSize.Letter;

                using (PrintDialog dialog = new PrintDialog())
                {
                    doc.PrintDialog = dialog;
                    PrintDocument printDoc = doc.PrintDocument;
                    printDoc.PrintController = new StandardPrintController();
                    printDoc.Print();
                }
                doc.SaveToFile(@"c:\printed_asletter.rtf");



            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }

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

Thu Jun 26, 2014 6:58 am

Hello,

Thanks for your feedback.
We have noticed the issue about the format, which has been posted to our Dev team, once there is any update, we will let you know.
For the issue you specified that the border is missing, sorry that we don't quite understand, as we see that there is no border missing. Can you describe it with screenshot?
Thanks in advance,
Gary
E-iceblue support team
User avatar

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

Thu Jun 26, 2014 7:10 am

Gary

Please find attached a scanned document indicating the issue.

The border around the clinical data at the top of the page is incomplete as its off the printable area of the page. This is the affect when the document is size "Letter" but we are printing it as A4.

Shaun

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

Thu Jun 26, 2014 8:35 am

Thanks.

Gary
E-iceblue support team
User avatar

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

Tue Jul 08, 2014 7:14 am

Gary,

Has there been any progress in regards to the page size issue.

Will there be a hot fix for this issue?

Shaun

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

Tue Jul 08, 2014 8:39 am

Hello,

Sorry for long silence.
The issue has been resolved, but sorry that there is still no a hot fix at present, once there is, we will inform you immediatly.
Sincerely,
Gary
E-icebue support team
User avatar

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

Tue Jul 15, 2014 7:42 am

Gary,

Do we have a date yet for the availability of the hotfix?

Shaun

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

Tue Jul 15, 2014 9:46 am

Hello,

Sorry for inconvenience. The hotfix will be released within this week.

Thanks,
Gary
E-iceblue support team
User avatar

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

Wed Jul 16, 2014 9:26 am

Hello,

The newest hotfix has been released, please download the Spire.Doc Pack(hot fix) Version:5.2.16 and test.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

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

Thu Jul 17, 2014 2:18 pm

Gary,

I have tried the newest hot fix and it still fails the with the border around the patient details, its being pushed off the printed area of the page.

If you look at the fail_rtf.rtf in preint preview in word the border is complete. However when you try to print through code the border is incomplete.

Please see the previous code attached in this thread.

Shaun

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

Fri Jul 18, 2014 7:14 am

Hello,

Thanks for your feedback.
We have tested the file with the SPire.Doc5.2.16, after printed, the border is complete. You can check the xps from the below link.
http://www.e-iceblue.com/downloads/attachment/print.zip
And what's your system environment? platform?
Thanks,
Gary
E-iceblue support team
User avatar

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

Tue Jul 22, 2014 9:10 am

Gary,

I have tried again this morning, ensuring I had the correct libaries and it still fails.

We are currently testing on windows XP with Microsoft Office Word 2007. I looked at both the in memory print from the test program and manually printing off the c:\printed_doc.rtf file. I tried to include the file I created this morning for comparision, but the board attachment quota had been reached. I email this directly Gary.

Could it be I am testing the evaluation copy while your engineers are testing the production version.

Shaun

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

Wed Jul 30, 2014 8:15 am

Gary,

Following on from your helpful email posts I have discovered the following.

I amended the test code for the renderPrint, given below to just save the document and perform no document manipulation. See the full test code in the post trail.

The original document which we are using to print c:\fail_rtf.rtf ( previously emailed ) has a margin of normal in word

The saved document doc_before_manipulation.rtf has a margin of Office 2003 Defaults.

To recap we read in a file with normal margin c:\fail_rtf.rtf , we save the document doc_before_manipulation.rtf with no manipulation and the margin becomes Office 2003 Defaults

Now I understand that this does not occur in your test environment but it occurs in occurs in ours.

Could you find out where the margin is being picked up from, as it appears to be taken from some system variable. If I open a new word document the margin is normal margin

Thanks for your continued help with this issue.

Shaun

Code: Select all
private void renderPrint(Document doc, PatientReportDetails patientDetails)
        {
            try
            {
               doc.SaveToFile(@"c:\doc_before_manipulation.rtf");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {



}

            }




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

Wed Jul 30, 2014 9:43 am

Hello,

We will investigate and let you know ASAP.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Wed Jul 30, 2014 10:01 am

Hello,

What's your system environment? For example, vs version, region and language, office version,etc.
BTW, could you please provide us the screenshot about the margin becomes Office 2003 Defaults?

Thanks,
Gary
E-iceblue support team
User avatar

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

Return to Spire.Doc