Skip to content

Wkhtmltopdf Custom header with ASP.NET

Torakami Softwares

Asked Oct 22, 2014, 1:13 AM EDT2 answers
Share
LinkedInX
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 ..
 
 
C#
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");         }
 

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • +1
    Wkhtmltopdf is a free tool that can be used to convert html to pdf, but it's not too good when it comes to performing more complicated tasks.

    For that, I recommend a commercial library, if you can use one: ExpertPdf Html To Pdf Converter is the best I have used.
    +1
  • 0

    One of the most common ways of disseminating information is through PDF files. PDF, which stands for Portable Document Format, is the file format used by Adobe Acrobat. Many people receive information in PDF format, but then want to transfer that information to a Word document so they can work with it.

    There are a couple of ways that you can get text from a PDF file to a Word document. Exactly which ones you can use depends on how the PDF file is protected. If the file is not protected, try these steps:

    1. Open the PDF document and display the page that contains the text you want to copy to Word.
    2. Click the Text tool on the toolbar.
    3. Click and drag to select the text you want to copy, or (if you want to select all the text) click once in the text area and press Ctrl+A.
    4. Press Ctrl+C to copy the selected text to the Clipboard.
    5. Switch to your Word document.
    6. Press Ctrl+V to paste the contents of the Clipboard into your document.

    This transfers the text to your Word document. It is only the plain, unformatted text, but you can now work with it in Word.

    VB.NET
    If you have Adobe Acrobat 7 (or a later version) you can actually  export a PDF document in either RTF or Word document format. (This won't  work with Adobe Reader; you must have the full version of Acrobat.)  Simply load the PDF and choose File | Save As. In the dialog box, choose  Word document as the Save As Type. When you click Save, the document  file is created.
    If the PDF file is protected (authors can set security settings on  PDF files so they are protected), then you won't be able to use either  of the foregoing solutions. Instead, you will need to look to a  third-party solution.
    If you already have a scanner and OCR software, you can print the PDF  file, then scan the document and use the OCR software to convert it to a  Word document. One company has taken the OCR process a step further,  allowing you to skip the scanning and instead convert directly from PDF.  If you are interested in this product, it is called PDF Transformer,  from ABBYY software:
    Code
    http://www.abbyy.com/pdftransformer/
    http://www.dianaboluk.co.uk/
    0