26650

Convert RTF to PDF format

Question:

Any ideas how to convert RTF to Text format and to keep both style and fonts?

<strong>NOTE:</strong>

I want to avoid using System.Windows.Forms

<strong>Update</strong>

I have something like this in RTF

<P style="TEXT-ALIGN: center; MARGIN: 0in 0in 0pt" class=MsoNormal align=center><FONT face=Calibri><SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt"><STRONG>Questions and Answers<BR style="mso-special-character: line-break"></STRONG><BR style="mso-specialcharacter: line-break"></SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 12pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></P> ... #558ED5; mso-style-textfill-fill-themecolor: text2; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfillfill- colortransforms: 'lumm=60000 lumo=40000'"><FONT color=#3366ff><SPAN style="LINEHEIGHT: 115%; FONT-SIZE: 14pt"><A title="Context Menu Default Items" href="http://PG1/FocusOrthoServer/Images/Help/Helps/FocusOrthoHelp.aspx?HelpPageID=368" target=_blank><FONT size=3 face="Times New Roman">Context Menu Default Items</FONT></A></SPAN></FONT></SPAN></U><FONT color=#000000>.<o:p></o:p></FONT></SPAN></P></FONT></FONT><o:p></o:p>

Which actually displays a help text. I need to write that text to a PDF as it is!

<strong>P.S</strong>

I am using iTextSharp

Answer1:

<strong>Edit :</strong>

Based on your edit the answer is a lot simpler. Just parse the file and store the individual elements together with their formatting tags.

Then create a pdf document and write out the text elements applying styles that match the original formatting tags. It's time consuming to implement but it will work.

I've done something similar a few years ago.

Alternatively you could use PDFSharp's virtual printer (or any other pdf virtual printer for that matter) to do this hassle free. Just print to PDF :)

<strong>Original Post :</strong>

You cannot have a plain text format (that's what I can assume from your question) that would have text formatting.

Tags is how formats like RTF maintain formatting in the first place. So getting rid of all tags gives you a plain text document.

However, you could have some sort of a meta file that would store the formatting data about your plain text document.

The idea is simple, you use word positions (line and column numbers) as keys to formatting tags that you will store in an xml or any other file format you want. You will end up with two files plain.txt and plain.meta.

Hope this helps.

Recommend

  • how to change the color of specified word in python
  • Microsoft Graph Subscriptions - Exchange Online resources are not supported for MSA requests
  • Progress Bar in Python Console on Windows
  • Spark dataframes: Extract a column based on the value of another column
  • Bind two JSF input fields with single property of backing bean
  • Replace HTML links with text
  • Dealing with XElement null value
  • Updates to SolrConfig.xml file are not being reflected
  • Updating one element of a bound Observable collection
  • How to check disabled jobs with Jenkins server?
  • Android NFC read Tags issue. Activity starts each time on data received
  • Android - VerifyError
  • Greek letters in legend in R
  • Open an application in a space using applescripts
  • Need a consistent TimePicker gizmo for mobile web site
  • Phonegap GA plugin not working
  • how to ignore xml namespaces?
  • Activity overlaying. WindowManager.LayoutParams
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • Synchronize windows folders
  • Splash Screen will not display
  • Doctrine/Symfony entity generator and generating entity from one table
  • Xamarin Android | Layout style
  • Setting the run time properties on SpringApplicationBuilder()
  • Enabling DTD support in Sql Server
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Looking for good analogy/examples for monitor verses semaphore
  • How to get current document uri in XSLT?
  • How to write order and limit within cakephp joins array
  • Passing 1 of 3 values to a Sub
  • Xcode 4 NSLog Macro link in Xcode 3
  • Play WS (2.2.1): post/put large request
  • Retrieving value from sql ExecuteScalar()
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Deserializing XML into class C#
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Is there a mandatory requirement to switch app.yaml?
  • Matrix multiplication with MKL
  • File upload with ng-file-upload throwing error
  • How to Embed XSL into XML