This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How do I convert my current HTML and CSS page (with the changes the user did) to a PDF file that can

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a webpage in which the user can make changes like highlighting an image, adding a comment and so on. What I want is when the user clicks on a submit button a PDF file of the web page with the changes is generated, so that I can send it to the user through email. Any help?
 
Saloon Keeper
Posts: 6798
162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Most operating systems can print a page to a PDF directly - MacOS and Windows 10 natively, and Linux via a freely available Print-to-PDF driver. So it sounds a bit like you intend to reinvent the wheel.
 
Heba Farid
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The printing feature you mentioned give the user the option to save the PDF on his/her own device. However, I want to have access to the PDF to send it through email.
 
Marshal
Posts: 26289
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those features which Tim mentioned all use the fact that the user's browser has already rendered the HTML/CSS/JavaScript?/etc page into a displayable (and therefore printable) format.

So if you want to do that on the server side, you're going to need something which simulates that process. I have no doubt that you can find that thing on the web, and I recommend that you do look for it there. Trying to write it yourself would not be a simple process.
 
Tim Moores
Saloon Keeper
Posts: 6798
162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Heba Farid wrote: I want to have access to the PDF to send it through email.


Why? What value does that add?

If you can restrict the pages to CSS-styled XHTML, then the Java library FlyingSaucer can do this.
 
Saloon Keeper
Posts: 23006
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be precise, in Linux, the "universal" print format is PostScript, and PDF is just PostScript in a metadata wrapper. So creating PDF's from Linux web browsers is trivially done via the standard Print dialog. It is the print driver's responsibility to convert PostScript to device-specific code such as HP PCL. The GhostScript program is what usually does this, in fact.

In Windows, it was more the reverse. Graphics output was in Window Metafile Format, which was really just a capture of raw Windows GDI commands, and the Windows print drivers would convert to raw device codes almost immediately instead of when the job was presented to a printer. Which was a pain, since you couldn't easily re-route such a job to a different brand of printer if you needed to. For a while there was, however, a booming market in third-party printer drivers that would "print to PDF".

By Windows 10, Microsoft had caught on, and printing to PDF is now built in, even though their approach is pretty weird.

I should note that unlike most devices, where a "driver" was the OS-to-hardware interface, in printing, the "printer driver" is more often a translator that sits between the original print request and the physical driver for the parallel (LPT) port, USB, or whatever.


So getting a PDF out can be as simple as displaying a printable web page.

The bigger problem is that web client programs are forbidden to run the printer directly without explicit user click-the-OK-button approval, much less saving as a PDF or emailing.

What you can do is save the user's indications in some format on the webapp server, merge that data into your prototype display, render it as PDF (using a Java PDF library) and then have the server do the emailing. So you're either talking about a fairly complex servlet or a servlet that sends a request to an offline processor using something like MQ, depending on how you like to partition things.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic