Coder Social home page Coder Social logo

Comments (3)

plessl avatar plessl commented on August 17, 2024

Hi Don

First of all, your HTML does not validate correctly. In this case it probably doesn't matter, but I would generally recommend to feed wkpdf only HTML that validates correctly (i.e. with correct DOCTYPE and character set specification).

I assume that the problem you are seeing is related to the fact that the document width is not defined when no pagination is used and your <div> doesn't have a width set. I'm not sure whether this is the expected behavior of your HTML/CSS or whether this is a bug in WebKit.

But if you use the following HTML the result renders just fine:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>untitled</title>

</head>

<body>
  <p style="background-color: grey; width: 200px;">
  This<br />
  is<br />
  a<br />
  test
  </p>
</body>
</html>

One more thing: --no-paginate does not work at least on my machine, but you need to use --paginate no to suppress pagination.

Hope this helps.

from wkpdf.

mrtoner avatar mrtoner commented on August 17, 2024

Odd. If I remove the width declaration in your example Safari will display the background color, but when I then preview the page as a PDF ( File > Print… > PDF > Open PDF in Preview ) the background color is not displayed.

BTW, as noted elsewhere, --paginate no doesn't work on my machine.

from wkpdf.

plessl avatar plessl commented on August 17, 2024

Your test seems to confirm my theory, that a <div>element without a width will be treated as zero width by the PDF renderer, but as non-zero width in the WebView that is used by Safari. I'm not sure whether this should be considered a bug in WebKit/Cocoa.

I think assigning a default width could be a workable workaround. But what about filing a bug report with WebKit?

from wkpdf.

Related Issues (20)

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.