-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print buton does not work (print.js error) #24
Comments
Can you share a reproducible example or more information about your scenario (vaadin version, component version, if this is browser specific, etc)? I did a quick test in the latest Vaadin version and latest component version and printing works okay. See |
Your example works (printing). Hmm interesing, maybe it works because of springboot. I am not using springboot. I am using java 17, pnpm, vaadin-cdi, some other addons, webpack latest vaadin and latest addon version. The app is deployed on Payara 5.2022.3, the application is war not jar. Sorry i can not share the real app with you. I tried different browser (safari lates osx) and throws the same error. |
New error: Uncaught Not Found (webpack-internal:///../target/flow-frontend/print-js/dist/print.js:468:9) |
It seems vaadin build wrong path to dynamic content. It is missing the app context root before /VAADIN/... |
Steps to reproduce error: 1) Go to : https://vaadin.com/hello-world-starters 2) Choose started : VAADIN 23 - CDI 3) add pdf addon + pdf files in resources + web pack flag 4) Run payara , deploy war 5) Print PDF NOT working, download working OK Zip project sample not working properly: |
I have a similar issue with both the download and print function. I'm using Spring boot, Vaadin 23 and java 17. Rather than reading a pdf file from disc as in the pdf-viewer-test sample provided above (which works fine with my setup), I'm using JasperExportManager to export to a temporary pdf file as follows:
The pdf displays OK in the viewer, but both print and download fail with "java.io.IOException: Stream Closed" error (even though I have not programmatically closed the stream). I think this means the stream has already been consumed in setting the Viewer and unavailable to print/download. Any help appreciated. |
any news about that ? |
Any fixes for print button not working ? It takes wrong URL for file (without context root of app) thus file not found 404 and print button not working. |
The problem is in file "print.js" in line 811: params.printable = /^(blob|http|\/\/)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== '/' ? '/' + params.printable : params.printable); // Get the file through a http request (Preload) It only gets origin of window which does not include app context root. If the app is deployed on server behind reverse-proxy (the url of app is mapped by external domain, context path is hidden), then the print works. Example:
|
I now have the download and print buttons working with an inputstream source on the fly using the following code:
I had originally created a temp file from JasperPrint, but here the StreamResource is derived from a PDF byte array by way of ByteArrayInputStream. I'm using pdfviewer version 2.7.2 in Vaadin 23.3.5. |
I have exact same code as you (from 1 year ago), always from byte array input stream (it is also jasper report byte pdf data). BUT still does not work. Download working, print not working (because print.js build wrong URL path to get the PDF source, see the comments above). pdfviewer version 2.7.2 in Vaadin 24.0.4 (but even with vaadin 23 does not work). |
So I'm running my code in development with no reverse proxy at http://localhost:8080/ - not tried it in production server yet. My issue (see previous post) was that when the InputStream is assigned to a variable before instantiating StreamResource, the PDF is displayed correctly in the viewer, but the download creates an empty PDF and the print does nothing because the stream is empty (had been consumed, but I don't get the print.js javascript error you described above). If the StreamResource is instantiated directly with "new ByteArrayInputStream(byteArray"), the PDF is populated correctly. So this produces an empty (corrupt) PDF:
But this works:
However I think that may be different to your problem. |
Try running the app with context root instead. Example: /AppName https/localhost:8181/AppName Without context root (empty) it is working. But we have multiple war deployed , so we cannot have empty context root of app. |
You're right, I can reproduce the error by configuring the root context path. As you said above, it seems to be a problem with "window.location origin" in print,js which only gets the base URL. I think it should be window.location origin + window.location.pathname as per this: https://www.samanthaming.com/tidbits/86-window-location-cheatsheet/ |
Yp. Probably fix. I guess it will never be fixed. |
@scrmtrey91 Are you customer of ours with some subscription tier? If yes, which one? |
We have Vaadin Pro Subscription. |
Probably don't want the entire pathname. It will include the route path, which you don't want. You will want only context path and servlet mapping (vaadin.urlMapping) if configured. |
Hi, // Create your StreamResource StreamRegistration streamRegistration = VaadinSession.getCurrent().getResourceRegistry().registerResource(streamResource); // Create a full string URI // Create a PdfViewer instance and set the source with the full URI |
I solved it using same approach from @jm2rodriguez, but keeping it relative
|
Print button is displayed correctly but it does not work, it does not print the PDF.
Error is in javascript of print.js:
I need this feature to work for clients. Now they download the PDF first then print it with windows or browser native viewer.
But i really want to use your addon because it is great and clean with only the necessary functions.
The text was updated successfully, but these errors were encountered: