Wicked_PDF struggles to display Bootstrap 4 styles

After addressing my previous issue with wicked_pdf, I am now facing a problem where the PDF generated is not displaying the Bootstrap styling of the application.

The technologies I'm using include bootstrap 4, ruby '2.4.2', and gem 'rails', '~> 5.2.1'

Here is a snippet from app/controllers/proposals_controller.rb:

def show
    @proposal = Proposal.find(params[:id])
    @custom_content = @proposal.custom_contents
    respond_to do |format|
      format.html
      format.pdf do
        render pdf: "some_name",
               template: "proposals/show.pdf.erb",
               layout: "pdf.html",
               margin: { top: 35, bottom: 35 }
      end
    end
  end

Below is part of app/views/layouts/pdf.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title>PDF</title>
  <%= wicked_pdf_stylesheet_link_tag "application" -%>
</head>
<body>
<div class='container d-flex justify-content-center'>
  test 2
  <%= yield %>
</div>
</body>
</html>
app/views/proposals/show.pdf.erb

<div class="row full-page justify-content-center" id="cover">
  <div class="container">
    <div class="row p-0">
      <div class="col-12 d-flex align-items-end ">
        <%= wicked_pdf_image_tag '1209232_1920-1.jpg' %>
      </div>
    </div>
    <div class="row pt-1 d-flex align-items-end text-justify">
      <div class="col-12 text-justify cover-background">
        <div class="row pt-1">
          <h2 class="text-white text-justify">Proposal For <br> Maintenance</h2>
        </div>
        <div class="row p-0">
          <div class="col-6">
            <h5 class="text-white text-justify">Prepared For: <%= @proposal.contact.name %></h5>
            <h6></h6>
          </div>
          <div class="col-6">
            <h5 class="text-white text-justify">Prepared By: <%= @proposal.user.name %></h5>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

In the stylesheet located at app/assets/stylesheets/application.scss, you can find:

// $navbar-default-bg: #312312;
// $light-orange: #ff8c00;
// $navbar-default-color: $light-orange;
$brand-color: #30AADD;

@import "font-awesome-sprockets";
@import "font-awesome";
@import "bootstrap";
@import "sticky-footer";
@import "announcements";
@import "summernote-bs4";
@import "summernote-custom-theme.min";
@import "material_icons";


// Proposal Cover
.full-page {
  min-height: 100vh;
}
.cover-image{
  background-image: url('https://heliportstudios.com/wp-content/uploads/2016/09/new-york-1209232_1920-1.jpg');
  max-width: 100%;
  max-height: 100vh;
}

.cover-background {
  background: $brand-color;
}

plus alot of custom styling

I have searched extensively for solutions to this issue but none seem to be effective.

Answer №1

To properly display the PDF in pdf.html.erb, make sure to include the bootstrap css file.

<head>
  <title>PDF</title>
  <%= wicked_pdf_stylesheet_link_tag "application" -%>
  <%= wicked_pdf_stylesheet_link_tag "bootstrap" %>
</head>

Remember to add the bootstrap.css file to your assets/stylesheets folder for it to be referenced correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for preventing breaks in typography

I have implemented a material ui Typography component, but it's causing a line break even though there is enough space. Here is the code snippet: <Box flexDirection="row"> <Typography> Gender: <RadioGroup row ...

jQuery Slider not appearing on the page

I am attempting to incorporate the Basic jQuery Slider into my website. Below is the code I have used: For HTML file: <div id="slides"> <ul class="bjqs"> <li><a href="somelink"><img src="someim ...

When the line-height is adjusted, nearby buttons and the text underneath them will shift downwards after a button is clicked

I am facing a challenge with my .button class. When the button is in its active state, I have added an inset box shadow and increased the line-height by 2 to create a button press effect. However, the adjacent button and text below it also move down, which ...

Tips for creating a flexbox layout that is responsive to different screen

Currently, I am using flex to ensure that the two inner div elements have the same height. However, the design is not responsive as it appears perfectly in a full-width window but gets squeezed on mobile devices. Is there a solution to this issue? Are th ...

The website covers the entire page, but I prefer it not to

During the development of my website, I encountered a challenge: How to confine it within a wrapper or container set at 1000px rather than occupying the entire webpage. Below is the HTML code: <!DOCTYPE html> <div class="wrap"> <html> & ...

Click on the text to be directed to the linked page

I have an interesting issue. I have an image that, when hovered over, displays some text. What I'd like to do is add a hyperlink within that text. For instance, the text might say "hello my name is," and I want to include "click to find out" as a cli ...

Choose a unique text color

Having trouble with my HTML select form and modifying text color for specific options. In the provided example, I changed the color for the Tuesday option, but it only shows up when scrolling through the options. How can I make the color change visible for ...

Position a full-width image with an SVG mask to the right, outside of the container using Bootstrap

I'm currently experimenting with aligning an image with a SVG mask to the right, outside of a container, but it's causing overflow issues. Interestingly, when I switch and align the image to the left, there is no overflow problem. At the moment, ...

The sticky footer seems to have lost its stickiness

I am facing an issue with the sticky footer on my website, as it doesn't stick properly and I'm struggling to find a solution. Here is the HTML code snippet: html.tpl.php <?php ?> <!DOCTYPE html> <head> <?php $head; ?> ...

The Bootstrap row does not display divs in a stacked formation when viewed on smaller screens

My layout is using bootstrap rows for two divs. I want them to be side by side on large devices, but stacked on small devices. However, Bootstrap is not stacking them on small devices and they are still both sitting at 50%. The specific divs I am talking ...

Learn how to utilize AngularJS Material to toggle the enable/disable functionality of a checkbox

Can someone assist me in enabling and disabling the checkbox as shown in the attachment image https://i.stack.imgur.com/l6g1C.jpg View the PLNKR angular.module('BlankApp', ['ngMaterial']) .config(['$mdThemingProvider', fun ...

Showing two hyperlinks in distinct columns within a table

I am encountering an issue with my system that showcases video tutorials. The code I have currently displays the video name (eNISATQuestion) and the video link (eNISATVideo) within one href tag. My goal is to include another column that will display a lin ...

Display data in JSON format along with a designated header

How can I include the cors header when rendering JSON in my controller? 'Access-Control-Allow-Origin' = '*'. I attempted to do this: def my_action render(json: some_params) response.headers['Access-Control-Allow-Origin' ...

What is the process for setting an object's property as a href in an AJAX call?

I've got a quick query. How can I assign an object's property to the href attribute? I've indicated the line with a comment. success: function (listOfTags) { let tagData = ''; $.each(listOfTags, function (i, tag) { ...

Bizarrely rapid transitions from standard to hovering appearance in CSS

After creating a custom styled button with a hover effect, I noticed an issue where if you happen to hover over a specific spot on the button, it quickly switches between its normal and hover states. https://i.sstatic.net/uPq1F.gif This is my code: but ...

CSS loop to centrally align divs

I am facing an issue where I want to center the divs in a panel. Each div is generated within a for-each-loop inside the panel. However, the problem arises when they are displayed as block elements: https://i.sstatic.net/RvnlX.jpg When I try floating them ...

Transforming fonts into various web-compatible font formats

This morning, I delved into the fascinating world of fonts as I am in need of a specific font for my CSS project. It appears to be quite complex to rely on others for correct font types, so I started exploring methods to convert fonts from one type to ano ...

What are the options for customizing JSON output in Ruby on Rails?

I have a model that represents different languages and I need to retrieve them in JSON format. The current output looks like this: [{"language":{"created_at":null,"id":1,"language":"English","updated_at":null}},{"language":{"created_at":null,"id":2,"lan ...

What is the most effective way to showcase a variety of random styles for various text elements within a single webpage?

Currently brainstorming some new concepts and contemplating a unique site layout idea that involves randomizing the styles of specific elements on a webpage. For instance, envision having 10 paragraphs on one page where each paragraph is presented in a dif ...

Creating a div overlay triggered by the addition of a child tag

Using the Paypal zoid feature, I have a button that opens an iframe in the parent div when clicked. However, the iframe causes the other contents of the website to shift around, making it look messy. I'm wondering if there is a way to make the parent ...