innoveit / play2-pdf

A PDF module for Play Framework 2
MIT License
77 stars 22 forks source link

Images served from a Play controller are not added to PDF #19

Closed DeveloperInResidence closed 8 years ago

DeveloperInResidence commented 8 years ago

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());
}`
marcosinigaglia commented 8 years ago

Hi, the module creates HTTP requests to load the resource in the PDF so the Authenticated call doesn't works since uses other headers.

DeveloperInResidence commented 8 years ago

Oh, I see, so it has to be completely openly accessible images? Guess I can create a temporary image, create the PDF, then remove the temporary image. Thanks!

marcosinigaglia commented 8 years ago

Yes, or you can create a temporary token for access the image.