converting an HTML page to a PDF
So the answer to this ended up being a combination of a few things.
1) I had to edit the CSS to make sure images were actually staying within the bounds of the "100%" of the page. I added CSS to make sure all images maxed out at 90%. This prevented any side-to-side scrolling on the page and prevented anything getting cut off in the PDF.
2) I went into the Page Setup section off of the File menu in the browser, went to the "Margins and Footers" tab and there were the places that were inscribing things like date/url/page number. I blanked all those out and all was good.
3) The trickiest part was making sure it split pages in the correct places. I finally learned about the CSS properties called page-break-before
and page-break-inside
. I created classes with each of these set like so:
// Creates a page break in the PDF right before element with this class
.pagebreak{
page-break-before: always;
}
// Doesn't allow the contents of a div with this class to split across pages.
.nobreak{
page-break-inside: avoid;
}
and, when converted to PDF, it read these and laid out the pages as I wanted. It was a bit tedious, but I ended up with the exact PDF that I wanted!
How to convert Html page to Pdf in android studio
Try this code :
PdfConverter converter = PdfConverter.getInstance();
String directory_path = Environment.getExternalStorageDirectory().toString();
File file = new File(directionPath, "name_file.pdf");
String htmlString = "<html><body><p>Hello World</p></body></html>";
converter.convert(getContext(), htmlString, file);
click
here to add file PdfConverter
Converting HTML files to PDF
The Flying Saucer XHTML renderer project has support for outputting XHTML to PDF. Have a look at an example here.
Related Topics
How to Style the Progressbar Component in Javafx
Firebaselistadapter Not Pushing Individual Items For Chat App - Firebase-Ui 3.1
How to Parse Jsonarray in Android
Javafx on Linux Is Showing a "Graphics Device Initialization Failed For: Es2, Sw"
How to Round a Number to N Decimal Places in Java
How to Parse Invalid (Bad/Not Well-Formed) Xml
How to Get the Path of a Running Jar File
How to Break Out of Nested Loops in Java
How to Create a Memory Leak in Java
Find Div Element by Multiple Class Names
Android 6.0 Multiple Permissions
Org.Apache.Http.Entity.Fileentity Is Deprecated in Android 6 (Marshmallow)
How to Stop Repeated Keypressed()/Keyreleased() Events in Swing
How to Create an Executable Jar With Dependencies Using Maven
Avoiding Nullpointerexception in Java
Why Don't Java'S +=, -=, *=, /= Compound Assignment Operators Require Casting