Create a PDF using Save to PDF with a transparent background

1,037 views
Skip to first unread message

Andy Teijelo

unread,
May 9, 2018, 1:54:43 AM5/9/18
to Chromium-discuss
Hi, I'm trying to use headless Chromium to generate some PDFs that I intend to superimpose on other PDFs.
The composition operation is done with:

pdftk base.pdf stamp top.pdf output output.pdf

And top.pdf is what I generate with Chromium Save to PDF. The page is dead simple:

   <html><body>Sample Content</body></html>

My problem is that top.pdf has a white rectangle in the background that covers the entire page. This can be seen
by opening the PDF with Inkscape and ungrouping all objects, or by looking inside the PDF:

$ qpdf --qdf --stream-data=uncompress --object-streams=disable top.pdf top-uncompressed.pdf

And inside:

    ....
    %% Contents for page 1
    %% Original object ID: 2 0
    5 0 obj
    <<
    /Length 6 0 R
    >>
    stream
    1 0 0 -1 0 792 cm
    q
    0 0 612 792 re
    W* n
    q
    .75 0 0 .75 0 0 cm
    1 1 1 RG 1 1 1 rg
    /G0 gs
    0 0 816 1056 re
    f
    ...

The last four lines set fill color to white (1 1 1 rg), border color to white (1 1 1 RG), define a rectangle (0 0 816 1056 re) and fill it (f)

I've tried a lot of CSS in my page (background-color: transparent, background-image: none, etc). But nothing has any effect on this
white rectangle.

Any pointers?

Stephen Chenney

unread,
May 9, 2018, 9:50:26 AM5/9/18
to atei...@gmail.com, Chromium-discuss
Does the page printed from Chrome contain the same white background rectangle?

If headless behaves differently I suggest filing a bug at crbug.com. This could be a wider problem if trying to print on colored paper.

Stephen.

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss


Andy Teijelo

unread,
May 9, 2018, 9:55:08 AM5/9/18
to Stephen Chenney, Chromium-discuss
Yes, it does. The white background is present is both Chromium and Chrome, headless or not. Thanks for the crbug pointer. I'll file it there.

Andy Teijelo

unread,
May 9, 2018, 10:58:46 AM5/9/18
to Chromium-discuss, atei...@gmail.com
Turns out someone had already filed it:


I added my findings as a comment. Thanks again!

J Decker

unread,
May 9, 2018, 11:14:46 AM5/9/18
to atei...@gmail.com, Chromium-discuss
Have you perhaps tried Electron?  (It's also chromium basically) but is able to create transparent browser surfaces; they don't pass mouse events correctly to really work well for me... But I was able to create a transparent window....


(and.. it seems to have issues too)

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Andy Teijelo

unread,
May 9, 2018, 11:55:25 AM5/9/18
to Chromium-discuss, atei...@gmail.com
It never occured to me to try Electron. I was set on the headless way. So I just
tried electron-pdf and voilà, the PDF file is OK. It doesn't have the white
background.

I'll see if this can meet my requirements. I'm new to using Electron
as a development tool. So far I had just used apps built with it (Atom, VSCode,
Skype, Postman, Spotify, etc)

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Reply all
Reply to author
Forward
0 new messages