应用外部样式表从HTML生成PDF [英] Generating PDF from HTML applying external Stylesheet

查看:58
本文介绍了应用外部样式表从HTML生成PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个asp.net应用程序,我需要生成一个网页Aspx / Html的pdf文档,我能够生成pdf文档,但问题是我的样式表未应用于此pdf文档



请在下面找到我的努力



(1)myxyz.css



  body  {
margin 0;
width 100%;
height 100%;

}
page
{

width 970px;
border 1px#E4E3E3 solid;
display table;
height 700px;
margin auto;
font-family Arial,Helvetica,sans-serif;


}
header
{
width 960px;
保证金 auto;
padding-bottom 15px;
border-bottom 1px#E4E3E3 solid;
display table;
}
headerLeftPart
{
padding-left < span class =code-keyword>: 10px;
float < span class =code-keyword>: left;
}
headerLeftPart h4
{
font-size 14pt;

}
headeraddresspan {
width 250px;
自动换行 break-word;
display block;
text-align < span class =code-keyword> left;
margin-top -15px;
font-size 12pt;
}
headerRightPart
{
float 正确;
}
headercontact {

宽度 310px;
margin-top 50px;
float right;
}
headercontactspan {

width 310px;
float right;
display block;
}
footer {

height 130px;
width 970px;
margin auto;
padding-top 50px ;
clear 两者;
display block ;

}
footerleft {
padding 10px;
宽度 350px;
float left;
显示 block;

}
footerleft span
{
显示 block;
float left;
width 350px;
padding 8px;
font-weight 粗体;
}
footerright {

width 350px;
float 右;
display 阻止;

}
footerright span
{
display block;
float right;
width 250px;
padding 8px;
font-weight 粗体;
}
内容 {
padding 6px;
padding-left 15px;
padding-top 15px;
}
section {

width 960px;
margin auto;
float left;
padding-left 5px;
padding-right 5px;
显示 block;
}
sectionhead {
}
sectionhead h4 {
font-size 14pt;
font-weight 粗体;
text-decoration 下划线;
display block;
}
inlinesectionhead {
font-size 14pt;
font-weight bold;
text-decoration 下划线;
display block ;
float left;

}
sectioncontent {
font-size 12pt;
}
sectioncontentinlinewrap {
padding-top 15px;

}
inlinesectionContent {
font-size 12pt;
float 左;
显示 阻止;
padding-left 15px;
margin-top 3px;
自动换行 break-word;

}
sectioncontent p {

自动换行 break-word;
padding-left 28px;
}
sectioncontent ul {

padding-left 40px;
}
sectioncontent ul > li {
自动换行 < span class =code-keyword> break-word;
}
sectiontable {
width 940px;
margin auto;
border 1px black solid;
}
sectiontable tr td th {
border border:1px black solid; ;
border-collapse 分开;
margin auto;
border 1px black solid;
text-align 中心;
}
inlinepara {
text-indent 30px;
text-对齐 对齐;
padding-right 30px;
}
paddresspara {
padding -left 0px !important ;
margin-top -14px;
}
projecthead {
float left;
display block;
font-weight 粗体;
}
projectpara {
padding-left 0px !important ;

}

projectcontent {
clear both;
width 960px;
padding-top 10px;
clear both;
}
projetcs {
clear both;
width 960px;
margin-top - 20px;
}
kutchdialstrip {
width 960px;
text-align center;
font-size 11px;
clear both;
}
/ * 打印设置* /

@ page
{
size auto ; / * auto是初始值* /
边距 0mm; / * 这会影响打印机设置中的边距* /
}

/ * 打印设置结束* /







(2)myxyz.aspx / html



 <  !DOCTYPE     html  >  
< html xmlns = < span class =code-k eyword> http://www.w3.org/1999/xhtml >
< head >
< title > < ; / title >
< link href = ../../ css / Jobseeker / resumstyle.css rel = 样式表 / >
< / head >
< body > ;
< div class = page >
< div class = 标题 >
< < span class =code-leadattribute> div
class = headerLeftPart > ;
< h4 > PRADEEP CHANDRAN < / h4 >
< span class = headeraddresspan >
Qtr No:F18,Aramji Society,
Evani Avas,Sector-11,
Moran- 370001,
ABC,印度
< / span >
< / div >
< < span class =code-leadattribute> div class = headerRightPart >
< div class = headercontact >
< span class = headercontactspan > 电话:+91 963834000X < / span >
< span class = headercontactspan > 电子邮件:gpxyzmjguj000582@gmail.com < / span >
< / div >
< /格 >

