Giter Site home page Giter Site logo

wkhtmltopdf's Introduction

Codaxy.WkHtmlToPdf

This is a small C# wrapper utility around wkhtmltopdf console tool. You can use it to easily convert HTML reports to PDF.

NuGet

NuGet includes single source file in your project.

Install-Package Codaxy.WkHtmlToPdf

Usage

PdfConvert.ConvertHtmlToPdf(new PdfDocument 
{ 
    Url = "http://wkhtmltopdf.org/",
    HeaderLeft = "[title]",
    HeaderRight = "[date] [time]",
    FooterCenter = "Page [page] of [topage]"

}, new PdfOutput 
{
    OutputFilePath = "wkhtmltopdf-page.pdf"
});

Licence

This project is available under MIT Licence.

wkhtmltopdf's People

Contributors

bajicdusko avatar chrisgarber-medlever avatar lozenlin avatar mstijak avatar tlk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wkhtmltopdf's Issues

Not able to run..

HI, I am trying to use this codaxy for converting webforms into pdf.

I am getting the following error. Could not find the exe.

Path.Combine(OSUtil.GetProgramFilesx86Path(), @"wkhtmltopdf\wkhtmltopdf.exe")

Do I need to install some exe here? where can I find this exe? When I download the sample, I only got the tests project. Need help on this.

Thanks.

Wkhtmltopdf not supported the --allow command

I've already created the one ticket in SO Link

I'm not able to execute the --allow command in wkhtmltopdf any suggestion about this?
or did I miss something?

I'm using the wkhtmltopdf for creating HTML to pdf it's working fine but for some additional requirements in the pdf, I have to add the background image/watermark on every page.

I go through this link wkhtmltopdf they mention a few commands below

--allow <path> Allow the file or files from the specified folder to be loaded (repeatable)
--background Do print background (default)

Is there any sequence issue in the below command argument? Here is my command argument.

--page-size A4 --footer-html http://localhost:49955/PDFExport/FooterUrl
--footer-left "Printed On 11/6/2022"
--footer-right "Page [page] of [topage]"
--footer-font-size "7"
--header-spacing 5
--margin-top 5mm
--margin-left 0mm
--margin-right 0mm --outline-depth 4
--background http://localhost:49955/PDFExport/BackgroundURL
--enable-local-file-access --allow "F:\bg-overlay.jpg"
"https://wkhtmltopdf.org/usage/wkhtmltopdf.txt" "F:\TestBackground.pdf"

image

Here you can see how PDF looks -> OutPut link

I'm not able to perform the below command let me know what I missed in the command.

--background
--enable-local-file-access
--allow

Exception thrown: 'Codaxy.WkHtmlToPdf.PdfConvertException'

Exception thrown: 'Codaxy.WkHtmlToPdf.PdfConvertException' in 'MyTest.exe'

Additional information: File 'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe' not found. Check if wkhtmltopdf application is installed.

Is it require some install to use? I can't understood this error. Because I've used the install-package.

How to use exemple

Hi,

Your library is very easy to use but an little exemple is missing in the documentation.
What do you think about :

MemoryStream memory = new MemoryStream();
PdfOutput output = new PdfOutput() { OutputStream = memory };
PdfConvert.ConvertHtmlToPdf(HeaderUrl, BodyUrl, FooterUrl, output);

Change footer/header fonts size

Any way of changing the footer font size? or just include it as HTML also basicly. Other than that, great so far.

System.IO.Stream stream = new System.IO.MemoryStream();
            PdfConvert.ConvertHtmlToPdf(new PdfDocument {
                Url = "http://wkhtmltopdf.org/",
                HeaderLeft = "[title]",
                HeaderRight = "[date] [time]",
                FooterRight = "Oh noooooooooooooo",
                FooterLeft = "Página [page] I am really long and will eventually collide with the ",
                

            }, new PdfOutput {
                OutputStream = stream,
            });
            stream.Flush();
            stream.Position = 0;
            return new FileStreamResult(stream, "application/pdf");

