I am using wicked_pdf for generating pdf in my rails application.
I need to display a map on pdf with iframe.
I used bellow code for the map.
%iframe{:frameborder => "0", :height => "200", :src => "https://maps.google.com/maps?q=#{spot_details.lat}, #{spot_details.lng}&hl=es;z=14&output=embed", :style => "border:0;width:100%;margin-bottom:20px"}
But it gives me simple frame without map like this http://storage1.static.itmages.com/i/17/0515/h_1494853712_9065572_7571a033f7.png
Anyone, please suggest me how to display map on wicked_pdf with rails application.
It appears to be working for me.
Commit adding Google map in Iframe to wicked_pdf_issues project
Resulting PDF - default style issue, but definitely working
Do you have other JavaScript or stylesheets that could be interfering?
It could be a timing issue if you have a slow connection from Google to your server.
Try increasing the default JavaScript rendering timeout with the option javascript_delay like this:
render pdf: 'mypdf',
javascript_delay: 5000 # wait 5 seconds for JS to fully execute
Related
I am working on a project using Gatsby, Strapi and Cloudinary. I am deploying the frontend on Netlify and the Strapi app on Heroku (with the addition of a Postgresql database instance).
I have been searching for weeks now and but I cannot seem to find a way to lazy-load images sourced through Cloudinary.
I have replaced the default rich content editor on Strapi with the ckeditor so editors can add photos to their content. These are automatically uploaded and served by Cloudinary.
My question is, is there a way to lazy-load the images, and if so, should this be done when serving them from Cloudinary, should I do this as a Strapi middleware or simply through Gatsby?
Note: I am not sourcing the images anywhere on the front-end since it's parsed as html from Strapi. All I'm currently doing in passing the fetched content to a div using
dangerouslySetInnerHtml.
With dangerouslySetInnerHtml directive you are inserting whatever is inside your rich text as HTML content so you lose control of customizing the behavior of that content. Hence, it will be rendered all at once.
There's no built-in way of doing this except by parsing your rich text with a third-party dependency (which I haven't been able to find)/custom method that will give you the capability of wrapping your images with any custom component. The idea, either way, is to parse your rich text blocks to customize the output.
In addition, check if the images tag (<img>) comes with the loading=lazy property attached:
<img src="image.jpg" alt="..." loading="lazy">
I need to convert a html page(with images, buttons and a lot of css) to PDF and I'm using yii.
I chose mPDF over HTML2PDF(no particular reason for that.) When I render a page for converting to PDF, the PDF doesn't load, but when I use renderPartial, the page loads(only the html part works here).
I want the page to be completely converted to PDF and I tried going through the mPDF documentation but I couldn't 'find' anything useful.
this is my code :
$mPDF1 = Yii::app()->ePdf->mpdf();
$mPDF1->WriteHTML(
$this->render('render_page',
array( ...),
true ));
//Output PDF file
$mPDF1->Output();
Please let me know if I have to provide more informations...
I am using CarrierWave to upload static HTML templates to certain user profiles on my webpage.
I am trying to render the HTML file on the user's home page once they log in. The Path for the HTML file after uploading is:
/uploads/profile/curation/8/User_Content.html
I'm new to rails and I thought I'd just be able to
<%= render /uploads/profile/curation/8/User_Content.html %>
to get the html to render, but I guess that only works for partials, which this is not.
Any advice?
You can use render_to_string. Please have a look over here. http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view
In your controller you can redirect to the page you want:
redirect_to "/uploads/profile/curation/8/User_Content.html"
What's the recommended way to add content to my rails app ? pages with cloud hosted images like amazon s3& formatted text ?
What I want is just to create a tutorial pages that are easily linked with an index page.
Is there a recommended approach rather than re-inventing the wheel ? what's the popular gems out there ?
If you need fixed content you have just to create an html in the public folder with the html that you need, and link directly from your index view to them.
In order to store the images in the cloud, just upload them and put a reference link to your page fixed content to it.
Otherwise, if you are building a dynamic page that you may upload new images and etc...
Use the paperclip gem. It is a good way to not reinvent the wheel!
So I am storing the whole embed code from youtube into my database and then outputting it like this.
<%= raw(people.video) %>
which outputs the general iframe tag copied from youtube:
<iframe src="foo" width=400 height=380></iframe>
the problem is that it actually displays that tag instead of embedding the video into the page itself. I can get around this just by storing the src in the database.... but this is part of a mini cms system and the site admins would find it much easier just to copy and past the embed code from youtube. Is there someway I can specify for the iframe to actually render instead of just spitting out the html on the page?
You can use the raw method to render the HTML of a string, are you storing it that way? You can also try the RedCloth gem - I was able to get this working like so:
<%= raw RedCloth.new(#page_content.content).to_html %>
Which allowed for my custom CMS to use the Textile markup
http://en.wikipedia.org/wiki/Textile_%28markup_language%29
I'm not 100% on what you're seeing, since raw should render HTML, but you might also try to include the embed tag using a JavaScript.write, since there are some issues related to Flash objects embedded in HTML vs JavaScript.
Let me know if this doesn't work, and if so, can you provide screenshots or copy what you're seeing on the page?