Giter Site home page Giter Site logo

play2-pdf's People

Contributors

eximius313 avatar felipebonezi avatar fhars avatar gertv avatar gpgekko avatar hashanchamikara avatar joergviola avatar marcosinigaglia avatar mgosk avatar raisercostin avatar wolfert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

play2-pdf's Issues

Presentation of generated PDF

How can i set orientation to landscape for generated pdf?
How can i resize my table in generated pdf?
i.e. all properties for generated pdf ?????

Please reply soon
Thanks

Not able to add colored text to my PDF

<strong style="font-size: 150%; color: #FF0000">RUSH</strong>

This simply shows RUSH as bold with bigger font...but in black. How do I get it in red?

Support scala 2.13

I think you need to publish this lib to work with scala 2.13, as for now, it returns with not found if I tried to use it

[BUG] problems with reading images with proxy_pass

Let's say we have a template:

<html>
<head>
  <meta charset="UTF-8">
  <title>my title</title>
</head>
<body>
<div class="photo"
      style="background-image: url('@routes.ImageController.myPicture("funnyCat")')"></div>
</body>
</html>

and we use it like this:

  public Result preparePdf() {
    final String host = routes.HomeController.index().absoluteURL(request());
    return ok(pdfGenerator.toBytes(views.html.myPdf.render(), host))
        .withHeader("Content-Disposition", "attachment; filename*=UTF-8''My.pdf")
        .as("application/pdf");
  }

and - what is important - our application.conf looks like this:

play {
  http {
    secret.key="secret_here"
    hostname = "myhost.io"
  }
  filters {
    enabled=[play.filters.hosts.AllowedHostsFilter]
    hosts.allowed=["myhost.io"]
  }
}

If you run stage locally - everything works fine and photos are displayed in PDF.
BUT if you are running your server with Apache mod_proxy:

    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    ProxyPass           /               http://localhost:9009/  nocanon
    ProxyPassReverse    /               http://localhost:9009/

then even if: final String host = routes.HomeController.index().absoluteURL(request()); points correctly to https://myhost.io, PDF is generated but no photos are displayed, nor exception is thrown.
It just fails silently!

Workaround that I found after hours of investigation is that you must use http://localhost:9009 for both:

//    final String host = routes.HomeController.index().absoluteURL(request());
    final String host = "http://localhost:9009";

and

  filters {
    enabled=[play.filters.hosts.AllowedHostsFilter]
    hosts.allowed=["myhost.io", "localhost:9009"]
  }

Why play2-pdf reads photos from localhost:9009 even though I'm pointing it specifically to myhost.io?

UTF-8

Hi,
thanks for your commits in this project.

Do you have problems with encoding?
Can you help me to solve it?
Look at my example in this image:
capturar

The example is not working in caracteres like "ç", "ã","õ"....

Best regards,
Carlos

Change orientation / resolution of generated pdf

I was working with this plugin and in HTML, I am using bootstrap's rows and cols, so when I am trying to generate a PDF with that HTML it is not rendered as columns(always in rows style, same when you decrease browser screen side).
So I was thinking is there any way to change the width of PDF or change the orientation to horizontal?
Thanks in advance.

Improve project management

Hi 👋🏻 @marcosinigaglia
Why won't you create a new repository without a fork reference?

We could maintain this project and I would like to help you.

We could implement the following to improve project management:

  • GitHub Actions for CI/CD
  • Project labels to easily identify a new issue or PR state
  • Release versions using the GitHub's release manager

Little actions could increase help from the community. If you see this repository has a lot of forks and stars.

If you need help, I'm very pleasant to help.

Does not work with play 2.

Setup
sbt.version=0.13.11
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0")

libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk" % "1.7.1",
"it.innove" % "play2-pdf" % "1.4.0"
)

"Conflicting cross-version suffixes in ..."

Problem with image rendering

Hello, i'm having some problems rendering a logo in a pdf.

In the scala template I've tried to load it both with @routes.Assets.at() and @routes.Assets.versioned(). If I render normally the template, the image shows up, when I use return pdfGenerator.ok(PDFList.render(courseSession), request().host());, no image.
The image is a simple .png file.

I'm using Play Framework 2.5 and play2-pdf 1.6.0 version (firstly tried with 1.7, but didn't worked)

use this lib on play 2.4.x

Hi,

this lib look pretty nice but i can't upgrade the project to 2.5.x for use it.