Fonts are not supported

Common fonts are not supported its shows symbols and bold fonts instead of clear HTML form.

Break Font Quality

Hi,

I used this tool and it was amazing. It helps me allot to create PDF from XHTML document. It looks perfect but the font quality is not actual as it was in XHTML document.

What to do to show the exact font quality? Please suggest.

Thanks

ContentNotFoundError caused by missing page elements like 404 js.

Because there is a failed js request, then even the wkhtmltopdf returns Done, our lib is still returning ContentNotFoundError

Result Message:	
Test method Util.PDF.Test.TestPDF.TestHTML_Codaxy_NoRadius threw exception: 
Util.PDF.Codaxy.WkHtmlToPdf.PdfConvertException: Html to PDF conversion of document failed. Wkhtmltopdf output: 
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[==========>                                                 ] 18%
Warning: Failed to load file://inpref-asia.s3.amazonaws.com/sites/misatravel_com.js (ignore)
[==========>                                                 ] 18%
[===============>                                            ] 26%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[============================================================] Page 1 of 1
Done                                                                      
Exit with code 1 due to network error: ContentNotFoundError

I am using @fean 's fork AuthiQ/wkhtmltopdf Because #13

Currently I am resolving this by adding a try catch around, however I am not sure if there is any side-effect

Try
    PdfConvert.ConvertHtmlToPdf(New PdfDocument() With {.Html = html},
                            New PdfOutput() With {.OutputFilePath = path})
Catch ex As Exception When ex.Message.Contains("ContentNotFoundError")
    'Ignore ContentNotFoundError due to 404 elements
End Try

Upgrade to 0.12.6

Please upgrade the wkhtml library to 0.12.6 so it works for 64-bit ARM.

Support for url behind Identity Authentication (.NET MVC 5)

I'm trying to use your wrapper in order to generate a PDF file of a html page containing an invoice in ASP.net MVC 5. This is a order system where it's, of course, protected from the public by log in and cookie authentication using Identity. I tried adding Cookies by doing:

 var cookies = Request.Cookies.AllKeys.ToDictionary(k => k, k => Request.Cookies[k].Value);

 Codaxy.WkHtmlToPdf.PdfConvert.ConvertHtmlToPdf(new Codaxy.WkHtmlToPdf.PdfDocument
        {
            Url = Request.Url.AbsoluteUri.Replace("pdf", "print"),
            HeaderLeft = "[title]",
            HeaderRight = "[date] [time]",
            FooterCenter = "Page [page] of [topage]",
            Cookies = cookies

        }, new Codaxy.WkHtmlToPdf.PdfOutput
        {
            OutputFilePath = Server.MapPath("~/Content/InvoicePDFs/"+ id.ToString() + ".pdf")
        }
return File("~/Content/InvoicePDFs/" + id.ToString() + ".pdf", "application/pdf", id.ToString() + ".pdf");
        );

But I just end up rendering the login page, and barely that, it's not even completely loaded. It just renders the elements, no text whatsoever.

Nuget package in documentation

It would be useful to have the nuget package url in documentation and the package manager console command for installation.

Exception: Pipe has been ended.

Because of environmental limitations I can only see the exception message.

As stated in the title it says:
Pipe has been ended.

This is the code I used:

            var stream = new MemoryStream();
            PdfConvert.ConvertHtmlToPdf(new PdfDocument()
            {
                Html = ret_invoice,
                ExtraParams = new Dictionary<string, string>()
                {
                    { "page-size", "1440" }
                }
            }, new PdfOutput()
            {
                OutputStream = stream
            });

I looked around on the internet and most times when this happened the C++ 2013 redistributable wasn't installed in the environment. I had already installed it before hand so that's not the cause. Also I tried to use both x86 and x64 versions of wkhtmltopdf.exe and they both worked fine.

Command I used to test wkhtmltopdf.exe:
wkhtmltopdf "http://tweakers.net" C:\test_pdf.pdf

