Comparison Of two HTML - c#

I am working on 2 pdf Compare where 1st I extracted PDF to get styles of PDF .PDF styles are extracted and converted to html. then at last I compare 2 HTML text.
For PDF Extraction I used itextsharp
Here is the code
this.result.AppendFormat(
"<tr><td>{0}</td><td>{1}</td><td>{2}pt</td><td>{3}</td><td>{4}</td><td>",
Form1.j, curFont, font_size_client, fontweight, fontstyle);
}
this.result.Append(renderInfo.GetText());
}
public string GetResultantText()
{
if (result.Length > 0)
{
result.Append("<tr><td></td><td></td>");
}
return result.ToString();
}
this is the code where i used for conversion. MY question is one sample PDF i used HTML text book itself for comparison the text .in HTMLbook there were some styles like background color, fontsize got appended to the text . instead of text it took style. Can you please tel me how to extract style. is the method i chosen to compare 2 PDF is wrong. OR any other method.

Once you extracted it to HTML you can use jQuery to get the .HTML() code.
Take a look here: https://api.jquery.com/html/
After that you can compare the two results.

Related

Is it possible to append a string in code to a Base64 string and create a new Image with the string?

I am using the QR Coder library in C# to generate QR codes that will go to a URL with a Token in the Query String.
https://github.com/codebude/QRCoder
Currently, I can Print Preview all the QR Codes, but without a Token showing beneath it.
I need to display a string below the QR Code image with a Token Code when I click on the Print Preview button. This will fetch all the QR Code images and show them on the Print Preview window.
The Print Preview button will fetch all the Tokens generated, append them to a link and finally generate the base64 string for the QR Image that is sent to a JavaScript Print method.
I am using Print JS: https://printjs.crabbly.com/
Below is my JavaScript method below with the following code (Multiple Image Mode):
function printAllQRCodesForProduct(base64, printwidth) {
printJS({ printable: **base64**, type: 'image', imageStyle: 'width:' + printwidth + '%;margin-
bottom:10px; float:left; margin-right:10px;' });
}
It does not seem that Print JS can allow you to have multiple image captions. If this was the case, that would work. Perhaps I can modify the Print JS code or perhaps is it possible to somehow take the generated Base64 image QR code and append a string with the Token text just below it without having to render the image on a Canvas tag and then re-saving it as a Base64 string? Can all this be done on the Code-Behind in C#?
So in summary, is it possible to modify a base64 generated image with another image and combine them, or is there a way to add text and get a new base64 image string?
I see that it is possible to add text to a generated Bitmap in C#.
Found the answer on this post: c# write text on bitmap

Android Webview equivalent in Windows Phone 8 app

I have text with some HTML tags in it.
Example : <I> I Play Football and Cricket </I>
Now when i try to display this text in Textblock it displays with Italics tag <I> as well.
The data is present in the XML file and i am working on Windows Phone 8 application.
In Android we use Webview, but what do i need to use here ?
EDIT
I have tried using TextBlock with inlines:
Italic itlText = new Italic();
itlText.Inlines.Add(new Run() { Text = "This is some example text in italics" });
Inilinetext.Inlines.Add(itlText);
It works good But issue here is suppose i have a text like below.
"This is text in <I>Italics</I> here"
Now it display entire text in italics.
This depends on how much content you want to display. If you will show large amount of HTML text, use WebBrowser control for that.
In case you only have a couple of tags i, em, b or strong, then you can actually use TextBlock, but you would have to do the parsing yourself then in order to convert the HTML to the suitable XAML components.
You also have to ask yourself how many such controls you need to display on a single page. If the answer is a few, use the WebBrowser then. If you need to display lots of them, say you have a chat or a feed, then the second route would be better.
EDIT:
Use the following code:
Inilinetext.Inlines.Add(new Run() { Text = "This is text in " });
Inilinetext.Inlines.Add(new Run() { Text = "Italics", FontStyle = FontStyle.Italic });
Inilinetext.Inlines.Add(new Run() { Text = " here" });
I told you you have to parse the original string to see which parts are italic and which are not.

How to copy both - HTML and text to the clipboard?

I'm trying to put in the clipboard piece of HTML and plain text at the same time, so that HTML-capable editors could paste HTML, and other editors could use plain text.
Clipboard.SetData(DataFormats.Html, htmlWithHeader);
Clipboard.SetData(DataFormats.UnicodeText, plainText);
But only the last format is actually put to the clipboard. In the sample above, clipboard would contain only plaintext (as shown by Clipboard.GetDataObject().GetFormats()). And if I swap the lines, the clipboard would have only the HTML format.
How can I put both formats into the clipboard at the same time?
You can NOT use Clipboard.SetData for setting both HTML and plain text. The second call of SetData will clear the content of clipboard that has been set by first call and store the new data.
You should use DataObject and Clipboard.SetDataObject().
Example:
DataObject dataObj = new DataObject();
dataObj.SetData(DataFormats.Html, htmlWithHeader);
dataObj.SetData(DataFormats.Text, plainText);
Clipboard.SetDataObject(dataObj);

C# Paste HTML to Excel or PowerPoint

How to paste HTML ( tables ) code into Excel or PowerPoint?
I've overcome some issues concerning pasting HTML into Excel and PowerPoint and noticed that a lot of people are asking that.
I'd like to share my research, solution I made out for it.
Let's say we have a html file named html and we would like to access it in Excel, let's do following:
Clipboard.SetText(html);
We copy our html into the Clipboard. The clipboard generates from the html a real table or image/chart from the input file.
System.Threading.Thread.Sleep(2000);
Let's wait a second to have a preview
sheet.Range(cellmapp).PasteSpecial();
Now, we paste the content into a range that we could like to paste it, by defining cellmap.
System.Threading.Thread.Sleep(1000);
Let's wait a second to see the output
sheet.UsedRange.Copy(Missing.Value);
Now, in order to copy the table image into PowerPoint, we must work the with UsedRange.Copy, because it will copy the currently selected Excel area.
In order to check that we paste it into the correct Powerpoint slide
foreach (PowerPoint.Slide slide in presentation.Slides)
{
foreach (PowerPoint.Shape pptshape in slide.Shapes)
{
if(<your condition satisfies>)
{
slide.Select(); // some position in any slide
pptshape.Delete();//delete old content that was in that slide
ppApp.ActiveWindow.View.PasteSpecial(); //paste the Excel content
}
}
}
Of course there are other solutions, like making an image out of the html code and pasting that, which was my initial idea.
Another post refering that manipulation:
Showing HTML in PowerPoint

I want to select all and copy it to clipboard

I have a WebBrowser displaying text.
If i copy it to clipbaord it copy's all the html tags to and i don't want that.
I want to be able to select all then copy to clipboard.
I want to copy the text and its formatting to the clipboard.
When i highlight the text my self and click copy when i paste, its perfect just how i want it.
But when i use this code to copy just the Document text i get the Html tags to.
This is how i copy to clipboard:
void CopyCellText()
{
Clipboard.Clear();
if (webBrowser1 != null)
{
Clipboard.SetText(webBrowser1.DocumentText.ToString().Trim());
}
}
To Select all and copy to clipboard:
webBrowser1.Document.ExecCommand("SelectAll", true, null);
webBrowser1.Document.ExecCommand("Copy", true, null);
You wont see the html tags but have all there formatting.
You mean you want to convert your html code to text and copy to clipboard? You will need HTML Agility Pack. Check this page for an easy guide.
http://www.dreamincode.net/code/snippet1921.htm << check this code snippet. it would be better, if you strip the string while using regex!
I think the reason you are getting the HTML tags is webBrowser1.DocumentText will take the entire content of the HTML document itself, which will include all the generated HTML.
A quick search gave me the following:
Retrieving Selected Text from Webbrowser control in .net(C#)
Get all text from WebBrowser control

Categories