Perform diff on RTF and preview changes - c#

I am looking to compare two RTF files and provide a way of highlighting the differences. Does anybody know of anyway I can do this? The project is a .net project, however worst case, I'm sure I could implement an unmanaged app.
Thanks

I'd say that depends.
If you just want to view the difference between the RTF "code", i.e. the plain textfiles, you could employ a library like DiffPlex.
If you want some WYSIWYG view, i.e. including formatting, etc., you could actually use Word (via Automation). Much like TortoisSVN (xdocdiff) does it.

Related

Parsing PCL for Text

Ok, so I know this is a crappy question but it has been driving me crazy all day...
I have a bunch of files containing raw PCL6/PCL XL code from printing jobs run to our printers. What I need to be able to do is somehow parse them so I can search for specific text.
Does anyone know if this is possible or understand PCL enough to suggest a reason why even on basic prints from say notepad the raw text doesn't seem to be visible within the code?
I suppose I should mention, I need to be able to code this into my C# app. Manual converters or the ability to print the pcl is not going to do what I want.
#mcalex is correct, PCL 6 (PCLXL) is a compiled binary. You can't read it. You need something that can decompile for you. Pagetech have some solutions for this. You could also look to convert to some other format where the data might be more readable. If the source could be generated in PCL 5 or PS you "might" have a better chance or reading the data directly (although not likely).

Edit HTML files manipulating DOM in a jQuery style

I have a batch of HTML files which need some editions easy to perform with jQuery (mainly selecting some nodes and changing their attributes).
My approach to achive this, has been opening them one by one in Google Chrome, excecuting the jQuery code in the console, and then copying the resulting DOM back to my HTML editor.
Since what I'm currently doing takes a lot of time, and also due to the fact that every file needs the same edition (i.e., the same jQuery/JS code will work for every HTML file), I am considering to write a script/program to do this.
Anyway, I am not completely clear of which of the following (if any of them) approaches I should take to accomplish this task.
Write a JavaScript script with jQuery using some FileSystem/File manipulation library (which one?)
Write a Java or C# program using some jQuery-based library (like CsQuery)
Finding a plugin for some of my editors (Aptana, Notepad++, Eclipse, etc) or a completely different editor that supports jQuery-like commands for edition (just as notepad++ regex replacement support). This would be slow with big batches, but at least it would allow me to avoid the annoying copy/paste to/from Chrome.
Is one of this approaches the right way to accomplish what I need? (Is there a right way to do this?) Which should be more straight-forward?
I think that #2 would be easier for me since I have a lot more experience in Java and C# than in JavaScript, but I think that maybe that idea would be sort of using a sledgehammer to crack a nut.
You should consider using PhantomJs. It is a headless WebKit which can be executed from te commandline. It accepts a javascript or coffeescript file as a an argument, which can be used to e.g. do something with a web page. Here is an example:
var page = require('webpage').create();
page.open('http://m.bing.com', function(status) {
var title = page.evaluate(function(s) {
return document.querySelector(s).innerText;
}, 'title');
console.log(title);
phantom.exit();
});
I am not sure of the right way but it sounds like you are familiar with C# and would think writing a class library would be the least overhead for automation. Here are some potential solutions:
Scripting Library (e.g., C#.NET) - You can use a library like the one you mentioned or something like ScriptSharp if you want to use DOM manipulation. If the HTML has appropriate closing tags you can also use LINQ to easily navigate the HTML (or something like the HTML Agility Pack found on CodePlex). I would even recommend using Mustache with an HTML file template in C#.
JavaScript Library - If you wanted to stay in pure JavaScript you can use Node.js. There are file manipulation libraries you can use.
Headless Browsers - Haven't thought through being able to save the resulting HTML automatically but you can use something like jsTestDriver or Phantom.js
You can go with the plugins in editors as well, but I would stick with a Java, C#, python, etc. library that you can potentially call from existing application or schedule as a job/service.

How to draw a base glyph with one color and its attached diacritic with another one?

MS Word has this capability in its Hebrew and Arabic versions. I would like to achieve this in a windows desktop application, using .Net (may be with win-api calls).
As explained in the link provided by Otaku here, current rich text edit controls can not handle this (unless you go for the hack OP in that Q did, which did not seem like a very good solution).
You could write code to do this manually yourself, ditching the text edit control completely, but that would probably mean a lot of work. It took Microsoft years to get support for combining diacritics working properly in MSWord. I would search for open source software that has this capability, and look at how other developers have done it. It might be hard to find, though, and you would likely have to step outside .NET-land. Maybe OpenOffice can do this?
This discussion might also be of help.
I am afraid that you will find, though, that you'll have to manually parse the Unicode and assign colors to the correct glyphs. If you want to be complete, that is one heck of a job.

C# XML language file

I want to have my ASP C# application to be multi-language. I was planned to do this with a XML file. The thing is, i don't have any experience with this. I mean how, do i start? Is it a good idea to store the languages in an xml file? And how in the code do i set the values for ie my menu buttons? I'd like to work with XML because i never worked before with XML, i want to learn how to deal with cases like this.
You want to look into RESX resource files. These are XML files that can contain texts (and images) and they have standardized handling of localization/translations.
Support for this is built right into ASP.NET. There is a guide for how to use it and set it up at: http://msdn.microsoft.com/en-us/library/fw69ke6f(VS.80).aspx.
The walkthough is pretty detailed and should help you to understand the concepts. My preferred is method described a bit down in the document in the section "Explicit Localization with ASP.NET". Using this you will get a set of XML files with your texts and translations in a fully standardized format.
Do you know about the .Net From automatic translatation (based on .resx) resources ?
You're in luck, this sort of stuff is built directly into .Net
The way it's done is that for every page you have a language specific resx file.
eg
Homepage.aspx
Homepage.aspx.cs
Homepage.aspx.en.resx
Homepage.aspx.fr.resx
you simply dynamically figure out what resource file to use, and all the appropriate labels come through in French for example.
Helpful Tutorials and Videos
A Simple Example
Good luck.
If internationalization in .net is something you want to get into seriously, you might want to consider this
(and no - I have no stake in it)

How do I extract/insert text into RTF string in C#

In a C# console app I have the need to extract the text from an RTF string, add some more text to it, and then convert it back into RTF. I have been able to do this using the System.Windows.Forms.RichTextBox class, but I find it a bit odd to use a Forms control in a non-Forms app. Any better way to do this?
Doing anything with RTF is pretty difficult unless you're using the windows forms. As stated above, using forms is the easiest way to go.
You could write something yourself, but the RTF spec is pretty complicated.
http://www.biblioscape.com/rtf15_spec.htm
Or you could use a conversion DLL / ActiveX object of which there is a large number available.
http://www.sautinsoft.com/
Or - If you're doing this from Linux, there are also tools available. A cursory glance throws up UnRTF
http://www.gnu.org/software/unrtf/unrtf.html
I haven't included stuff to turn text back to RTF because I think the RTF specification treats and formats text correctly.
I think you should just shake this feeling of "odd". There's nothing odd about it.
It depends on what you mean by 'better'. You are already using the simplest and easiest way of doing it.
There is nothing wrong with using an user-interface control in a console application or even in a web application. The Windows controls are part of the .NET Framework, might as well use them. These controls do not need to be hosted in "forms" in order to work.
Reinventing the wheel, using DLL/ActiveX/OCX, and using Linux are simply not practical answers to your question. The better way is...do what you know. There is actually a performance and maintainence benefit to using existing framework methods then using the suggested alternatives.

Categories