there is a way this lib can be used in play 2.4.x ?

Broken PDF images when run in production mode

Hi there,

I've been using this module and it have worked wonderfully. But when I run my application in production mode, the PdfGenerator renders the images incorrectly.

Has anyone the same problem?
Have you found any solution?

Thanks in advance.

Is it really needed to use all Play dependencies?

I was reviewing the project and realized that we're using all Play modules defined into project/plugin.sbt.

We could improve our dependency to Play only using the exact module that we need.
The two main problems we will suffer is that we use Results.Result as the main return from PdfGenerator.ok(...) as we can see at here and play.Environment as the helper class to get all resources (e.g. Images, CSS, etc) files from public folder.

From my research I see that we're using the following modules:

I believe that we could remove this method and return only byte[] and InputStream as the available returns to render the PDF and implement another way to get the resources from the public folder (maybe using something very similar to play.Environment implementation).

The benefits we could have are:

  • Do not have to maintain all related modules from Play updated;
  • Do not be exposed to all bugs related to all modules from Play;
  • Significantly reduce the size of the project.

The malicious we could have:

  • It's a breaking change feature, so, a Migration Guide is needed and could be not well received by the users;
  • We couldn't know how to implement a good solution to get all resources files from public folder.

Hope to hear more opinions.

.css styles ignored

Hello and thanks for the great module.

I am trying to attach a .pdf file to an email by using val pdf = pdfGenerator.toBytes(pdf.render(object), "http://localhost:9000/") and it seems like the .css files are ignored; something that is not happening when I include an image to it (both included with @routes.Assets.public("file.ext")).

Generated .pdf contains all the images (as it should) but there is no style applies to it.

Maybe this might be related to this issue?

Erroned documentation

Hi,

Nice project, but the documentation is wrong on the front page :

PdfGenerator.ok and PdfGenerator.toBytes except two parameters (Html, String), not one (Html).

Does not output colored font / background.

Something as simple as the below template does not work. It creates the pdf but the text is black and the background color is still white. Am I missing something, or does this really not support colored font / background?

Specifically, I am doing the following from my Controller:
return ok(pdfGenerator.toBytes(previewStuff.render(), urlBase)).as("application/pdf");

This is the scala view template file (previewStuff.scala.html):
@()

<div style='color: blue;'>
hi there
</div>
\div style='background-color: red'>
bye there
</div>

Error on play 2.5.x

After upgrade to play 2.5.3 i have following error.

ExecutionError: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: play/mvc/Results$Status

Encoding issue

Hi,

When using :

return ok(Html)

the output contains accent correctly, but when changing it to :

return PdfGenerator.ok(Html)

The generated PDF contains wrongly encoded accents (è instead of è)

Landscape orientation

Document has render in portrait orientation by default.
How can I render it in landscape orientation?

Problem with cyrillic

Hello.
Cyrillic chars are broken if don't set meta tag utf-8. And don't renders if set meta tag.

thanks.

PDF as an attachment

Hello, I'm posing this question here as this project does not seem to have a chat. I need to both serve PDF directly to the client and/or as an attached document to an email. Can this be done with play2-pdf?

Thank you.

Also, in keeping with Play's vision of being 100% reactive and non-blocking, do you have any plans to migrate from java to scala?

Cannot render .SVG file in .scala.html

Is there any chance that play2pdf does not support .svg in .scala.html files?

I have seen all flying saucer examples and I couldn't make any of them work.
<svg> tags wont work
<img source="logo.svg"> wont work
<object data="logo.svg"> wont work

Fonts rendering fail

Hello, I have an issue: When I download PDF using Chrome (last version 60) document rendering fails, server immediately returns empty file. But when I use Chrome in private everything works fine, server spend some time and finally returns pdf with data.
Here is stack trace:

[ERROR] - from application in application-akka.actor.default-dispatcher-37
Error creating document from template
org.xhtmlrenderer.util.XRRuntimeException: /tmp/tmp_Roboto-Black7459385378730820963.ttf not found as file or resource.
at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:218)
at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:193)
at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:188)
at it.innove.play.pdf.PdfGenerator.toStream(PdfGenerator.java:111)
at it.innove.play.pdf.PdfGenerator.toBytes(PdfGenerator.java:97)
at it.innove.play.pdf.PdfGenerator.toBytes(PdfGenerator.java:92)
at it.innove.play.pdf.PdfGenerator.ok(PdfGenerator.java:72)

