Faster background image on PDF generation with wkhtmltopdf - html

I'm trying to generate a 5-page PDF based on my HTML file with wkhtmltopdf and it is working well. I'm having a problem, however, regarding the time spent for this task, especifically when using a background image for each page.
When I use a bg_image, wkhtmltopdf uses about ~1.7s to generate, but without it (--nobackground option) only ~0.5s are spent. I've tried to convert my bg_image from .jpg to .png to try to make it faster, but it didn't work.
Is there any workaround onto it? Maybe a parameter change or a css change? (Right now my html file contains a declaration for a bg_image on each page, and a global declararion at the start setting its size and "no_repeat" option).
Thanks a lot for your attention!

I don't know about internals of wkhtmltopdf, how they handle a background. If they need some measureable time, i would expect, that they decode and encode the image data of the background image.
You could also use pdftk utility to apply a prepared pdf-background file to all pages of a pdf, which should be fast:
pdftk in.pdf background back.pdf output out.pdf
https://linux.die.net/man/1/pdftk

Related

Python Convert HTML Image to PNG

Given a saved HTML file with an image (an output from Bokeh), how can I save it as a PNG file with a DPI of 300?
I found some answers to similar questions, but they don't seem to work for me. I think I need someone to explain the whole process (importing the needed package, where it needs to be located if applicable, and how to call it).
I've tried this after pip installing webkit2png:
import os
os.system("webkit2png" "texas.html")
I've also tried:
import subprocess
subprocess.call("webkit2png", "texas.html")
Thanks in advance!
As of Bokeh 0.12.6, it is now possible to export PNG and SVG directly from
Python code.
Exporting PNGs looks like this
export_png(plot, filename="plot.png")
And exporting SVGs looks like this
plot.output_backend = "svg"
export_svgs(plot, filename="plot.svg")
There are some optional dependencies that need to be installed.
You can find more information in the Exporting Plots section of the User Guide.
Currently, plots are saved at their native resolution, but in 0.12.7 you will be able to set the size.
There's no such thing as an "HTML image." HTML enables one to incorporate image files of various types within an HTML document, which a Web browser knows how to display and process.
Run your Bokeh (?) code and use a commercial screen capture utility (I like SnagIt!, which is FREE). That gives you the capability of saving out the image to disk in a wide array of formats (JPEG, TIF, PNG, GIF, etc.).

How to provide a document preview as a thumbnail independent of file type

In gmail when a file is sent as an attachment to an email, the recipient(s) can see a small portion of the contents of the file before even hovering over it. Now I'm very curius and in fact interested in implementing this in my own application. I've tried inspect element but couldn't quite get how they do this. Ok, with images I can somewhat understand how it's done. But how about pdf, word or excel document? Do they take a snapshot of some portion of the file and store it along with the attachment to later show it inside a container? Has anyone been able to do this? Is just html and css enough?
May be you have found a solution....
But am just updating an answer i just found
If you use Krajee Plugin then you can get that type of preview of the file. Its just not giving gmail like file preview but also giving other type plugin to upload and preview the images and files(almost every type). Giving below the links for your reference.
File Preview Demo
File Preview Icon Demo

Image with parameter - HTML

I do not know how to frame the question. And I do not know how the below tag is working...
<img src="img.png?value=23"/>
This tag is working fine. And its rendering the image correctly.
Does the value=23 has some effect??? or It is been ignored by Browser??
I do not even know how to Google this!!! Is it like passing parameter to the Image??? If that is the case, how to retrieve the value attribute. Does the parameter has any sense
It depends on server, if you have png MIME type as text and you parse the files as if they were text files with php code then it has effect.
It really depends on configuration of server not a browser.
Morover, mod_rewrite can be used to change files that look like png to php files.
Adding parsing png files via php parser
AddType application/x-httpd-php .png
mod_rewrite
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]*)\.png$ img.php?value=$1
With these lineasdfasdf.png will be treated as img.php?value=asdfasdf
So in this case when you use $_GET['value'] on asdfasdf.png or img.php?value=asdfasdf. It will have effect.
If server is not configured to do such things and images are images(Yes i know it's briliant sentence) then it has no effect on common image.
To sum up.
It depends on server configuration not on the browser
If this image is dynamic in some way, then the server that's hosting this image must be generating the image from PHP code.
Take a look at the GD library, which lets you use PHP to generate images based on nothing or other images. The parameter must be passed to include that value inside the image (for example, an image that includes the text "123" or calculates using it somehow, for example a user ID).
Then an .htaccess on the server rewrites the extension of .png to .php (or maybe another one) to make it look like a genuine image to some libraries and crawlers, or scripts etc.
Another option, is that this is a simple image and that value is being ignored, or is just random to make sure the image isn't cached.
The value=23 only has an effect if the server uses it. The browser requests http://example.com/img.png?valud=23, so the server will see the parameter.
For example, with PHP, if your use $_GET['value'], and that variable changes what image is sent, then the value=23 is needed.
Parameters are often sent with images to specify a height or width, or to determine which image is loaded.
For this sample i don't know what does it mean
But it's possible to write
<img src="path_img.png?<?php time() ?>" />
to force your browser to download resource without using cache
It sure does!
For example, take a look at this piece of software that is intended to dynamically resize an image.
http://imageresizing.net/docs/basics
If done correctly, adding parameters to an image url could be very useful.
Edit:
As others point out, you need to ensure that the server knows how to handle the extra parameter. In this case it is intended to resize/watermark/rotate an image. It can certainly do other wonderful things.
value=23 is not ignored by your browser but by the server.
It's like passing parameters to the web server. For images it will be mostly ignored.
The arguments in a url are mostly used for getting some information about a specific item but can be used in more other ways. When talking about the images, the browser won't ignore the argument value=23 but the server you are using will.
But if the image is some sort of dynamic then it may be used in order to change the image's URL or other things.

How can I convert BASE64 encoded HTML to GIF using ColdFusion?

I am receiving a BASE64 encoded string from a WebService. The string represents an HTML page, and I can use built-in ColdFusion functions to convert and display it. However, I need a GIF representation of the HTML page, and I'm wondering if there's any way to do this using ColdFusion.
NOTE: The website I'm working on is ColdFusion 8.
UPDATE: As it turns out, the vendor gave me incorrect instructions (different from their documentation). I don't need to output a GIF of the document they are sending, so this is a non-issue now. However, seeing as the question has received 6 upvotes already, I'm going to leave the it open, as I'm curious if there is - or will be - an answer someday.
You could save the html to the file system, and use this technique for creating URL Thumbnails
Since CFIMAGE's writeToBrowser doesn't allow you to output a GIF (as you've no doubt found out), you'd have to take the image and save it to the filesystem as a gif, then write an HTML IMG tag pointing to that GIF file.
You can't write a gif but you can take the base64 and write it to the browser as a png.

Loading images from various sources in QTWebKit

I am trying to create a "smart" web browser to load local images. Basically it works as a GUI for an application. I am using QTWebKit to power the browser, the problem is that the images of a given page can be found in different places, some are local files, others are in different resource files.
For example:
an HTML node to load image x.jpg can look like <img src="x.jpg"> and for image y.gif on the same page it can be <img src="y.gif">, now x.jpg is a local file that can be either in the root directory or in some other place. y.gif on the other hand can be in a resource file.
I want the web browser first to set the paths to all possible sources and once the page has been loaded or preferably while the page is loading searches for the images and loads them from their original path.
I considered the option of reading the HTML data first, parse it and search for the resources one by one, then edit the html to include the full path of the image but that would take a long time than what I want and it isn't practical.
Can any one put me on the right direction or does any one have any ideas on how such a design can be implemented.
EDIT: I have manage to delegate the requests by overriding the QNetwrokAccessManager and QNetwrokReply and been able to get the path to the image. The only problem is loading the image into view. I am currently using QHttp to handle the incoming requests but so far I haven't been able to load the image.
been trying to use QHttp's Get() function and passing the path to the jpg image as (file:///path/to/image) and also tried using the local path but nothing is working.
Take a look at How to tell QWebPage not to load specific type of resources?
You need the same approach but instead of dropping request by constructing QNetworkRequest with empty QUrl you need to pass url to the file on the disk.