Easiest way to print RichEditBox Document - c#

UWP Windows 10. C#
What the easiest way to print RTF Document from RichEditBox?
I found the solution from MSDN, but I don't completely understand this. In this example prints element (like RichEditBox screenshot). I need just to print RichEditBox.Document text...

If I understand your question correctly, what you need is save a Rich Text Format (.rtf) file in a RichEditBox.
To do this, you can refer to the official RichEditBox document, there is sample in this document shows how to edit, load, and save a Rich Text Format (.rtf) file in a RichEditBox.

Related

C# PDFsharp output RTF text

I have data in SQL that is in RTF as it contains a lot of superscript characters. I am trying to print the data on a PDF using PDFsharp (not MigraDoc) using DrawString, however, as I expected, it just shows the RTF string...
I tried putting it in a RichTextBox and then retrieving the Text property, this gives the correct plain text but not in superscript format, which I need.
Can anyone tell me how to correctly output the RTF data?
First from FAQ of pdfsharp:
Can I use PDFsharp to convert HTML or RTF to PDF?
No, not "out of the
box", and we do not plan to write such a converter in the near future.
Yes, PDFsharp with some extra code can do it. But we do not supply
that extra code. On NuGet and other sources you can find a third party
library "HTML Renderer for PDF using PdfSharp" that converts HTML to
PDF. And there may be other libraries for the same or similar
purposes, too. Maybe they work for you, maybe they get you started.
A workaround I think is using DrawToBitmap with a RichTextBox to render the RTF string into an image, then use DrawImage to put it in the pdf file.
Using a RichTextBox would also be my approach, but I would select only a single character in the text and query the relevant properties (subscript, superscript, maybe also bold, italic, underline, and anything else you need). And when any of those properties changes, draw the text you collected so far and continue collecting characters for the new set of properties until any relevant property changes.
I would probably use MigraDoc so I would not have to deal with line-breaks in my code, but that is up to you. I would not create bitmaps for the text as this voids the advantages of the PDF format.

Need helping exporting HTML or Block data as a document in WinRT

I'm running into a problem that I can't seem to figure out. The scenario is:
Download a bunch of text data as an HTML string
Use an HTML-to-Xaml converter to parse the HTML string and create a List<Block> (Windows.UI.Xaml.Documents.Block).
Display the collection of Blocks as a RichTextBlock control that's available in WinRT.
All of that works well. The problem is, I want to export this data as either a doc/docx or pdf file. Is there a way to export either the RichTextBlock directly or add these Blocks to a RichEditBox or even use the original HTML string to export to the file?
I looked at the Syncfusion Essential Studio, that offers the RichTextBoxAdv control, that's used as:
xmlns:rtba="using:Syncfusion.UI.Xaml.RichTextBoxAdv">
<Grid>
<rtba:SfRichTextBoxAdv>
</rtba:SfRichTextBoxAdv>
</Grid>
But so far as I can tell, there is no way to import Block data or use an HTML string. The latter used to exist in WPF but it's not there anymore. Any suggestions?
Syncfusion SfRichTextBoxAdv control for WinRT supports importing and exporting HTML document, Word document, Rich Text Format document and Text document. With the help of this functionality, you can easily achieve your requirement by using Syncfusion SfRichTextBoxAdv control. Please do find the sample from below link.
Sample link:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample-2055612463
Kindly go through the online KB from following link, to know more information about binding HTML string to SfRichTextBoxAdv control.
https://www.syncfusion.com/kb/5415/how-to-bind-html-text-in-sfrichtextboxadv-control
Regards,
Arumuga Perumal S.

Embed word document into another WITHOUT icon

