I'm trying to convert single asp.net page to pdf. Based on my research, most of people said that it can be done using wkhtmltopdf<pre lang="text"></pre>
I've downloded the wkhtmltox0.dll from here http://code.google.com/p/wkhtmltopdf/downloads/list . I am working in asp.net and i can't find any example of how to use it!
Does anybody can provide me an example?
I tried with itextsharp dll but that doesjnt support css and many so i switched to this ..
I will show you what i tried so for with both possibilities
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ObjectivesPdfDocument.ascx.cs" Inherits="ActusAppraisalSystem.Controls.ObjectivesPdfDocument" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<link href="../css/reporttablestyle.css" rel="stylesheet" type="text/css" />
<link href="../../css/chosen.css" rel="stylesheet" />
<script src="../../js/jquery-1.10.2.js"></script>
<script src="../../js/chosen.jquery.js"></script>
<h2>
<img alt="" src="../../logos/20130305120113.jpg" />
</h2>
<div class="FrameWrapper frameheight" id="pnlPerson" runat="server">
<div class="ObjectiveWrapper">
<div class="Form_Wrap_Left">
<div class="form_lft_inner" id="divCompany" runat="server">
<div class="TwoColumn_Form_Wrap_Lft">
Objectives Report
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
<div class="form_lft_inner">
<div class="TwoColumn_Form_Wrap_Lft">
Michael O’Sullivan
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
<div class="form_lft_inner" runat="server" id="divManager">
<div class="TwoColumn_Form_Wrap_Lft">
Manager: Lucinda Carney
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
</div>
<div class="Form_Wrap_Right">
<div class="Form_rght_inner">
<div class="TwoColumn_Form_Wrap_Lft">
20013/14 {in Arial Bold 14pts}
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
<div class="Form_rght_inner">
<div class="TwoColumn_Form_Wrap_Lft">
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
<div class="Form_rght_inner">
<div class="TwoColumn_Form_Wrap_Lft">
</div>
<div class="TwoColumn_Form_Wrap_Rht">
</div>
</div>
</div>
<div style="clear: both;"> </div>
[Objective Title] [Status] [Target Date] {all in Arial Bold 12pts}<br />
<br />
<%----%>
<table id="Panel3" runat="server" style="border:dotted;height:101px;width:619px;border-style:solid;border-color:black">
<tr>
<th>This field should contain all of the text from the [Define Objective] field it should be in Arial size 11 font; left aligned. I would like a thin line around the text as shown. Can this box be a flexible size depending on the amount of text in the ‘define objective’ field – or do we need to make it a fixed size?
</th>
</tr>
</table>
<br />
<strong>Milestones</strong>
<br />
<br />
[Date of 1st milestone] [text from 1st Milestone……….]<br />
<br />
[Date of 2nd milestone] [text from 2nd Milestone……….]<br />
<br />
[Date of 3rd milestone etc etc] [text from 3rd Milestone……….]<br />
<br />
<strong>Comments</strong><br />
<br />
[Date of 1st comment] [text from 1st comment….]<br />
<br />
[Date of 2nd comment] [text from 2nd comment….]<br />
<br />
<strong>Completion Review<br />
<br />
<asp:Panel ID="Panel2" runat="server" Height="101px" Width="619px" BorderStyle="Solid" BorderColor="Black">
This field should contain all of the text from the [Define Objective] field it should be in Arial size 11 font; left aligned. I would like a thin line around the text as shown. Can this box be a flexible size depending on the amount of text in the ‘define objective’ field – or do we need to make it a fixed size?
</asp:Panel>
</strong>
<br />
<div runat="server" id="div2">
<a href="#item1">
<asp:Button ID="btnExportToExcel" runat="server" Text="Export To Excel" CssClass="BtnRegular_Popup" OnClick="btnExportToExcel_Click" Style="margin-bottom: 15px;" />
</a>
</div>
<div style="clear: both; margin: 0px 0px 10px 0px">
</div>
<div class="ErrorSuccesmsg">
<asp:Label ID="lblMessage" runat="server" EnableViewState="false"></asp:Label>
</div>
</div>
</div
>
my code behind code :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using ActusLibrary.Utils;
using System.Text;
using System.Globalization;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.IO;
using System.Web;
using System.Diagnostics;
namespace ActusAppraisalSystem.Controls
{
public partial class ObjectivesPdfDocument : System.Web.UI.UserControl
{
#region PageLevelEvents
protected void Page_Load(object sender, EventArgs e)
{
Page.Header.Title = "Reports";
}
#endregion
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
Way1();
Way2();
}
private void Way2()
{
string myDocumentsPath = "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe ";
ProcessStartInfo psi = new ProcessStartInfo(myDocumentsPath, "./User/PerformancePDF.aspx");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
Process myProcess = Process.Start(psi);
myProcess.WaitForExit();
myProcess.Close();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=abc.pdf");
Response.ContentType = "application/pdf";
Response.WriteFile("D:\\bb.pdf");
Response.End();
}
private void Way1()
{
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
//StringWriter sw = new StringWriter();
//HtmlTextWriter hw = new HtmlTextWriter(sw);
//this.Page.RenderControl(hw);
//StringReader sr = new StringReader(sw.ToString());
//Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
//HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
//PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
//pdfDoc.Open();
//htmlparser.Parse(sr);
//pdfDoc.Close();
//Response.Write(pdfDoc);
//Response.End();
}
}
}