Rails 5: render pdf file from html.erb and css templates
up vote
0
down vote
favorite
I'm trying to use princely gem to render diploma pdf for users who have finished courses to route users/:id/serve_diploma.
when I write this route, I see the browser get data and not errors, but I get a blank page.
These are my controller, css and html.erb files:
users_controller.rb
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
diploma.component.html.erb
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
diploma.css
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
ruby-on-rails ruby-on-rails-5 pdf-generation erb princexml
add a comment |
up vote
0
down vote
favorite
I'm trying to use princely gem to render diploma pdf for users who have finished courses to route users/:id/serve_diploma.
when I write this route, I see the browser get data and not errors, but I get a blank page.
These are my controller, css and html.erb files:
users_controller.rb
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
diploma.component.html.erb
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
diploma.css
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
ruby-on-rails ruby-on-rails-5 pdf-generation erb princexml
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to use princely gem to render diploma pdf for users who have finished courses to route users/:id/serve_diploma.
when I write this route, I see the browser get data and not errors, but I get a blank page.
These are my controller, css and html.erb files:
users_controller.rb
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
diploma.component.html.erb
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
diploma.css
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
ruby-on-rails ruby-on-rails-5 pdf-generation erb princexml
I'm trying to use princely gem to render diploma pdf for users who have finished courses to route users/:id/serve_diploma.
when I write this route, I see the browser get data and not errors, but I get a blank page.
These are my controller, css and html.erb files:
users_controller.rb
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
diploma.component.html.erb
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
diploma.css
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
def serve_diploma
@user = User.find_by_id!(params[:id])
completed_courses_id_array = @user.user_courses.select{|uc| uc.completed == true}.map(&:course_id)
@completed_courses_count = @user.user_courses.select{|uc| uc.completed == true}.map(&:completed).flatten.count
@user_courses_title_array = Course.find(completed_courses_id_array).map(&:title)
@courses_count = Course.all.count
@completion_date = @user.user_courses.order('completed_course_date DESC').first.completed_course_date
render :pdf => "#{@user.name}",
:template => '/shared/diploma.component.html.erb',
:stylesheets => '/public/diploma.css',
:formats => %w[pdf]
end
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
<div *ngIf="user" class="container frame">
<div class="inner-frame">
<h3 class="academy center">Superheros Academy</h3>
<h5 class="certificate center">This is to certify that</h5>
<h1 class="user-name center"><%= @user.name.upcase %></h1>
<h4 class="completed-courses center">has successfully completed the folowing courses (<%= @completed_courses_count %>/<%= @courses_count %>)</h4>
<% @user_courses_title_array.each do |uc| %>
<p class="course-list center"><%= uc %>,</p>
<h2 class="diploma center" style="padding-top:2%;">Diploma</h2>
<div class="row justify-content-lg-center align-items-center">
<div class="col-lg-4" style="padding-top:5%; float:left;">
<p class="date-ceo center"><%= @completion_date %></p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Date of Completion</p>
<p class="date-ceo"> </p>
</div>
<div class="col-lg-4 center">
<img src="../../assets/images/stamp.png" class="d-inline-block" style="height:200px;">
</div>
<div class="col-lg-4 center" style="padding-top:5%; float:right;">
<p class="date-ceo center"> </p>
<hr class="center" style="position:relative;">
<p class="completion-date-steve center">Peter Parker</p>
<p class="date-ceo center">CEO</p>
</div>
</div>
<% end %>
</div>
</div>
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
@page { size: A4 landscape; margin: 0; }
.center{
text-align: center !important;
}
.frame{
background-image: url('../../assets/images/frame.png');
background-repeat: no-repeat;
height: 21cm;
background-size: 100% 100%;
padding: 85px;
}
hr{
height: 1px;
border-top: 1px solid #ccc;
border-color: black;
width: 240px;
margin: -1em -1rem 2rem 3rem
}
.inner-frame{
position: relative;
}
.academy{
font-family: "Playfair Display";
font-size: 35px;
color: #3E3F46;
font-style: italic;
}
.certificate{
font-family: 'Open Sans';
font-weight: 100;
font-size: 25px;
color: #3E3F46;
}
.user-name{
font-family: 'Open Sans';
font-weight: bold;
font-size: 60px;
color: #3E3F46;
margin-top: -2%;
margin-bottom: -1%;
}
.completed-courses{
font-family: 'Open Sans';
font-size: 25px;
font-weight: 100;
color: #3E3F46;
}
.course-list{
font-family: 'Open Sans';
font-size: 22px;
color: #3E3F46;
padding: 0 100px;
}
.diploma{
font-family: 'Open Sans';
font-size: 40px;
}
.completion-date-steve{
font-family: 'Open Sans';
font-weight: bold;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
text-align: center;
}
.date-ceo{
font-family: 'Open Sans';
font-weight: 100;
font-size: 20px;
color: #3E3F46;
margin-top: -1rem;
}
ruby-on-rails ruby-on-rails-5 pdf-generation erb princexml
ruby-on-rails ruby-on-rails-5 pdf-generation erb princexml
asked Nov 21 at 15:29
Ofir Sasson
9614
9614
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415373%2frails-5-render-pdf-file-from-html-erb-and-css-templates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown