innoveit / play2-pdf Goto Github PK
View Code? Open in Web Editor NEWA PDF module for Play Framework 2
License: MIT License
A PDF module for Play Framework 2
License: MIT License
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
<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?
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
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
?
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.
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:
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.
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 ..."
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)
We need to fix CVE report problems.
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-36944
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-29425
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 ?
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.
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:
The malicious we could have:
public
folder.Hope to hear more opinions.
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?
We need to upgrade Sbt version to 1.7.x
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).
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>
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
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 è)
Has anyone figured out how to force the PDF rendering to being a new page?
Document has render in portrait orientation by default.
How can I render it in landscape orientation?
Hello.
Cyrillic chars are broken if don't set meta tag utf-8. And don't renders if set meta tag.
thanks.
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?
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
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)
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
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());
}`
i.e. play.api.i18n.Messages
I need to generate my PDFs based on a user's preferred language. How would I do this with this package?
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.
if i use scala template with tag 'meta charset="utf-8', then word 'ТЕКСТ' disappear...
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.
When I generate a PDF from my laptop everything works well, but when I generate it from an Ubuntu server some of the characters are not encoded correctly.
Laptop generated PDF
https://drive.google.com/open?id=0B2fKdPvkC8IGSno4b3JBR3lKcGs
Ubuntu Server generated PDF
https://drive.google.com/open?id=0B2fKdPvkC8IGaVlxUl8xNHBDd1E
HTML Source
https://drive.google.com/open?id=0B2fKdPvkC8IGaWNOV1ZZMVN5bU0
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:
Other suggestions to consider as acceptable to merge are:
approved
or merge-when-gtg
) to the 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)
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.