Skip to content

Commit 59a4525

Browse files
committed
Added RichTextFormat support
1 parent f51b6bf commit 59a4525

File tree

13 files changed

+1642
-8
lines changed

13 files changed

+1642
-8
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### What is WebFormsDocumentViewer?
2-
WebFormsDocumentViewer is a simple custom control that lets you embed documents (PDF, Word, PowerPoint and Excel) in your ASP.NET WebForms pages.
2+
WebFormsDocumentViewer is a simple custom control that lets you embed documents (PDF, Word, PowerPoint, Excel and RichTextFormat) in your ASP.NET WebForms pages.
33

44
### How do I get started?
55
First, add a reference in your web.config to the WebFormsDocumentViewer assembly:
@@ -33,7 +33,7 @@ You can configure the following parameters of the viewer:
3333
* Width: sets the width of the iframe
3434
* Height: sets the height of the iframe
3535
* FilePath: path to the file to be render on the HTML page
36-
* TempDirectoryPath: path for the temporary converted to PDF files (see Word, PowerPoint and Excel sections below).
36+
* TempDirectoryPath: path for the temporary converted to PDF files (see Word, PowerPoint, Excel and RichTextFormat sections below).
3737
* PdfRenderer: is used by documents converted to PDFs (see below) and you can choose between [PDF.js](https://mozilla.github.io/pdf.js/) and [Adobe Reader](https://acrobat.adobe.com/uk/en/). Adobe Reader is used by default now, but this requires Adobe to be installed client-side. PDF.js is relying only on JavaScript, but the library is still developing. For further information check their websites.
3838
3939
### How to embed PDF documents?
@@ -79,6 +79,18 @@ You can embed an Excel document as shown below:
7979
If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root.
8080
You can additionally set the PdfRenderer parameter if you want to use PDF.js.
8181

82+
### How to embed RichTextFormat documents?
83+
RichTextFormat documents are converted to PDF documents, then rendered in iframe. You should have Microsoft Office installed on the server for this to work.
84+
You can embed a RichTextFormat document as shown below:
85+
86+
```html
87+
<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.rtf" TempDirectoryPath="~/TempFiles" PdfRenderer="PdfJs" />
88+
```
89+
90+
If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root.
91+
If PdfRenderer is not supplied, Adobe Reader is used by default.
92+
93+
8294
### Do you have an issue?
8395
Have a bug or a feature request? Please search for existing and closed issues before submitting a new one. If your problem or idea is not addressed yet, please open a new issue.
8496

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.IO;
4+
5+
namespace WebFormsDocumentViewer.Converters.Tests
6+
{
7+
[TestFixture]
8+
public class RtfToPdfConverterTests
9+
{
10+
[Test]
11+
[Category("INTEGRATION")]
12+
public void Convert_When_RtfFileNotFound_Then_NullIsRetuned()
13+
{
14+
RtfToPdfConverter converter = new RtfToPdfConverter();
15+
string newFilePath = converter.Convert("test.rtf", "Temp", "");
16+
Assert.That(newFilePath, Is.Null);
17+
}
18+
19+
[Test]
20+
[Category("INTEGRATION")]
21+
public void Convert_When_RtfFileIsFound_Then_NewFilePathIsReturned()
22+
{
23+
RtfToPdfConverter converter = new RtfToPdfConverter();
24+
string root = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
25+
string newFilePath = converter.Convert("Samples\\sample.rtf", "Temp", root);
26+
Assert.That(newFilePath, Is.Not.Null);
27+
Assert.That(Path.GetExtension(newFilePath), Is.EqualTo(".pdf"));
28+
}
29+
30+
[Test]
31+
[Category("INTEGRATION")]
32+
public void Convert_When_RtfDestinationPathDoesNotExist_Then_DirectoryIsCreated()
33+
{
34+
string currentDateSpan = DateTime.Now.Ticks.ToString();
35+
RtfToPdfConverter converter = new RtfToPdfConverter();
36+
string root = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
37+
38+
Assert.That(Directory.Exists(Path.Combine(root, "Temp" + currentDateSpan)), Is.False);
39+
converter.Convert("Samples\\sample.rtf", "Temp" + currentDateSpan, root);
40+
Assert.That(Directory.Exists(Path.Combine(root, "Temp" + currentDateSpan)), Is.True);
41+
Directory.Delete(Path.Combine(root, "Temp" + currentDateSpan), true);
42+
}
43+
}
44+
}

WebFormsDocumentViewer.Tests/Infrastructure/ConverterFactoryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void GetConverter_When_ConverterIsRequested_Then_FactoryReturnsCorrectIns
1616
Assert.That(ConverterFactory.GetConverter(SupportedExtensions.pptx), Is.TypeOf<PowerPointToPdfConverter>());
1717
Assert.That(ConverterFactory.GetConverter(SupportedExtensions.xls), Is.TypeOf<ExcelToHtmlConverter>());
1818
Assert.That(ConverterFactory.GetConverter(SupportedExtensions.xlsx), Is.TypeOf<ExcelToHtmlConverter>());
19+
Assert.That(ConverterFactory.GetConverter(SupportedExtensions.rtf), Is.TypeOf<RtfToPdfConverter>());
1920
}
2021
}
2122
}

0 commit comments

Comments
 (0)