Twelve
Twelve

Reputation: 597

How to use custom css file when converting page to pdf using EvoPDF?

I want to use custom, external CSS file when converting my ASP.NET MVC page to pdf using EvoPDF library. I don't see anywhere any Styles property that indicates it could be done, is it possible? Do you know any workaround to have specific CSS styles only for conversion using EvoPdf?

Upvotes: 0

Views: 999

Answers (2)

Cameron Lattz
Cameron Lattz

Reputation: 83

You could use the CSS @media rule to target only a certain mediatype. You could then set the mediatype of the rendered HTML using EvoPDF:

var pdfConverter = new HtmlToPdfConverter(serverIp, serverPort)
        {
            MediaType = "evopdf"
        };

Upvotes: 1

EddyHaigh
EddyHaigh

Reputation: 13

I have an automatic process to create a Style.cshtml file which is a partial injected into the default layout.

var gulp = require('gulp'),
fs = require('fs'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
gap = require('gulp-insert');

gulp.task('default', function () {
     return gulp.src("Content/main.scss")
         .pipe(sass())
         .pipe(rename("_style.cshtml"))
         .pipe(gap.wrap("<style>\n", "</style>"))
         .pipe(gap.transform(function (contents, file) {
          // Prevent @Fontface etc from causing errors
          return contents.replace(/@/g, "@@");
          }))
          .pipe(gulp.dest("Views/Shared/"));
});

Upvotes: 0

Related Questions