Use constructor injection instead of field injection

PdfGenerator uses filed injection:

@Inject
Environment environment;

public PdfGenerator() {

}

therefore there is no possibility to configure it at all, because if you do:

public class ApplicationModule extends AbstractModule {
  @Override
  protected void configure() {
    bind(PdfGenerator.class).toProvider(PdfGeneratorProvider.class).asEagerSingleton();
  }
  
  static class PdfGeneratorProvider implements Provider<PdfGenerator> {
    private final PdfGenerator pdfGenerator;

    public PdfGeneratorProvider() {
      this.pdfGenerator = new PdfGenerator();
      this.pdfGenerator.loadLocalFonts(asList("fonts/opensans-regular.ttf"));
    }

    @Override
    public PdfGenerator get() {
      return pdfGenerator;
    }
  }
}

then you end up in NullPointerException (because environment is null!)

If you just change it to construction injection:

final Environment environment;

@Inject
public PdfGenerator(final Environment environment) {
        this.environment = environment;
}

then everything works and is backward compatibile

Images served from a Play controller are not added to PDF

I'm rendering a template as HTML and making it into a PDF with play2-pdf.
When I use an image served through the Assets controller the image is added to the PDF, but when I use an image served through my own Controller method, it doesn't seem to be added to the PDF at all.
This is how I serve the image in my own controller:
`@Authenticated(Secured.class)

public Result getPublicFile(String file) {
    File f = new File(methodToGetFilePathHere(file));

    MediaType mime;
    try {
        mime = MediaType.parse(Files.probeContentType(f.toPath()));
    } catch (IOException e) {
        e.printStackTrace();
        return badRequest();
    }
    return ok(f, true).as(mime.type()+"/"+mime.subtype());
}`

Problems with encoding.

Hello.
Please look, can you have any ideas what could be the problem.
When generating pdf there is a problem with the symbols.

example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
@*<meta charset="utf-8"/>*@
<title>Title</title>
</head>
<body>
<div class="pdf-content">
<div class="pdf-label">Label</div>
<div> ТЕКСТ Russian </div>
</div>
</body>
</html>

Html render = template.render();
byte[] content = pdfGenerator.toBytes(render, "http://localhost:9001");

if i use scala template without tag 'meta charset="utf-8', then word 'ТЕКСТ' have wrond encode.
wrong

if i use scala template with tag 'meta charset="utf-8', then word 'ТЕКСТ' disappear...
disappear

html it turns out right. But pdf wrong.
html

Local file not loaded

Hi,

when callign a file from local (instead of absolute url), like CSS or Images, the PdfGenerator fails with the error :

java.net.MalformedURLException: no protocol: /public/css/general.css

But

System.out.println(Play.current().resourceAsStream("/public/css/general.css")); correctly returns true.

Implement GitHub Actions to CI & CD

We need to improve our code validation using GHA to check, validate, test, and build our project before any new PR is merged into the master branch.

I have a suggestion to run the build/test action only if:

  1. The code is well formatted (using sbt-java-formatter);
  2. The code is binary compatible with the previous versions (using MiMa).

Other suggestions to consider as acceptable to merge are:

  1. Build must be completed successfully (no exceptions, nor even by admins);
  2. All the tests must pass successfully (no exceptions, nor even by admins);
  3. At least one review by an admin before the merge is available;
  4. Add a label (such as approved or merge-when-gtg) to the PR;
  5. We could use Mergify to set these rules to have an automatic way to merge PR.

Last but not least, about the merge strategy, I would prefer rebase/squad instead of merge to maintain the project with a linear history of change.

Does anyone have a different opinion? (cc @marcosinigaglia)

"activator run" dont start when adding innoveit pdf module into dependencies

Hello
i was trying to add PDF module into build.sbt

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
jdbc,
javaEbean,
cache,
ws,
"mysql" % "mysql-connector-java" % "5.1.34",
"it.innove" % "play2-pdf" % "1.2.0"
)

when i do it and run the activator i get this.

[trace] Stack trace suppressed: run last compile:run for the full output.
error java.lang.NoSuchMethodException: play.core.server.NettyServer.mainDevHttpMode(play.core.BuildLink, play.core.BuildDocHandler, int)
[error] Total time: 8 s, completed 17.06.2015 19:58:34

when i remove the "it.innove" % "play2-pdf" % "1.2.0" its working again. please i need help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.