< / div >
< div class = content >
< div class = section >
< div class = sectionhead > < h4 > 目标:< / h4 > < / div >
< div class = sectioncontent >
< p >
要获得铁杆体验,请放大我的知识,保持与组织的关系,也有增长。
< / p >
< / div >
< / div >
< div class = section >
< div class = sectionhead < span class =code-keyword>>
< h4 > 个人资料摘要:< / h4 > < / div >
< div class = sectioncontent >
< ul >
< li > 我自2007年12月起与JCPL(NIIT特许经营商)合作,担任Microsoft .Net的培训师< / li >
< li > 2011年11月,升任NIIT集团负责人,同时任命与微软合作开发团队。 Stringz Solutions的网络开发人员是JCPL的姐妹关注点。< / li >
< li > 2014年1月离开NIIT并担任Stringz Solutions的Microsoft .Net开发人员,这是JCPL的姐妹关注点。< / li >

< < span class =code-leadattribute> / ul >
< p class = inlinepara >
我的技术专长是.NET,Microsoft SQL-Server 2005,并且还精通编写程序,函数和数据库触发器以及日常数据库维护活动。我还参与了客户会议,需求收集和分析。
< / p >
< / div >
< / div >
< div class = section>
<div class=\"sectionhead\"< span class=\"code-keyword\">><h4>IT / Computer Skills :</h4></div>
<div class=\"sectioncontent\">
<table class=\"sectiontable\" cellspacing=\"0\">
<tr>
<th>Skill</th>
<th>Experience</th>
<th>Last Used</th>

</tr>
<tr>
<td>HTML - Markup Language</td>
<td>2.5 years<
/td>
<td>2010</td>

</tr>
<tr>
<td>HTML - Markup Language</td>
<td>2.5 years</td>
<td>2010</td>
</tr>
<tr>
<td>HTML - Markup Language</td>
<td>2.5 years</td>
<td>2010</td>
</tr>
<tr>
<td>HTML - Markup Language</td>
<td>2.5 years</td>
<td>2010</td>
</tr>
</table>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"><h4>Educational Qualification :</h4></div>
<div class=\"sectioncontent\">
<table class=\"sectiontable\" cellspacing=\"0\">
<tr>
<th>Qualification</th>
<th>University/Board</th>
<th>Percentage/Grade</th>
<th>Year</th>
</tr>
<tr>
<td>Bachelor of Information Tec hnology </td>
<td>GSHEB</td>
<td>71.57</td>
<td>2005</td>
</tr>
<tr>
<td>Bachelor of Information Technology</td>
<td>GSHEB</td>
<td> ;71.57</td>
<td>2005</td>
</tr>
<tr>
<td>Bachelor of Information Technology</td>
<td>GSHEB</td>
<td>71.57</td>
<td>2005</td>
</tr&g t;
<tr>
<td>Bachelor of Information Technology</td>
<td>GSHEB</td>
<td>71.57</td>
<td>2005</td>
</tr>
</table>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"><h4>Achivements :</h4></div>
<div class=\"sectioncontent\">
<ul>
<li>Consolidated four accounting offices into one location, resulting in greater efficiency, streamlined operations and savings of over $500K in payroll alone.</li>
<li>Implemented new travel policy with effective controls, resulting in greater efficiency and consiste ncy in travel planning and a $100K reduction in costs.</li>
<li>Directed an exhaustive search for new office space, negotiated lease agreements and secured sub-tenants in two locations, resulting in savings of $2.5M.</li>

