msokk / electron-render-service

Microservice for rendering PDF/PNG/JPEG from HTML with Electron
MIT License
102 stars 28 forks source link

A setup for #14 #16

Closed Reggino closed 8 years ago

Reggino commented 8 years ago

This should allow HTML to be POSTED, as discussed #14

Reggino commented 8 years ago

I'll fix the linting issues and change the request method to POST when sending HTML

Reggino commented 8 years ago

Raw HTML can now be POST-ed to retrieve a PDF's and images.

I tried to keep the existing structure in tact, so i change the request-method to GET after the tmp-file is created. Maybe you prefer the GET-handler to be a separate method and be called instead... See https://github.com/kingsquare/electron-render-service/blob/send-html/src/server.js#L54

Reggino commented 8 years ago

I've added transparent: true to the BrowserWindow. This prevents a white rectangle being drawn behind the actual output. This way it is possible to add your own background or watermark (with external software)

Reggino commented 8 years ago

The missing white background rectangle causes a binary difference in the test-results, they look the same though... I think the compare-files should be updated...

msokk commented 8 years ago

Hey,

Looks great, first question - why saving to a tempfile instead of loading the posted HTML as a data URI?

Such as: data:text/html;charset=utf-8,<!DOCTYPE%20html><html%20lang%3D"en"><head><title>Embedded%20Window<%2Ftitle><%2Fhead><body><h1>42<%2Fh1><%2Fbody><%2Fhtml> with HTML being encoded with encodeURIComponent.

Of course there might be some unknown issues with this approach :)

msokk commented 8 years ago

👍 for transparency support, test themselves are quite brittle (in a sense that test code is comparing bytes), but I couldn't figure out how to make them more robust. Testing is done inside the docker image, so any test fixtures have to be generated with that (as each platform has subtle rendering differences).

Reggino commented 8 years ago

I didn't really test it, but i'm afraid there are limits to the length of an url . To prevent that kind of issues, streaming the request into a tempfile seems a more solid approach and causes a minimal amount of performance impact...

msokk commented 8 years ago

Yup, URLs with protocol are usually limited around 2k characters, datauri is a different thing, but looks like Chrome limits it at 2MB - https://bugs.chromium.org/p/chromium/issues/detail?id=44820#c16. So still out of question.

Reggino commented 8 years ago