The type or namespace Codaxy could not be found

Hi,
Ive added the nuget package into my project (aspnet 5/core mvc 6 project). I can see it in project.json file and in reference directory.
Getting this error when adding in the using statement: "using Codaxy.WkHtmlToPdf;"
Is there another step Im missing!? Does it work with latest version of asp.net?

Timeout on > 5 pdf pages

I'm able to convert between 1 and 5 pages with no issue, but once I test with generating 6 pages, the Process times out. Below is arguments string sent with the ProcessStartInfo. I've tried with 32 and 64 bit with no luck. I'm able to use the same argument in command line with no issue.

--page-size LETTER
--footer-html http://localhost/TEMPFOLDERs/TEMPFOLDERFooter.aspx
margin-bottom 25 --footer-spacing 5
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275013 
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275023
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275029
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275030
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275032
http://localhost/TEMPFOLDERs/TEMPFOLDER.aspx?p=275033
C:\\Users\\Me\\Documents\\Projects\\APPLICATION\\TEMPFOLDERs\\Generated\\owg2vwvl.dzw\\ABC_Healthcare.pdf

Error with no message

We have a project using wkhtmltopdf, when generating the PDF it throws an error with no information. I do apologize if it's obvious, this was delivered by a contractor and I have no experience with this tool.
I've read some posts at the oracle (stackoverflow) and some have indicated that it requires the redistributed c++, is that the case?

Here is the error we are getting:
System.Exception
HResult=0x80131500
Message=
Source=Wkhtmltopdf.NetCore
StackTrace:
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)

Thanks

customPath null

For some reason it is not possible to get the value for the customPath variable in the GetWkhtmlToPdfExeLocation method in the PdfConvert class.

Process timing

How do I get this to wait for the HTML internal Java scripts to process before converting to PDF?
I am using an external tool to create formal math expressions. See attached examples.

Base HTML document:
Calculation (2).zip

As converted by your tools:
testcalcs.pdf

As converted by https://html2pdf.com/:
Calculation.pdf

My current code:
@page "/Calcs"

@code
{
protected override async Task OnInitializedAsync()
{
PdfConvert.ConvertHtmlToPdf(new PdfDocument
{
Url = "https://localhost:44392/Calculation.html",
HeaderLeft = "[title]",
HeaderRight = "[date] [time]",
FooterCenter = "Page [page] of [topage]"

    }, new PdfOutput
    {
        OutputFilePath = "testcalcs.pdf"
    });
}

}

Missing information on usage

I am using this C# converter from html to pdf.

In the .csproj I have:

<ItemGroup>
<PackageReference Include="Codaxy.WkHtmlToPdf" Version="0.5.8" />
</ItemGroup>

I want to use in the controller something like:

        PdfConvert.ConvertHtmlToPdf(new PdfDocument
        {
            Url = "http://wkhtmltopdf.org/",
            HeaderLeft = "[title]",
            HeaderRight = "[date] [time]",
            FooterCenter = "Page [page] of [topage]"

        }, new PdfOutput
        {
            OutputFilePath = "wkhtmltopdf-page.pdf"
        });

(this is the same code as in GitHub).

However, when I do (in the same controller):

using Codaxy.WkHtmlToPdf;

the project doesn't build (and shows error in the VS editor...). The error presented is:

Error CS0246 The type or namespace name 'Codaxy' could not be found (are you missing a using directive or an assembly reference?)

The GitHub page of the project lacks directions on using using directive....

Could you help me?
I am using VS2019 and .Net Core 2.1

'ConfigurationManager' missing

I've just updated to the latest version and am seeing an error on line 75 of PDFConvert.cs:

 private static string GetWkhtmlToPdfExeLocation()
 {
    string filePath, customPath = ConfigurationManager.AppSettings["wkhtmltopdf:path"];
    ...

The error is:
The name 'ConfigurationManager' does not exist in the current context

How can I fix this? I'm downgrading temporarily as this is urgent but will upgrade again once you have a fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.