wkhtmltopdf ASP.NET自定义标头

问题描述:

Hii,



我正在使用wkhtmltopdf将我的html页面转换为pdf。



我把在我的html文件中将图像作为我的标题。但是当数据很大并且将PDF格式转换为几页后。



我的标题徽标仅出现在第一页上。



有没有办法在我的案例中修改公司徽标的所有页面中的标题..所以即使数据很大并且在转换后它会分成多个页面,我想有每个页面的标题..我的图像标志。



贝洛是我到目前为止尝试的代码..



Hii ,

I am converting my html pages to pdf using wkhtmltopdf.

I put image as my header in my html file.But when data is large and after converting the pdf breaks down into few pages.

My header logo comes only on first page.

Is there any way to fix the header throughout all the pages in my case the company logo .. so even if data is large and after converting it splits down into multiple pages , i would like to have header for each page.. my image logo.

Belo is my code i tried so far ..

protected void btnExportToExcel_Click(object sender, EventArgs e)
       {
           WorkingWay3();
       }

       private void WorkingWay3()
       {
           string pdfExportPath = profile + ApConfig.CurrentCompany.CompId + "/" + ApConfig.CurrentUser.EmpId.ToString();

           if (!Directory.Exists(Server.MapPath(pdfExportPath)))
           {
               Directory.CreateDirectory(Server.MapPath(pdfExportPath));
           }
           else
           {
               pdfExportPath = pdfExportPath + "/Objectives.pdf";
           }

           string objpath = Server.MapPath(pdfExportPath);

           HtmlToPdf("http://localhost:32370/User/PerformancePDF.aspx", @"D:/Projects/New.pdf");

           Response.Clear();
           Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");
           Response.ContentType = "application/zip";
           objZip.Save(Response.OutputStream);
           Response.End();
       }

       private void HtmlToPdf(string website, string destinationFile)
       {

           ProcessStartInfo startInfo = new ProcessStartInfo();

           startInfo.UseShellExecute = false;

           startInfo.RedirectStandardOutput = true;

           startInfo.RedirectStandardInput = true;

           startInfo.RedirectStandardError = true;

           startInfo.CreateNoWindow = true;

           startInfo.FileName = "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe";
           startInfo.Arguments = website + " " + destinationFile;
           Process myProcess = Process.Start(startInfo);
           myProcess.WaitForExit();
           myProcess.Close();
           objZip.AddFile(destinationFile, "Files");
       }

<pre lang="c#"><pre lang="c#"><pre lang="c#"><pre lang="c#">

公共部分类ABC:System.Web.UI.UserControl

{

ZipFile objZip = new ZipFile() ;

string profile =〜/ ExportToPDFDocuments /;

string objpath;



#region PageLevelEvents


protected void Page_Load(object sender,EventArgs e)

{

Page.Header.Title =Reports ;

}



#endregion



protected void btnExportToExcel_Click(object sender,EventArgs e)

{

WorkingWay3();

}





private void WorkingWay3()

{

string pdfExportPath = profile + ApConfig.CurrentCompany.CompId +/ + ApConfig.CurrentUser.EmpId.ToString()+/+Objectives;

string PDFdeletePath = profile + ApConfig.CurrentCompany.CompId;

if(!Directory .Exists(Server.MapPath(pdfExportPath)))

{

Directory.CreateDirectory(Server.MapPath(pdfExportPath));

}

pdfExportPath = pdfExportPath +/Objectives.pdf;

objpath = Server.MapPath(pdfExportPath);



string deletePath = Server.MapPath(PDFdeletePath);

HtmlToPdf(http:// localhost:32370 / User / Perfor mancePDF.aspx,objpath);



Response.Clear();

Response.AddHeader(Content-Disposition,附件; filename = DownloadedFile.zip);

Response.ContentType =application / zip;

objZip.Save(Response.OutputStream);

Directory.Delete(deletePath,true);

Response.End();

}



private void HtmlToPdf(string website,string destinationFile)

{

ProcessStartInfo startInfo = new ProcessStartInfo();

string switches =;

开关+ = - header-html http:// localhost:32370 / PDFheader.aspx;

//开关+ = - 头部中心测试;

startInfo.Arguments = switches ++ website ++ destinationFile;



startInfo.UseShellExecute = false;



startInfo.RedirectStandardOutput = true;



startInfo.RedirectStandardInput = true;



startInfo.RedirectStandardError = true;



startInfo.CreateNoWindow = true;



startInfo.FileName =C :\\Program Files \\wkhtmltopdf\\bin\\wkhtmltopdf.exe;

//startInfo.Arguments = website ++ destinationFile;



处理myProcess = Process.Start(startInfo);



myProcess.WaitForExit();

myProcess.Close();

objZip.AddFile(destinationFile,Files);

}

}

public partial class ABC: System.Web.UI.UserControl
{
ZipFile objZip = new ZipFile();
string profile = "~/ExportToPDFDocuments/";
string objpath;

#region PageLevelEvents

protected void Page_Load(object sender, EventArgs e)
{
Page.Header.Title = "Reports";
}

#endregion

protected void btnExportToExcel_Click(object sender, EventArgs e)
{
WorkingWay3();
}


private void WorkingWay3()
{
string pdfExportPath = profile + ApConfig.CurrentCompany.CompId + "/" + ApConfig.CurrentUser.EmpId.ToString() + "/" + "Objectives";
string PDFdeletePath = profile + ApConfig.CurrentCompany.CompId;
if (!Directory.Exists(Server.MapPath(pdfExportPath)))
{
Directory.CreateDirectory(Server.MapPath(pdfExportPath));
}
pdfExportPath = pdfExportPath + "/Objectives.pdf";
objpath = Server.MapPath(pdfExportPath);

string deletePath = Server.MapPath(PDFdeletePath);
HtmlToPdf("http://localhost:32370/User/PerformancePDF.aspx", objpath);

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");
Response.ContentType = "application/zip";
objZip.Save(Response.OutputStream);
Directory.Delete(deletePath, true);
Response.End();
}

private void HtmlToPdf(string website, string destinationFile)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
string switches = "";
switches += "--header-html http://localhost:32370/PDFheader.aspx";
//switches += "--header-center TEST" ;
startInfo.Arguments = switches + " " + website + " " + destinationFile;

startInfo.UseShellExecute = false;

startInfo.RedirectStandardOutput = true;

startInfo.RedirectStandardInput = true;

startInfo.RedirectStandardError = true;

startInfo.CreateNoWindow = true;

startInfo.FileName = "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe";
//startInfo.Arguments = website + " " + destinationFile;

Process myProcess = Process.Start(startInfo);

myProcess.WaitForExit();
myProcess.Close();
objZip.AddFile(destinationFile, "Files");
}
}