The filename is always optional and must not be used blindly by the application: path information should be stripped, and conversion to the server file system rules should be done. This parameter provides mostly indicative information. When used in combination with Content-Disposition: attachment , it is used as the default filename for an eventual "Save As" dialog presented to the user.
Warning: The string following filename should always be put into quotes; but, for compatibility reasons, many browsers try to parse unquoted names that contain spaces. This simple HTML file will be saved as a regular download rather than displayed in the browser.
Most browsers will propose to save it under the cool. It doesn't contain any of the extra page metadata that the browser print method included. However, notice what happens between page one and two. The table extends all the way down to the bottom of the first page and then just picks right back up at the top of the second page.
There is no extra margin applied, and the table text content has the potential to be cut in half, which is actually what happens between pages six and seven. The PDF also doesn't include the repeating table column headers or table footer, which was the same problem we saw in Safari's print functionality.
While jsPDF is a powerful library, it seems like this tool may work best when the exported content can fit on just one page. Let's take a look at our second open-source library, pdfmake. With over , weekly downloads from NPM and a seven-year lifespan, this library is even more popular and more senior than jsPDF. While building the export functionality for my demo app, the configuration for pdfmake was considerably harder than it was for jsPDF.
That means that rather than providing pdfmake with a reference to my HTML table, I had to provide it data for the header, footer, content, and layout of my PDF table. Not too shabby! We get to include styles for our table, so we can still reproduce the blue column headers and striped table row backgrounds. We also get the repeating table column headers to make it easy to keep track of what data we're seeing in each column on each page. You'll notice though that the table content between page one and page two still isn't separated perfectly.
The page break partially splits the row for between the pages. Overall, it seems like pdfmake's greatest strength is in constructing PDFs from scratch. If, for example, you wanted to generate an invoice based on some order data, and you don't actually show the invoice on the screen inside of your web app, then pdfmake would be a great choice. The last option we'll consider is DocRaptor. DocRaptor differs from the first three options we explored in that it is a paid service.
The basic DocRaptor configuration is fairly simple. You provide it the name of your document, the type of document you want to create 'pdf' in our case , and the HTML content to use. There are hundreds of other options for various configurations depending on what you need, but the basic configuration is an excellent starting point.
Now there's a good-looking document! We get to keep our nice table styles. The table column headers and table footer are repeated on every page. The table rows don't get cut off, and there is an appropriately sized margin on all sides of the page.
The page header is repeated on every page as well, and so are the page numbers at the bottom of each page. Viewed k times. Top-Master 4, 3 3 gold badges 20 20 silver badges 38 38 bronze badges. Wilco Wilco Similar issue here stackoverflow. Add a comment. Active Oldest Votes. HoldOffHunger Pascal Pascal. See w3. Greg Greg k 52 52 gold badges silver badges bronze badges.
But Content-disposition is more correct. USE force-download. They might work, but are useless here. RFC w3. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
0コメント