How to embed a word document into another word document via OpenXML SDK, but showing content, not an icon of word? Such, as we do it manually in word: Insert object from file -> WITHOUT checking "Dispaly as icon"?
I've found this article, but it uses an icon. I've also tried to use OpenXML SDK Productivity Tool, but shows only generated binary data.
EDITED:
I use the following code:
DrawAspect = OleDrawAspectValues.Content
and then i add image part:
var imagePart = mainDocumentPart.AddNewPart<ImagePart>("image/x-emf", imagePartId);
GenerateImagePart(imagePart);
But my image part - is just an array of bytes of word's icon.
So, in this case happens the following: when i open generated document, it shows embedded document as an icon, but when i double click this embedded document, edit it and save changes, the embedded document is shown as a content, so maybe it's possible in some way to show this content without editing embedded document? Should i use instead of array of bytes of word's icon an array of bytes of doc's screenshot?
Not sure i described it clear, so please ask
I'm afraid what you are asking for is almost impossible.
The only difference as far as the word file is concerned between the icon and the embedded file, is the image.
When you don't use a icon Word pretty much just take a screenshot of the document you are embedding and inserts that in place of the Icon graphic.
I've uploaded an example I grabbed from a Word file I made. Found this little gem in the /media folder inside the .docx file.
So basicly, your only choice in resolving this if you can't live with the Icon is to somehow grab a picture of the word-file you want to embed and insert that instead of the Icon image.
How you'd go about that can't be pretty. First of all the open xml sdk contains no such functionality. I tried playing a bit around with office interop as well, but no luck.
I only see two possible ways to achieve this.
First one is via Interop. You'll need to install a "pretend printer" like the ones that print to PDF instead of sending it to a printer. This one however needs to print to an image format. The format of the file in the Media folder was .emf but I'm not positive thats a requirement.
Anyways, should the above somehow be possible you could embed that picture, pretty much using the example you link from Microsoft, and just change this size of the "icon" which now would be an image of the document.
Second possibility would be to open the word document as a process, set the document size to 72% (or whatever makes the document be the only one on screen on your desktop) and the grab a print screen and cut it down to just the document and the use that as your image for the embedding.
For the record, I don't recommend you do any of the above, but thoose are the only options I see.
Should someone have a better solution to this I'm all ears.
Finally, should you decide that you want to push on with this, I'll be happy to code up an example of option number 2 if you reply and tell me you'd like that.
Kaspar
There is a nice wrapper API (Document Builder 2.2) around open xml specially designed to merge documents, with flexibility of choosing the paragraphs to merge etc. You can download it from here.
Using this tool you can embed a paragraph of another word document or entire word document as per your requirement.
The documentation and screen casts on how to use it are here.
Hope this helps.

C# PDFSharp: Examples of how to strip text from PDF?

I have a fairly simple task: I need to read a PDF file and write out its image contents while ignoring its text contents. So essentially I need to do the complement of "save as text".
Ideally, I would prefer to avoid any sort of re-compression of the image contents but if it's not possible, it's ok too.
Are the examples of how to do it?
Thanks!
Extracting text from a PDF file with PDFsharp is not a simple task.
It was discussed recently in this thread:
https://stackoverflow.com/a/9161732/162529
Extracting text from a PDF with PdfSharp can actually be very easy, depending on the document type and what you intend to do with it. If the text is in the document as text, and not an image, and you don't care about the position or format, then it's quite simple. This code gets all of the text of the first page in the PDFs I'm working with:
var doc = PdfReader.Open(docPath);
string pageText = doc.Pages[0].Contents.Elements.GetDictionary(0).Stream.ToString();
doc.Pages.Count gives you the total number of pages, and you access each one through the doc.Pages array with the index. I don't recommend using foreach and Linq here, as the interfaces aren't implemented well. The index passed into GetDictionary is for which PDF document element - this may vary based on how the documents are produced. If you don't get the text you're looking for, try looping through all of the elements.
The text that this produces will be full of various PDF formatting codes. If all you need to do is extract strings, though, you can find the ones you want using Regex or any other appropriate string searching code. If you need to do anything with the formatting or positioning, then good luck - from what I can tell, you'll need it.
Example of PDFSharp libraries extracting images from .pdf file:
link
library
EDIT:
Then if you want to extract text from image you have to use OCR libraries.
There are two good OCRs tessnet and MODI
Link to thread on stack
But I fully can recommend MODI which I am using now. Some sample # codeproject.
EDIT 2 :
If you don't want to read text from extracted images, you should write new PDF document and put all of them into it. For writing PDFs I use MigraDoc. It is not difficult to use that library.

For eBook which control i should use and how to start

i want to develop such an application through which i can read book ,currently i am using the Richtextbox in flow document,i dont want to use the scroll ,i prefer the navigation style i.e prev page next page start and end ,book may contains images tables so and so ,and how do i import books in my application
How can i achieve?
Regards,
Aamir
You want to look at the FlowDocument, which is meant for documents with pages.
You'll need to write code to extract the text from the word or pdf document.
You can get out the text from a Word document using Word automation.
For pdf files you can possibly use the iTextSharp library:
http://itextsharp.sourceforge.net/
For other formats you might be able to use the source of FBReader as a sample:
http://www.fbreader.org/downloads.php

Categories