【发布时间】:2014-05-14 07:08:24
【问题描述】:
我正在使用 Itextsharp 将 html 转换为 pdf。我的 html 使用框架和 css。主页是 ConvertHTMLToPDF.htm,它使用 frame1.htm、frame2.htm 和文件 style.css。我正在使用 Itextsharp 将此 html 页面转换为 pdf。虽然我能够将 html 转换为 pdf,但它只是将我的 ConvertHTMLToPDF.htm 转换为 pdf。关联的 frame1.htm ,frame2.htm 和 style.css 没有嵌入到 pdf 文件中。
////////////////File name: ConvertHTMLToPDF.htm
<html>
<head><title>Simple Web Page Using 2 Frames (Main Page)</title>
</head>
<frameset cols="20%, *">
<frame src="frame1.htm" name="contents" noresize>
<frame src="frame2.htm" name="pageinfo" noresize>
<noframes>
<body>
This web page is constructed using frames.
Your web browser does not support frames.
Seek, nonframes version.
</body>
</noframes>
</frameset>
</html>
-----------------------------------------------------------------
////////////////File name: frame1.htm
<html>
<head><title>Left Pane (frame1.htm)</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#FF0000">
<h3>Page Contents</h3>
<br>
<h5>
Link 1<br><br>
Link 2<br><br>
Link 3<br><br>
Link 4<br><br>
</h5>
</body>
</html>
-----------------------------------------------------------------
////////////////File name: frame2.htm
<html>
<head><title>Right Pane (frame2.htm)</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#FF0000">
<h3 align="center">Information Page</h3>
<br>
<h5>Welcome. Here you can find....</h5>
</body>
</html>
/////////////////////////File name: frame1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<H1>Hi this is ANIKET !!!<H1>
<H2>This example is for converting pdf to word </H2>
</body>
</html>
/////////////////file name: style.css
p{ line-height: 1em; }
h1, h2, h3, h4{
color: orange;
font-weight: normal;
line-height: 1.1em;
margin: 0 0 .5em 0;
}
h1{ font-size: 1.7em; }
h2{ font-size: 1.5em; }
a{
color: black;
text-decoration: none;
}
a:hover,
a:active{ text-decoration: underline; }
/* you can structure your code's white space so that it is as readable for when you come back in the future or for other people to read and edit quickly */
body{
font-family: arial; font-size: 80%; line-height: 1.2em; width: 100%; margin: 0; background: #eee;
}
/* you can put your code all in one line like above */
#page{ margin: 20px; }
/* or on different lines like below */
#logo{
width: 35%;
margin-top: 5px;
font-family: georgia;
display: inline-block;
}
/* but try and be as concise as possible */
#nav{
width: 60%;
display: inline-block;
text-align: right;
float: right;
}
#nav ul{}
#nav ul li{
display: inline-block;
height: 62px;
}
#nav ul li a{
padding: 20px;
background: orange;
color: white;
}
#nav ul li a:hover{
background-color: #ffb424;
box-shadow: 0px 1px 1px #666;
}
#nav ul li a:active{ background-color: #ff8f00; }
#content{
margin: 30px 0;
background: white;
padding: 20px;
clear: both;
}
#footer{
border-bottom: 1px #ccc solid;
margin-bottom: 10px;
}
#footer p{
text-align: right;
text-transform: uppercase;
font-size: 80%;
color: grey;
}
/* multiple styles seperated by a , */
#content,
ul li a{ box-shadow: 0px 1px 1px #999;
}
【问题讨论】:
-
您使用的是不受支持且已弃用的
HTMLWorker还是受支持的XMLWorker?如果是前者,你应该升级到后者。前者对 HTML 和 CSS 有非常基本的支持,而后者则更高级。XMLWorker知道frame和iframe标签,甚至将它们放在名为EMBEDDED_CONTENT的集合中,但目前似乎没有使用这些标签,因此不受支持。 -
是的,我用过XmlWorker。但我不知道我错在哪里......
标签: html asp.net c#-4.0 itextsharp