-
Notifications
You must be signed in to change notification settings - Fork 365
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
Render PDF from multiple HTML files #214
Comments
This will work, sort of. The only problem is the //214
public static void main(String...args) throws Exception {
String[] uris = new String[] {
"file:///Users/me/Documents/pdf-issues/issue-206.htm",
"file:///Users/me/Documents/pdf-issues/issue-180-p.htm"
};
PDDocument doc = new PDDocument();
for (String uri : uris) {
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withUri(uri);
builder.usePDDocument(doc);
PdfBoxRenderer renderer = builder.buildPdfRenderer();
renderer.createPDFWithoutClosing();
renderer.close();
}
OutputStream os = new FileOutputStream("/Users/me/Documents/pdf-issues/output/mytest-214.pdf");
doc.save(os);
os.close();
} |
Thanks @danfickle, it works!!! 😄 Although, I have some issues with characters like Also, code highlighting with http://prismjs.com/ isn't working same like in the browser. |
Hi @sake92 For the characters, you will still have to embed a valid font for most languages other than English. See the template author's guide on the readme for tips. In regard, to the prismjs, this project doesn't run Javascript, so you would probably need to find a Java syntax highlighter (see link below) or somehow get prismjs running in a Javascript runner available from Java (Nashorn or Rhino). https://stackoverflow.com/questions/1853419/syntax-highlighter-for-java |
@danfickle as far as I'm concerned, you can close this issue. Proposed solution works! 😌 If someone is interested, here is my implementation, from my static site generator: https://github.com/sake92/hepek/blob/master/src/main/scala/ba/sake/hepek/pdf/PdfGenerator.scala Example of PDF with some math: https://blog.sake.ba/pdfs/Matematika.pdf |
Dear @danfickle, how I can generate one PDF file with 2 pages from 2 html templates? |
I strongly recommend combining the templates if possible. Other than that, the sample above in this thread should work. What are you having trouble with? |
Thank you for quick reply. Yes, I've used the example above but with some modifications:
And it works but without "I strongly recommend combining the templates" - do you mean concatenate the two html templates? |
It works for me too. I implemented the integration of multiple processed templates (Thymeleaf) with once PDF file. On the Kotlin:
But if you have some special logic for all of these files, it will be hard to implement, for example, if you need common order with page numbers. |
public static void main(String...args) throws Exception {
Does doc(PDDocument instance) need to call close method? |
Hi @danfickle , the code you provided works for me to generate PDF from multiple HTML files, but it is adding each HTML as a new page and not starting from where previous page ended. |
Hi all, is it possible to render a PDF from multiple input files/strings, like in this example from flyingsaucer?
I had a problem with flyingsaucer, it throws something like "Page 21 was requested but document has only 20 pages"... 😞
I could set a
baseURL
for every page, on thesetDocumentFromString
method.With openhtmltopdf I should concatenate all the HTMLs into one, right? But the base folder is not the same for all of them... 😄 In some of them it is "../styles/main.css" but in some other "../../styles/main.css" (deeper folder)
The text was updated successfully, but these errors were encountered: