WickedPDF Rendering differently locally vs production - ruby-on-rails

I have installed wkhtmltopdf 0.12.3 (with patched qt) on my desktop machine and the exact same version on my Centos virtual machine.
I am using WickedPDF and Rails to convert HTML to PDF.
When the PDF is generated it has slight differences in the font. Some weird letter spacing. I have attached images showing this.
You can see the gap between the e and n this however is not present on my local machine. Image below:
Does anyone know why this would happen?
Any advice would be appreciated.
Thanks
This is the Ruby code which I am using to generate the PDF with WickedPDF
def generate_pdf
pdf = WickedPdf.new
pdf_file = pdf.pdf_from_string(ActionController::Base.new().render_to_string('card_requests/show.pdf.haml', layout: 'pdf', locals: {card_request: self}),
dpi: '300',
margin: {top: 0, bottom: 0, left: 0, right: 0},
page_height: '2.25in',
page_width: '3.75in',
disable_smart_shrinking: false
)
tempfile = Tempfile.new(["#{self.name.gsub(' ', '_').downcase}_biz_card", '.pdf'], Rails.root.join('pdfs'))
tempfile.binmode
tempfile.write pdf_file
tempfile.close
self.pdf = File.open(tempfile.path)
tempfile.unlink
self.save
end
Here is also the show.pdf.haml file with the CSS at the top:
!!! 5
%html
%head
:css
html * {
margin: 0 !important;
padding: 0 !important;
page-break-inside: avoid !important;
}
body {
margin: 0 !important;
padding: 0 !important;
page-break-inside: avoid !important;
text-rendering: optimize-speed;
}
.card-preview {
font-family: 'TradeGothic';
background-size: contain;
width: 369px;
height: 220px;
page-break-after: avoid !important;
position: relative;
}
#card-name {
color: #ED1D27;
font-weight: bold;
font-size: 12pt;
position: absolute;
top: 37px;
left: 39px;
width: 328px;
}
#card-title {
color: #2E2D2D;
font-weight: bold;
position: absolute;
top: 54px;
left: 39px;
font-size: 9pt;
}
#card-office-phone {
color: #4e4e48;
position: absolute;
top: 148px;
left: 39px;
font-size: 8.5pt;
}
#card-cell-phone {
color: #4e4e48;
position: absolute;
top: 135px;
left: 39px;
font-size: 8pt;
width: 200px;
}
#card-email {
color: #4e4e48;
position: absolute;
top: 161px;
left: 39px;
font-size: 8.5pt;
}
#card-website {
color: #4e4e48;
position: absolute;
top: 174px;
left: 39px;
font-size: 8pt;
}
.hide {
display: none;
}
%meta{:charset => "utf-8"}
%body
.card-preview{style: "background-image: url('#{Rails.root.join('app', 'assets', 'images', 'card_template_2.svg')}')"}
#card-name
= card_request.name
#card-title
= card_request.title
#card-office-phone{class: (card_request.office? ? "" : 'hide')}
== office 555 555 5555 #{card_request.ext? ? "ext #{card_request.ext_phone}" : ''}
#card-cell-phone{class: ((card_request.cell? && !card_request.cell_phone.blank?) ? "" : 'hide'), style: (card_request.office? ? "" : 'top: 148px; left: 39px;')}
= (card_request.cell? ? "cell 555 555 5555" : '')
#card-email
= card_request.email
#card-website
www.website.com
I have since fixed this issue by following this:
https://taskman.eionet.europa.eu/issues/20890
It fixes kerning issue on CentOS for me.

I was facing a similar issue of spaces after certain specific letters like
Reg istration ---> space after letter 'g'
O pen ---> space after Capital letter 'O'
The above issue could be due to system specific fonts configs. I referred an issue reported over github for the same https://github.com/wkhtmltopdf/wkhtmltopdf/issues/45
This issue occurs on a production instance (AWS AMI linux) with CentOS 6.x but was working perfectly with ubuntu 14.04. I looked into the system fonts configs 51-local.conf over CentOS at path /etc/fonts/conf.d .If there is no file with name wkhtmltopdf at the same path then use the default fonts file 51-local.conf to have the below configuration as custom fonts.
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
</match>
</fontconfig>
Also, If you are using wicked_pdf.rb initializer configuration exec path as /usr/local/bin/wkhtmltopdf for development environment. try to replace the path with /bin/wkhtmltopdf for production bundle

Related

How to Save a page assembled using GrapeJS to a database using ASP.NET MVC

Well, I am developing my own Content Management System using ASP.NET MVC and for a page builder I've decided to use GrapeJS. Now, since this is new to me, I can't seem to find a way to save the pages I would have assembled using GrapeJS. I have used the gjs-preset-webpage GrapeJS plugin and the only JavaScript for the assembling area I have is as shown below:
<script type="text/javascript">
var editor = grapesjs.init({
height: '100%',
showOffsets: 1,
noticeOnUnload: 0,
storageManager: { autoload: 0 },
container: '#gjs',
fromElement: true,
plugins: ['gjs-preset-webpage'],
pluginsOpts: {
'gjs-preset-webpage': {}
}
});
</script>
The HTML I've used is as follows as well:
<div id="gjs" style="height:0px; overflow:hidden">
<div class="panel">
<h1 class="welcome">Welcome to</h1>
<div class="big-title">
<svg class="logo" viewBox="0 0 100 100">
<path d="M40 5l-12.9 7.4 -12.9 7.4c-1.4 0.8-2.7 2.3-3.7 3.9 -0.9 1.6-1.5 3.5-1.5 5.1v14.9 14.9c0 1.7 0.6 3.5 1.5 5.1 0.9 1.6 2.2 3.1 3.7 3.9l12.9 7.4 12.9 7.4c1.4 0.8 3.3 1.2 5.2 1.2 1.9 0 3.8-0.4 5.2-1.2l12.9-7.4 12.9-7.4c1.4-0.8 2.7-2.2 3.7-3.9 0.9-1.6 1.5-3.5 1.5-5.1v-14.9 -12.7c0-4.6-3.8-6-6.8-4.2l-28 16.2" />
</svg>
<span>GrapesJS</span>
</div>
<div class="description">
This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can
copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.
</div>
</div>
<style>
.panel {
width: 90%;
max-width: 700px;
border-radius: 3px;
padding: 30px 20px;
margin: 150px auto 0px;
background-color: #d983a6;
box-shadow: 0px 3px 10px 0px rgba(0,0,0,0.25);
color: rgba(255,255,255,0.75);
font: caption;
font-weight: 100;
}
.welcome {
text-align: center;
font-weight: 100;
margin: 0px;
}
.logo {
width: 70px;
height: 70px;
vertical-align: middle;
}
.logo path {
pointer-events: none;
fill: none;
stroke-linecap: round;
stroke-width: 7;
stroke: #fff
}
.big-title {
text-align: center;
font-size: 3.5rem;
margin: 15px 0;
}
.description {
text-align: justify;
font-size: 1rem;
line-height: 1.5rem;
}
</style>
</div>
Now that I have embedded it into my project and can assembled pages using it, I can't seem to find how to save or where would the assembled page be to be saved. Can anyone help me?
You need a endpoint to allow grapes' storage manager to send your site current status information. I save the json and html just in case, but I think json is enough. Well then you setup your storage manager.
const editor = grapesjs.init({
storageManager:{
type: 'remote',
autosave: true, // Store data automatically
urlStore: 'YOUR_ENDPOINT_URL',
}
});
You will get a call to your endpoint every time something changes with the following parameterts:
gjs-assets: Assets array
gjs-components: Object with markup definition of your site
gjs-styles: Object with styles definition
gjs-html: your site HTML
gjs-css: your CSS
Just be sure to inject this definitions when initialising grapes as well:
const editor = grapesjs.init({
components: "YOUR_STORED_COMPONENTS_HERE",
style: "YOUR_STORED_CSS_HERE",
storageManager:{
type: 'remote',
autosave: true, // Store data automatically
urlStore: 'YOUR_ENDPOINT_URL',
}
});
For further information: Docs

Embed a Twitter profile, not a timeline

I have been looking for a solution for embedding Twitter user profiles, but have come up empty so far. What I'm looking for is something similar to how Twitter pops up a nice profile overview when you click a username on twitter.com. I took a screencap of my profile so you can see below what I'm talking about.
I don't have any need for the user timeline or anything like that, just the user info, the cover photo background would be nice as well as a link to follow the person. I took a look through Twitters embed code builder but there didn't seem to be anything that really fit the bill. I am using Wordpress so a plugin solution could be viable, but if it's just a code embed that is fine as well.
There is currently no embed functionality that I know of for the profile summary, however you can call the api to get profile information from Twitter in two ways:
For one use at a time: /users/show, or
For up to 100 users at once: /users/lookup
You can then take the returned json and style it to match the twitter format or any other style you wish.
Not really embed but this could work for you too https://dev.twitter.com/web/intents#user-intent
Here is an implementation for the button, this require some work to add the profile picture and the background picture
Icon SVG code:
<symbol id="twitter" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" /></symbol>
SASS/CSS:
.twitter a
font-family: "Roboto", "Noto Sans", "Open Sans", "sans-serif"
display: inline-flex
color: #fff
border-radius: 5px
background: #1b95e0
padding: .4em .8em
text-decoration: none
font-weight: bold
text-align: left
HTML:
<div class="twitter" style="height: 35px; width: 240px;"><a target="_blank" rel="noopener noreferrer" href="https://twitter.com/LinuxHacksOrg">
<svg height="20px" width="20px" style="margin-right: 5px; fill: #fff;">
<use xlink:href="/assets/imgs/res/icons-full.svg#twitter"></use></svg>
Follow us #LinuxHacksOrg</a></div>
<style>
.twitter a {
font-family: "Roboto", "Noto Sans", "Open Sans", "sans-serif";
display: inline-flex;
color: #fff;
border-radius: 5px;
background: #1b95e0;
padding: .4em .8em;
text-decoration: none;
font-weight: bold;
text-align: left;
}
</style>
<div class="twitter" style="height: 35px; width: 300px;"><a target="_blank" rel="noopener noreferrer" href="https://twitter.com/LinuxHacksOrg">
<svg height="20px" width="20px" style="margin-right: 5px; fill: #fff;" viewBox="0 0 512 512" preserveAspectRatio="none">
<path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" />
</svg>
Follow us #LinuxHacksOrg</a></div>

Jquery RemoveClass not working for bootstrap buttons

I am having trouble using the Jquery removeClass functionality to disable a certain class. The class definition is given below
.btn-purple
{
background-color: #F1B2E1;
background-image: -moz-linear-gradient(top, #F1B2E1, #E986D0);
background-image: -ms-linear-gradient(top, #F1B2E1, #E986D0);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#F1B2E1), to(#E986D0));
background-image: -webkit-linear-gradient(top, #F1B2E1, #E986D0);
background-image: -o-linear-gradient(top, #F1B2E1, #E986D0);
background-image: linear-gradient(top, #F1B2E1, #E986D0);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#F1B2E1', endColorstr='#E986D0', GradientType=0);
border-color: #0055cc #0055cc #003580;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:dximagetransform.microsoft.gradient(enabled=false);
}
.btn-purple:hover,
.btn-purple:active,
.btn-purple.active,
.btn-purple.disabled,
.btn-purple[disabled] {
background-color: #E986D0;
}
In the javascript file I have the following
$(function(){
$("#1").click(function(){
$("#1").removeClass("btn-purple", 1000);
return false
});
});
And here is the HTML markup for the section I wish to remove the class definition from
<div id="1" class="span3 well homeBox opaque btn-purple">
<span class="siteBoxContent">What do we do?</span>
</div>
And here is the error I'm getting while debugging in the Webkit Error Console
TypeError: 'undefined' is not an object (evaluating 'fx.end[0]') jquery.effects.core.js:32
If I try to remove a class like 'homeBox', the removeClass works fine. Here is the definition for the homeBox class definition
.homeBox
{
position:relative;
width:26.666666666667%;
height:200px;
}
So I'm guessing jQuery may have a problem with removing classes which have background-image, colour or even the filter attributes. If you require any more information, please let me know. Thanks in advance for your help.
Use:
$("#1").removeClass("btn-purple");
Instead of:
$("#1").removeClass("btn-purple", 1000);
since there is not second argument available for it and 1000 doesn't make any sense there.
Two possible signatures of it are:
.removeClass( [className] )
.removeClass( function(index, class) )
More Info:
http://api.jquery.com/removeClass/
You use a function signature that doesn't exist:
removeClass("classname", integer) // WRONG
There's no such possibility in JQuery AFAIK, you can do:
.removeClass( [className] )
.removeClass( function(index, class) ) // from version 1.4
I don't understand what 1000 stands for, but I bet that removing it should fix the issue.

CSS Sprite for Submit Button not working (In Rails 3)

I'm having trouble getting my CSS sprite effect to work in my rails app, not sure why because I don't totally understand the concept.
Heres my submit button code:
<%= f.submit '', :class => 'submitpost'%>
and the CSS behind it:
.submitpost {
border: none;
height: 40px;
width: 145px;
background: url('sharebutton_up.jpg') 0 0;
}
.submitpost:hover {
cursor:pointer;
height: 40px;
width: 145px;
background: url('sharebutton_down.jpg') 0 -40px;
}
Thanks in advance!
background: url('sharebutton_down.jpg') 0 -40px;
I think you should remove -40px since you have changed the images from sharebutton_up to sharebutton_down already

sIFR 3 - I can't get it to display anything

I'm trying to implement the latest sIFR. But I can't get even the simplest of tests to work. My test page is at http://www.kellymitchelljewelry.com/testsifr.asp. There should be an sIFR-generated line that says "2nd line" between the first and third lines. I'm using the examples provided on the sIFR page exactly.
My html looks like this:
<html>
<head>
<title>Kelly Mitchell Fine Jewelry</title>
<link rel="stylesheet" href="sifr.css" type="text/css">
<script src="sifr.js" type="text/javascript"></script>
<script src="sifr-config.js" type="text/javascript"></script>
</head>
<body>
First Line<br><br>
<h1>Second Line</h1>
<br>Third Line<br><br>
</body>
</html>
My sifr-config.js looks like this:
var cgoth = { src: 'cgoth.swf' };
sIFR.activate(cgoth);
sIFR.replace(cgoth, {
selector: 'h1'
});
My sifr.css file looks like this:
#media screen {
.sIFR-flash {
visibility: visible !important;
margin: 0;
padding: 0;
}
.sIFR-replaced, .sIFR-ignore {
visibility: visible !important;
}
.sIFR-alternate {
position: absolute;
left: 0;
top: 0;
width: 0;
height: 0;
display: block;
overflow: hidden;
}
.sIFR-replaced div.sIFR-fixfocus {
margin: 0pt;
padding: 0pt;
overflow: auto;
letter-spacing: 0px;
float: none;
}
}
#media print {
.sIFR-flash {
display : none !important;
height : 0;
width : 0;
position : absolute;
overflow : hidden;
}
.sIFR-alternate {
visibility : visible !important;
display : block !important;
position : static !important;
left : auto !important;
top : auto !important;
width : auto !important;
height : auto !important;
}
}
/*
Place CSS rules for to-be-replaced elements here. Prefix by .sIFR-active
so they only apply if sIFR is active. Make sure to limit the CSS to the screen
media type, in order not to have the printed text come out weird.
*/
#media screen {
.sIFR-active h1 {
font-family: Verdana;
visibility: hidden;
line-height: 1em;
}
*/
I've tried recreating my swf file just in case I did something wrong, and closely followed the instructions to make sure I didn't leave anything out.
Can someone help me figure what I'm doing wrong?
Tom
I don't think your Flash movie is correct, opening it directly should show "Rendered with sIFR 3" text. Make sure it was exported correctly.
I have never been able to get a .swf file exported from Flash to work with sIFR. I've always ended up having to use the online sIFR generator: http://www.sifrgenerator.com/wizard.html
I don't know if my version of Flash (CS3) is just not compatible with sIFR or what... I do always save as version 8 like it says to, and make sure every setting is as it should be, but no luck. However, using that generator always seems to solve it. So if your Flash is jinxed to, you might want to give it a try.

Resources