</ul>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"><h4>Representative Projects:</h4> </div>
<div class=\"projetcs\">
<div class=\"projectcontent\">
<span class=\"projecthead\">Systems Engineering:&l t;/span>
<span class=\"projectpara\">Led design and multinational rollout of robust, scalable and secure electronic data interchange (EDI), enterprise resource planning (ERP) and point-of-sale (POS) systems for clients including AmEx, Citigroup and McDonald’s.</span>
</div>
<div class=\"projectcontent\">
<span class=\"projecthead\">Database Developments:</span>
<span class=\"projectpara\">Guided teams in the development of relational database management systems (RDBMS) for clients including Coca-Cola, Caterpillar and Allied Waste Industries.</span>
</div>
<div class=\"projectcontent\">
<span class=\"projecthead\"< span class=\"code-keyword\">>System Integrations/Migrations:</span>
<span class=\"projectpara\">
Project-managed large-scale initiatives involving the transition of programs to new platforms and the merger of disparate systems from acquired client companies.
Results: Achieved seamless migrations and integrations that were transparent to client customers, accomplished with no unscheduled downtime and delivered by as much as $750K under budget.
</span>
</div>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"><h4> Permanent Address: </h4></div>
<div class=\"sectioncontent\">
<p class=\"paddresspara\">
Qtr No: F18, Aramjinagar Society,
Evani Avas , Sector-11,
Mora- 370801,
ABC,India
</p>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"></div>
<div class=\"sectioncontent sectioncontentinlinewrap\">
<span
class=\"inlinesectionhead\">Current Location</span>
<span class=\"inlinesectionContent\">Mora ,Gujarat, India</span>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"></div>
<div class =\"sectioncontent sectioncontentinlinewrap\">
<span class=\"inlinesectionhead\">Current CTC</span>
<span class=\"inlinesectionContent\">25000/p.m</span >
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"></div>
<div class=\"sectioncontent sectioncontentinlinewrap\">
<span class=\"inlinesectionhead\">Languages Known</span>
<span class=\"inlinesectionContent\">English,Hindi,Gujarati</span>
</div>
</div>

</div>
<div class=\"footer\">
<hr />
<div class=\"footerleft\">
<span>Place: </span>
<span>Date: <
/span>
</div>
<div class=\"footerright\">
<span>Signature: </span>
<span>Name: </span>
</div>
<div class=\"kutchdialstrip\">
<hr />
my copyright text

</div>
</div>
</div>
</body>
</html>





