I am converting our current PDF export using ITextSharp over to Migradoc. We currently render Rich Text to ITextSharp from a string stored in the database - for example:
<p><strong style=\"color: rgb(230, 0, 0);\"><u>test</u></strong></p>
ITextSharp is able to pick out the elements of this and render appropriately using (I think) Cell.AddElement(ElementListItem).
Ideally I am looking for something identical to this for MigraDoc but any help on RTF in MigraDoc would be greatly appreciated.
MigraDoc does not parse HTML.
You can use the AddFormattedText method of the Paragraph class to mix various rich formats within one paragraph, but parsing the HTML is up to you.
See also:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
Related
I need to get a text that's being written by a user (in CKEditor HTML), and then add that text to a MigraDoc document, as a paragraph or whatever I need it to be.
My idea was converting the text to an MDDDL document (in memory) and add it to the document. But I don't know if there are any DLLs that permit that behaviour.
So, my question is, can someone give me pointers or advice on how I could make this happen? Should I parse the HMTL text? If so, to what should I parse it? How can I add it afterwards?
Neither PDFsharp nor MigraDoc can parse HTML, so either write your own code or try to find a third-party library (which may not exist yet).
I would probably convert the HTML directly to MigraDoc document objects in memory.
MigraDoc / PDFSharp can't do this.
But, you could use HtmlAgilityPack nuget and then use its htmlDoc.DocumentNode.Descendants() to pull out the pieces of text from html in a flat list kind of a structure, and node.ParentNode.Name to figure out the tag that the text is wrapped in. And then insert the text into your MigraDoc document with something like .AddFormattedText() and apply custom MigraDoc styles to it - i.e. if the parent tag is "strong" then apply a MigraDoc style where Font.Italic = true; etc..
I'm using Migradoc to print a series of PDF pages. I also have a RichTextBox from the Extended WPF Toolkit. The text is currently using the rtf encoding and is bound to a string property.
I have already seen this answer: https://stackoverflow.com/a/13986397/978622.
It appears to convert the generated XPS to an entire PDF page. I'd like to use the textbox content within a page.
How can I print the formatted text from the textbox with Migradoc? I've
I'm willing to consider using any rich textbox that allows binding & serialization of the data if it makes printing with Migradoc easier.
I am using iTextSharp to read PDF files using C#.
The text extraction using PdfTextExtractor.GetTextFromPage() function returns all text as expected.
But for a PDF which has say, Table of Content, Index & say page number should be dropped.
And I just want to get the paragraph of text.
I checked for availability of options by exploring the ITextExtractionStrategy.
I am really clueless and any pointers will help.
I explored to isolate the fields using AcroFields, but that looks like a long shot.
Thank you.
Regards,
~Mayur
i have a word(Office) file. this file content text and picture.
how can read this file and show in <textarea> </textarea>;
The best way to display rich content like word document on UI is through html. You can export your word document to HTML and render it to asp.net UI controls. If you prefer, textarea, you have to implement custom textarea to support images from word-html file.
Also, you can use WebBrowser control to display this word-html file instead of textarea.
I don't believe you can read this into a <textarea> as you ask. (I will watch to see if somebody else shows how, because I want to see that too...) I believe the closest result you will get is to open the document into an <iframe> with the application/msword content type. If you are looking for some flexiblity in this, wrap the space in a <div> and swap out <textarea> for <iframe> at the server when appropriate.
I need to add strings coming from different RichTextBoxes with different fonts into one RichTextBox retaining the original fonts (more typically sometime I get XML format where fonts for substrings is defined.)
Is there a way of constructing this string in memory and then simply puting it in a RichTextBox? If not, is there any other way?
Try this:
richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new Font( "Veradana", 8.25F );
foreach block with different font just repeat the code
You can save anything in RichTextBox in .rtf format using its
SaveFile method within RichTextBoxStreamType.RichText format and If you wish to load saved format , call LoadFile method
Source here
This answer gives a code sample for drawing text with different colors into a picture box. You could easily modify it to draw the text with different fonts as well. If you need the scrollability of the RichTextBox, you could place the picture box on a panel.
Update: since you need to use a RichTextBox, this link shows you how to transform your original XML into RTF that you can load into your RichTextBox. In order to do this, you have to create an XSLT document that describes how to transform the XML into RTF. The link I included gives a sample XSLT document; you would have to modify this XSLT based upon how the different fonts are specified in your original XML document (if you post a sample of your original XML, we could probably help you modify the XSLT accordingly).