Korean utterances are not well mapping into GeneratePdf from html content - c#

I am generating pdf from this HTML, and for achieving this I am using https://www.nrecosite.com/pdf_generator_net.aspx
This is the HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>Remarks</p>
<p>한국어 발언을 표시하는 테스트입니다</p>
</div>
</body>
</html>
and this the code for generating the pdf:
var pdfBytes = new
NReco.PdfGenerator.HtmlToPdfConverter().GeneratePdf(html);
and the result is this:
how can I generate the pdf with the correct Korean utterances?
Thanks

Related

A section won't render in my ASP.NET MVC website with error: "the delegate type could not be inferred"

This is the layout code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- theme meta -->
<meta name="theme-name" content="A Hopefull Life" />
</head>
<body>
<div>
#RenderBody()
</div>
<div>
#RenderSection ("myFAQ")
</div>
</body>
</html>
This is the code for the faq.cshtml:
#{
ViewData["Title"] = "FAQ";
Layout = "/Views/Shared/FAQLayout.cshtml";
}
#section myFAQ{
}
This is a simplified code of the entire website, I thought I did everything accordingly, but I got the error message. I thought it was the contents of the section causing the error (which was a few paragraphs) so I removed it but it wasn't the source.

Unable to load the image

Unable to add image.
I am unable to upload the image in browser using the code as show below
When i try to run the code, image is not displaying, in console it showing the error has below:
a1.jpg:1 Failed to load resource: the server responded with a status of 404 (Not Found)
\\\
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Myproject</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div>
<img src="assests/a1.jpg" height="20" width="40">
</div>
<div>
<app-root></app-root>
</div>
</body>
</html>
There is a spelling error in assets. Spell it assets and not assests and try again

How to only return contents of an html body with razor?

I have the a page and I want to conditionally return the contents of the body tag only. The condition is ViewBag.BodyOnly
I've tried the following, but I get The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup error:
#if (ViewBag.BodyOnly) {
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Title</title>
</head>
<body>
}
<div>this</div>
<div>that</div>
#if (ViewBag.BodyOnly) {
</body>
</html>
}
What am I missing here?
Your best bet is to extract a partial for the content inside your body tag for example:
#if (ViewBag.BodyOnly)
{
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Title</title>
</head>
<body>
#Html.Partial("_body")
</body>
</html>
}
else
{
#Html.Partial("_body")
}
Then in _body.cshtml:
<div>this</div>
<div>that</div>
The problem is that you're thinking of HTML in terms of tags when you need to think of it in terms of nodes.
When you do something like this:
#if (something) {
<html>
}
Your if-statement is lopping off the first half of a node, and the rest of it is left out in the cold.
In order to do what you're trying to accomplish, factor out the body portion, and then use that in two places:
#helper Body()
{
<div>this</div>
<div>that</div>
}
#if (ViewBag.BodyOnly)
{
#Body()
}
else
{
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Title</title>
</head>
<body>
#Body()
</body>
</html>
}

C# WebBrowser.Print() does not print specific HTML files when the IMG image is not exists

I am trying to print from a very basic C# Form application using the WebBrowser control Print() method, but with a specific HTML file, nothing seems to happen.
The printing works fine with other HTML files, and the only difference, is that the problematic html file contains an image with a non existing image. I would expect to ignore the non existing image and print the file, but no printing, not even an exception happens.
How could I somehow manage the printing even if the file has non existing references, such as image? What workarounds do i have?
The browser emulation is already set to IE11, and already tried ExecWB, nothing seems to work.
HTML: (image.jpg is not exists)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<BODY>
<div class="page">
<table class="table"><tbody><tr><td class="nobotpadding">
<div class="per-details">
<span class="med-text blue mr10">
test text
<img src="/img/image.jpg" alt="" width="14" height="14">
</span>
</div></td></tr></tbody></table>
</div></BODY></HTML>
C#: (Load and Print are different buttons on the form.)
public void Load()
{
webBrowser1.Navigate(localhtmlfile);
}
public void Print()
{
webBrowser1.Print();
}
You can maybe do something like that:
htmlfilewithimg:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<BODY>
<div class="page">
<table class="table"><tbody><tr><td class="nobotpadding">
<div class="per-details">
<span class="med-text blue mr10">
test text
<img src="/img/image.jpg" alt="" width="14" height="14">
</span>
</div></td></tr></tbody></table>
</div></BODY></HTML>
the htmlfilewithoutimg:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<BODY>
<div class="page">
<table class="table"><tbody><tr><td class="nobotpadding">
<div class="per-details">
<span class="med-text blue mr10">
test text
</span>
</div></td></tr></tbody></table>
</div></BODY></HTML>
and inside your C# code, you try to go inside your picture to see if there is a file with the name of the picture and if there isn't a picture, you use the second htmlfile
like :
public void Load()
{
try
{
Path.GetFileName("img/img");
webBrowser1.Navigate(htmlfilewithimg);
}
catch(Exception ex)
{
webBrowser1.Navigate(htmlfilewithoutimg);
}
}
public void Print()
{
webBrowser1.Print();
}

Automatically press a button from iframe

I have a HTML page that have an iframe. This iframe has a button. Which is one of the possibile ways to press that button?
I tried with javascript, but I didn't solve it...
Thank you in advance!
hey you can try to find that button id and handle the click event..
it will look something like this.
$('#youriframeid').contents().find('#yourbuttonid').click(function(){});
EDIT
Your main html page containing iframe.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js" type="text/javascript"> </script>
<script>
$('#a').contents().find('#iframbtn').click(function(){alert("It Worked!")});
$('#a').contents().find('#iframbtn').trigger('click');
</script>
</head>
<iframe id="a" source="a.html">
</iframe>
</html>
Your second html page containing iframe mark up
<html>
<input type="button" id="iframbtn" value="clickme"/>
</html>
Try to use this:
$("#mainiframe").contents().find("someID").trigger("click");
Sample1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
function call(){
try{
document.frm.but.click();
}catch(e){
}
}
</script>
<BODY onload ="call()">
<iframe src="Sample2.html" name="frm" width=100 height=100 />
</BODY>
</HTML>
Sample2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
function called(){
alert("---DONE--");
}
</script>
<BODY>
<input type="button" name="but" value="submit" id="but" width=60 height=60 onclick="called()" />
</BODY>
</HTML>
Hope this helps you.

Categories