(3) C# Code

  try 
{
string strHtml = string.Empty;
string pdfFileName = HttpContext.Current.Request.PhysicalApplicationPath + \"Media\\files\\xyz\\\" + \"GenerateHTMLTOPDF.pdf\";

StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
dvHtml.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
strHtml = sr.ReadToEnd();
sr.Close();

CreatePDFFromHTMLFile(strHtml, pdfFileName);

HttpContext.Current.Response.ContentType = \"application/x-download\";
HttpContext.Current.Response.AddHeader(\"Content-Disposition\", string.Format(\"attachment; filename=\\"{0}\\"\", \"GenerateHTMLTOPDF.pdf\"));
HttpContext.Current.Response.WriteFile(pdfFileName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}


public static void CreatePDFFromHTMLFile(string HtmlStream, string FileName)
{
try
{
object TargetFile = FileName;
string ModifiedFileName = string.Empty;
string FinalFileName = string.Empty;

// HtmlStream = HtmlStream.Replace(\"\r\n\", \"\");

GeneratePDF.HtmlToPdfBuilder builder = new GeneratePDF.HtmlToPdfBuilder(iTextSharp.text.PageSize.A4);

GeneratePDF.HtmlPdfPage first = builder.AddPage();
first.AppendHtml(HtmlStream);
builder.ImportStylesheet(HttpContext.Current.Request.PhysicalApplicationPath + \"CSS\\myxyz.css\");
byte[] file = builder.RenderPdf();
File.WriteAllBytes(TargetFile.ToString(), file);

iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(TargetFile.ToString());
ModifiedFileName = TargetFile.ToString();
ModifiedFileName = ModifiedFileName.Insert(ModifiedFileName.Length - 4, \"1\");

iTextSharp.text.pdf.PdfEncryptor.Encrypt(reader, new FileStream(ModifiedFileName, FileMode.Append), iTextSharp.text.pdf.PdfWriter.STRENGTH128BITS, \"\", \"\", iTextSharp.text.pdf.PdfWriter.AllowPrinting);
reader.Close();
if (File.Exists(TargetFile.ToString()))
File.Delete(TargetFile.ToString());
FinalFileName = ModifiedFileName.Remove(ModifiedFileName.Length - 5, 1);
File.Copy(ModifiedFileName, FinalFileName);
if (File.Exists(ModifiedFileName))
File.Delete(ModifiedFileName);

}
catch (例外情况)
{
抛出 ex;
}
}

解决方案

500K in payroll alone.</li>
<li>Implemented new travel policy with effective controls, resulting in greater efficiency and consistency in travel planning and a


100K reduction in costs.</li>
<li>Directed an exhaustive search for new office space, negotiated lease agreements and secured sub-tenants in two locations, resulting in savings of


2.5M.</li>

</ul>
</div>
</div>
<div class=\"section\">
<div class=\"sectionhead\"><h4>Representative Projects:</h4> </div>
<div class=\"projetcs\">
<div class=\"projectcontent\">
<span class=\"projecthead\">Systems Engineering:</span>
<span class=\"projectpara\">Led design and multinational rollout of robust, scalable a nd secure electronic data interchange (EDI), enterprise resource planning (ERP) and point-of-sale (POS) systems for clients including AmEx, Citigroup and McDonald’s.</span>
</div>
<div class=\"projectcontent\">
<span class=\"projecthead\">Database Developments:</span>
<span class=\"projectpara\">Guided teams in the development of relational database management systems (RDBMS) for clients including Coca-Cola, Caterpillar and Allied Waste Industries.</span>
</div>
<div class=\"projectcontent\">
<span class=\"projecthead\">System Integrations/Migrations:</span>
<span class=\"projectpara\">
Project-managed large-scale initiatives involving the transition of programs to new platforms and the merger of disparate systems from acquired client companies.
Results: Achieved seamless migrations and integrations that were transparent to client customers, accomplished with no unscheduled downtime and delivered by as much as


i am developing an asp.net application where in i need to generate a pdf document of web page Aspx/Html , i was able to generate pdf document but the issue is my stylesheet is not getting applied to this pdf document

please find my effort below

(1) myxyz.css

body {
    margin:0;
    width: 100%;
    height:100%;

}
.page
{

    width:970px;
    border:1px #E4E3E3 solid;
    display:table;
    height:700px;
    margin:auto;
    font-family:Arial, Helvetica, sans-serif;


}
.header
{
    width:960px;
    margin:auto;
    padding-bottom:15px;
    border-bottom:1px #E4E3E3 solid;
    display:table;
}
.headerLeftPart
{
    padding-left:10px;
    float:left;
}
.headerLeftPart h4
{
 font-size:14pt;

}
.headeraddresspan{
    width:250px;
    word-wrap:break-word;
    display:block;
    text-align:left;
    margin-top: -15px;
    font-size:12pt;
}
.headerRightPart
{
    float:right;
}
.headercontact {

    width:310px;
    margin-top:50px;
    float:right;
}
.headercontactspan {

    width:310px;
    float:right;
    display:block;
}
.footer {

     height:130px;
     width:970px;
     margin:auto;
     padding-top:50px;
     clear:both;
     display:block;

}
.footerleft {
    padding:10px;
    width:350px;
    float:left;
    display:block;

}
.footerleft span
{
    display:block;
    float:left;
    width:350px;
    padding:8px;
    font-weight:bold;
}
.footerright {

    width:350px;
    float:right;
    display:block;

}
.footerright span
{
    display:block;
    float:right;
    width:250px;
    padding:8px;
    font-weight:bold;
}
.content {
    padding:6px;
    padding-left:15px;
    padding-top:15px;
}
.section {

    width:960px;
    margin:auto;
    float:left;
    padding-left:5px;
    padding-right:5px;
    display:block;
}
.sectionhead {
}
.sectionhead h4{
    font-size:14pt;
    font-weight:bold;
    text-decoration:underline;
    display:block;
}
.inlinesectionhead{
    font-size:14pt;
    font-weight:bold;
    text-decoration:underline;
    display:block;
    float:left;

}
.sectioncontent {
    font-size:12pt;
}
.sectioncontentinlinewrap {
    padding-top:15px;

}
.inlinesectionContent {
    font-size:12pt;
    float:left;
    display:block;
    padding-left:15px;
    margin-top: 3px;
    word-wrap:break-word;

}
    .sectioncontent p {

        word-wrap:break-word;
        padding-left:28px;
    }
     .sectioncontent ul {

        padding-left:40px;
    }
    .sectioncontent ul > li {
            word-wrap:break-word;
        }
    .sectiontable {
        width:940px;
        margin:auto;
        border:1px black solid;
    }
     .sectiontable  tr , td , th {
        border: border:1px black solid;;
        border-collapse:separate;
        margin:auto;
        border:1px black solid;
        text-align:center;
    }
.inlinepara {
    text-indent:30px;
    text-align:justify;
     padding-right:30px;
}
.paddresspara {
    padding-left:0px !important;
    margin-top: -14px;
}
.projecthead {
    float:left;
    display:block;
    font-weight:bold;
}
.projectpara {
    padding-left:0px !important;

}

.projectcontent {
    clear:both;
    width:960px;
    padding-top:10px;
    clear:both;
}
.projetcs {
   clear:both;
   width:960px;
   margin-top:-20px;
}
.kutchdialstrip {
    width:960px;
    text-align:center;
    font-size:11px;
    clear:both;
}
/*print settings*/

@page
    {
        size: auto;   /* auto is the initial value */
        margin: 0mm;  /* this affects the margin in the printer settings */
    }

/*print settings ends*/




(2) myxyz.aspx/html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../css/Jobseeker/resumstyle.css" rel="stylesheet" />
</head>
<body>
        <div class="page">
            <div class="header">
                <div class="headerLeftPart">
                    <h4>PRADEEP CHANDRAN</h4>
                    <span class="headeraddresspan">
                        Qtr No: F18, Aramji Society,
                        Evani Avas , Sector-11,
                        Moran- 370001,
                        ABC,India
                    </span>
                </div>
                <div class="headerRightPart">
                    <div class="headercontact">
                        <span class="headercontactspan">Phone : +91 963834000X </span>
                        <span class="headercontactspan">Email: gpxyzmjguj000582@gmail.com</span>
                    </div>
                </div>

            </div>
            <div class="content">
                <div class="section">
                    <div class="sectionhead"><h4>Objective :</h4></div>
                    <div class="sectioncontent">
                        <p>
                            To have a hardcore experience, enlarge my knowledge, maintain long term relationship with the organization and also to have growth.
                        </p>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4>Profile Summary:</h4></div>
                    <div class="sectioncontent">
                        <ul>
                            <li>I was working with JCPL (Franchisee of NIIT) since December, 2007, as Trainer in Microsoft .Net</li>
                            <li>Nov, 2011, Promoted as Group Leader of NIIT, Simultaneously appointed to work with development team as Microsoft .Net developer for Stringz Solutions a sister concern of JCPL.</li>
                            <li>Jan, 2014, left NIIT and working as Microsoft .Net developer for Stringz Solutions a sister concern of JCPL.</li>

                        </ul>
                        <p class="inlinepara">
                            My technological forte is .NET, Microsoft SQL-Server 2005 and also proficient in writing Procedures, Functions and Database Triggers with day to day database maintenance activity. I am also involved in Client Meeting, Requirement Gathering and Analysis.
                        </p>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4>IT / Computer Skills :</h4></div>
                    <div class="sectioncontent">
                        <table class="sectiontable" cellspacing="0">
                            <tr>
                                <th>Skill</th>
                                <th>Experience</th>
                                <th>Last Used</th>

                            </tr>
                            <tr>
                                <td>HTML - Markup Language</td>
                                <td>2.5 years</td>
                                <td>2010</td>

                            </tr>
                            <tr>
                                <td>HTML - Markup Language</td>
                                <td>2.5 years</td>
                                <td>2010</td>
                            </tr>
                            <tr>
                                <td>HTML - Markup Language</td>
                                <td>2.5 years</td>
                                <td>2010</td>
                            </tr>
                            <tr>
                                <td>HTML - Markup Language</td>
                                <td>2.5 years</td>
                                <td>2010</td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4>Educational Qualification :</h4></div>
                    <div class="sectioncontent">
                       <table class="sectiontable" cellspacing="0">
                           <tr>
                               <th>Qualification</th>
                               <th>University/Board</th>
                               <th>Percentage/Grade</th>
                               <th>Year</th>
                           </tr>
                           <tr>
                               <td>Bachelor of Information Technology </td>
                               <td>GSHEB</td>
                               <td>71.57</td>
                               <td>2005</td>
                           </tr>
                           <tr>
                               <td>Bachelor of Information Technology</td>
                               <td>GSHEB</td>
                               <td>71.57</td>
                               <td>2005</td>
                           </tr>
                           <tr>
                               <td>Bachelor of Information Technology</td>
                               <td>GSHEB</td>
                               <td>71.57</td>
                               <td>2005</td>
                           </tr>
                           <tr>
                               <td>Bachelor of Information Technology</td>
                               <td>GSHEB</td>
                               <td>71.57</td>
                               <td>2005</td>
                           </tr>
                       </table>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4>Achivements :</h4></div>
                    <div class="sectioncontent">
                        <ul>
                            <li>Consolidated four accounting offices into one location, resulting in greater efficiency, streamlined operations and savings of over $500K in payroll alone.</li>
                            <li>Implemented new travel policy with effective controls, resulting in greater efficiency and consistency in travel planning and a $100K reduction in costs.</li>
                            <li>Directed an exhaustive search for new office space, negotiated lease agreements and secured sub-tenants in two locations, resulting in savings of $2.5M.</li>

                        </ul>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4>Representative Projects:</h4> </div>
                    <div class="projetcs">
                        <div class="projectcontent">
                            <span class="projecthead">Systems Engineering:</span>
                            <span class="projectpara">Led design and multinational rollout of robust, scalable and secure electronic data interchange (EDI), enterprise resource planning (ERP) and point-of-sale (POS) systems for clients including AmEx, Citigroup and McDonald’s.</span>
                        </div>
                        <div class="projectcontent">
                            <span class="projecthead">Database Developments:</span>
                            <span class="projectpara">Guided teams in the development of relational database management systems (RDBMS) for clients including Coca-Cola, Caterpillar and Allied Waste Industries.</span>
                        </div>
                        <div class="projectcontent">
                            <span class="projecthead">System Integrations/Migrations:</span>
                            <span class="projectpara">
                                Project-managed large-scale initiatives involving the transition of programs to new platforms and the merger of disparate systems from acquired client companies.
                                Results: Achieved seamless migrations and integrations that were transparent to client customers, accomplished with no unscheduled downtime and delivered by as much as $750K under budget.
                            </span>
                        </div>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"><h4> Permanent Address: </h4></div>
                    <div class="sectioncontent">
                        <p class="paddresspara">
                            Qtr No: F18, Aramjinagar Society,
                            Evani Avas , Sector-11,
                            Mora- 370801,
                            ABC,India
                        </p>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"></div>
                    <div class="sectioncontent sectioncontentinlinewrap">
                        <span class="inlinesectionhead">Current Location</span>
                        <span class="inlinesectionContent">Mora ,Gujarat, India</span>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"></div>
                    <div class="sectioncontent sectioncontentinlinewrap">
                        <span class="inlinesectionhead">Current CTC</span>
                        <span class="inlinesectionContent">25000/p.m</span>
                    </div>
                </div>
                <div class="section">
                    <div class="sectionhead"></div>
                    <div class="sectioncontent sectioncontentinlinewrap">
                        <span class="inlinesectionhead">Languages Known</span>
                        <span class="inlinesectionContent">English,Hindi,Gujarati</span>
                    </div>
                </div>

            </div>
            <div class="footer">
                <hr />
                <div class="footerleft">
                    <span>Place: </span>
                    <span>Date: </span>
                </div>
                <div class="footerright">
                    <span>Signature: </span>
                    <span>Name: </span>
                </div>
                <div class="kutchdialstrip">
                    <hr />
                    my copyright text

                </div>
            </div>
        </div>
</body>
</html>



(3) C# Code

  try
       {
           string strHtml = string.Empty;
           string pdfFileName = HttpContext.Current.Request.PhysicalApplicationPath + "Media\\files\\xyz\\" + "GenerateHTMLTOPDF.pdf";

           StringWriter sw = new StringWriter();
           HtmlTextWriter hw = new HtmlTextWriter(sw);
           dvHtml.RenderControl(hw);
           StringReader sr = new StringReader(sw.ToString());
           strHtml = sr.ReadToEnd();
           sr.Close();

           CreatePDFFromHTMLFile(strHtml, pdfFileName);

           HttpContext.Current.Response.ContentType = "application/x-download";
           HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", "GenerateHTMLTOPDF.pdf"));
           HttpContext.Current.Response.WriteFile(pdfFileName);
           HttpContext.Current.Response.Flush();
           HttpContext.Current.Response.End();
       }
       catch (Exception ex)
       {
           HttpContext.Current.Response.Write(ex.Message);
       }


public static void CreatePDFFromHTMLFile(string HtmlStream, string FileName)
   {
       try
       {
           object TargetFile = FileName;
           string ModifiedFileName = string.Empty;
           string FinalFileName = string.Empty;

          // HtmlStream = HtmlStream.Replace("\r\n", "");

           GeneratePDF.HtmlToPdfBuilder builder = new GeneratePDF.HtmlToPdfBuilder(iTextSharp.text.PageSize.A4);

           GeneratePDF.HtmlPdfPage first = builder.AddPage();
           first.AppendHtml(HtmlStream);
           builder.ImportStylesheet(HttpContext.Current.Request.PhysicalApplicationPath + "CSS\\myxyz.css");
           byte[] file = builder.RenderPdf();
           File.WriteAllBytes(TargetFile.ToString(), file);

           iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(TargetFile.ToString());
           ModifiedFileName = TargetFile.ToString();
           ModifiedFileName = ModifiedFileName.Insert(ModifiedFileName.Length - 4, "1");

           iTextSharp.text.pdf.PdfEncryptor.Encrypt(reader, new FileStream(ModifiedFileName, FileMode.Append), iTextSharp.text.pdf.PdfWriter.STRENGTH128BITS, "", "", iTextSharp.text.pdf.PdfWriter.AllowPrinting);
           reader.Close();
           if (File.Exists(TargetFile.ToString()))
               File.Delete(TargetFile.ToString());
           FinalFileName = ModifiedFileName.Remove(ModifiedFileName.Length - 5, 1);
           File.Copy(ModifiedFileName, FinalFileName);
           if (File.Exists(ModifiedFileName))
               File.Delete(ModifiedFileName);

       }
       catch (Exception ex)
       {
           throw ex;
       }
   }

解决方案

500K in payroll alone.</li> <li>Implemented new travel policy with effective controls, resulting in greater efficiency and consistency in travel planning and a


100K reduction in costs.</li> <li>Directed an exhaustive search for new office space, negotiated lease agreements and secured sub-tenants in two locations, resulting in savings of


2.5M.</li> </ul> </div> </div> <div class="section"> <div class="sectionhead"><h4>Representative Projects:</h4> </div> <div class="projetcs"> <div class="projectcontent"> <span class="projecthead">Systems Engineering:</span> <span class="projectpara">Led design and multinational rollout of robust, scalable and secure electronic data interchange (EDI), enterprise resource planning (ERP) and point-of-sale (POS) systems for clients including AmEx, Citigroup and McDonald’s.</span> </div> <div class="projectcontent"> <span class="projecthead">Database Developments:</span> <span class="projectpara">Guided teams in the development of relational database management systems (RDBMS) for clients including Coca-Cola, Caterpillar and Allied Waste Industries.</span> </div> <div class="projectcontent"> <span class="projecthead">System Integrations/Migrations:</span> <span class="projectpara"> Project-managed large-scale initiatives involving the transition of programs to new platforms and the merger of disparate systems from acquired client companies. Results: Achieved seamless migrations and integrations that were transparent to client customers, accomplished with no unscheduled downtime and delivered by as much as


这篇关于应用外部样式表从HTML生成PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