tuespetre / TuesPechkin

A .NET wrapper for the wkhtmltopdf library with an object-oriented API.
326 stars 116 forks source link

HtmlToPdfDocument not working with body, header and footer set together. #171

Open SIM128 opened 6 years ago

SIM128 commented 6 years ago

Hi,

I'v a problem converting a document with the PageUrl, Header and Footer set.

This is my method:

static void Main(string[] args) 
{
    PdfToolset pdfToolset = new PdfToolset(new Win64EmbeddedDeployment(new TempFolderDeployment()));
    IConverter converter = new StandardConverter(pdfToolset);

    HtmlToPdfDocument document = new HtmlToPdfDocument
    {
        GlobalSettings = {
            ProduceOutline = true,
            DocumentTitle = "DocumentTitle",
            PaperSize = new PechkinPaperSize("297mm", "420mm"),
        },
        Objects = {
            new ObjectSettings
            {
                PageUrl = $"http://localhost:5000/Document_1_1_1",
                FooterSettings = new FooterSettings {
                    HtmlUrl = $"http://localhost:5000/DefaultFooter",
                },
                HeaderSettings = new HeaderSettings {
                    HtmlUrl = $"http://localhost:5000/DefaultHeader",
                },
            }
        }
    };
}

The result is a pdf only with header and footer and nothing in the "body".

If i set HtmlText instead of PageUrl it works.

I tested the same via cli and it works:

PS> C:\Program Files\wkhtmltopdf\bin> .\wkhtmltopdf.exe -s A3 http://localhost:5000/Document_1_1_1 --footer-html http://localhost:5000/DefaultFooter --header-html http://localhost:5000/DefaultHeader --header-spacing 10 --footer-spacing 10 C:\Users\SIM\Downloads\test.pdf

I'm doing something wrong here?

jackiemanzzz commented 5 years ago

I have the same problem. If i add page url with another url, iss throw an exception which is wkhtmltox.dll_unloaded.

my code

var document = new HtmlToPdfDocument
        {
            GlobalSettings = {
                ProduceOutline = true,
                DocumentTitle = title,
                Orientation = orientation,
                PaperSize = PaperKind.A4,
                Margins =
                {
                    Left = 1.375,
                    Right = 1.375,
                    Top = top,
                    Bottom = bottom,
                    Unit = TuesPechkin.Unit.Centimeters
                }
            },
            Objects = {
                new ObjectSettings {
                    PageUrl = link,
                    HeaderSettings = new HeaderSettings{HtmlUrl = headerPath, ContentSpacing = 2 },
                    FooterSettings = new FooterSettings{HtmlUrl = footerPath,}
                }
            }
        } ;