iText7 don't work when I use CSS3 function target-counter in property content
I am very new to iText7. I am trying to create a pdf from a dynamic HTML string. So far I have been able to create the pdf using HtmlConverter.ConvertToPdf(). But the problem is that I need have a table of contents with chapters and page numbers at begin of the document. To do that, I wrote in my CSS file:
@page {
margin: 40mm 17mm 17mm 17mm;
size: A4 portrait;
@top-center {
content: element(header);
width: 100%;
}
@bottom-right-corner {
content: counter(page);
}
}
a::after {
content: leader('.') target-counter(attr(href), page)
}
And I wrote in my HTML file:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{${baseUrl} + '/static/css/relatorio_fiscalizacao.css'}"/>
</head>
<body>
<h1>ÍNDICE</h1>
<ul style="page-break-after: always;">
<li><a href="#ch1">STAFF</a></li>
<li><a href="#ch2">OPERATION DATA</a></li>
</ul>
<h1 id="ch1" class="chapter">STAFF</h1>
<p style="page-break-after: always;">....</p>
<h1 id="ch3" class="chapter">OPERATION DATA</h1>
<p style="page-break-after: always;">....</p>
</body>
</html>
And finally, I have a component in my Spring Boot application:
@Component
public class PdfGeneratorUtil {
@Autowired
private TemplateEngine templateEngine;
@Autowired
ServletContext servletContext;
@Autowired
private ApplicationContext context;
@Value("${baseUrl}")
private String baseUrl;
public ByteArrayOutputStream createPdf(String templateName, Map<String, Object> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
Assert.notNull(templateName, "The templateName can not be null");
System.out.println(baseUrl);
map.put("baseUrl", baseUrl);
IWebContext ctx = new SpringWebContext(request, response, servletContext, LocaleContextHolder.getLocale(), map, context);
String processedHtml = templateEngine.process(templateName, ctx);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(processedHtml, os, converterProperties);
System.out.println("PDF created successfully");
}
finally {
if (os != null) {
try {
os.close();
} catch (IOException e) { /*ignore*/ }
}
}
return os;
}
}
iText converts to Pdf fine. But the chapters from table of contens come up without the number of pages. And Log returns "Content property target-counter is either invalid or uses unsupported function."
I saw the file CssContentPropertyResolver.java and I realized that the code not treat the CSS function "target-counter". So, my question is: There is an other way to do that, maybe creating custom CSS appliers like this tutorial? Or maybe other way? If not, anybody know any other library that I could use instead iTextPdf?
css spring-boot itext thymeleaf html2pdf
add a comment |
I am very new to iText7. I am trying to create a pdf from a dynamic HTML string. So far I have been able to create the pdf using HtmlConverter.ConvertToPdf(). But the problem is that I need have a table of contents with chapters and page numbers at begin of the document. To do that, I wrote in my CSS file:
@page {
margin: 40mm 17mm 17mm 17mm;
size: A4 portrait;
@top-center {
content: element(header);
width: 100%;
}
@bottom-right-corner {
content: counter(page);
}
}
a::after {
content: leader('.') target-counter(attr(href), page)
}
And I wrote in my HTML file:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{${baseUrl} + '/static/css/relatorio_fiscalizacao.css'}"/>
</head>
<body>
<h1>ÍNDICE</h1>
<ul style="page-break-after: always;">
<li><a href="#ch1">STAFF</a></li>
<li><a href="#ch2">OPERATION DATA</a></li>
</ul>
<h1 id="ch1" class="chapter">STAFF</h1>
<p style="page-break-after: always;">....</p>
<h1 id="ch3" class="chapter">OPERATION DATA</h1>
<p style="page-break-after: always;">....</p>
</body>
</html>
And finally, I have a component in my Spring Boot application:
@Component
public class PdfGeneratorUtil {
@Autowired
private TemplateEngine templateEngine;
@Autowired
ServletContext servletContext;
@Autowired
private ApplicationContext context;
@Value("${baseUrl}")
private String baseUrl;
public ByteArrayOutputStream createPdf(String templateName, Map<String, Object> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
Assert.notNull(templateName, "The templateName can not be null");
System.out.println(baseUrl);
map.put("baseUrl", baseUrl);
IWebContext ctx = new SpringWebContext(request, response, servletContext, LocaleContextHolder.getLocale(), map, context);
String processedHtml = templateEngine.process(templateName, ctx);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(processedHtml, os, converterProperties);
System.out.println("PDF created successfully");
}
finally {
if (os != null) {
try {
os.close();
} catch (IOException e) { /*ignore*/ }
}
}
return os;
}
}
iText converts to Pdf fine. But the chapters from table of contens come up without the number of pages. And Log returns "Content property target-counter is either invalid or uses unsupported function."
I saw the file CssContentPropertyResolver.java and I realized that the code not treat the CSS function "target-counter". So, my question is: There is an other way to do that, maybe creating custom CSS appliers like this tutorial? Or maybe other way? If not, anybody know any other library that I could use instead iTextPdf?
css spring-boot itext thymeleaf html2pdf
1
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18
add a comment |
I am very new to iText7. I am trying to create a pdf from a dynamic HTML string. So far I have been able to create the pdf using HtmlConverter.ConvertToPdf(). But the problem is that I need have a table of contents with chapters and page numbers at begin of the document. To do that, I wrote in my CSS file:
@page {
margin: 40mm 17mm 17mm 17mm;
size: A4 portrait;
@top-center {
content: element(header);
width: 100%;
}
@bottom-right-corner {
content: counter(page);
}
}
a::after {
content: leader('.') target-counter(attr(href), page)
}
And I wrote in my HTML file:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{${baseUrl} + '/static/css/relatorio_fiscalizacao.css'}"/>
</head>
<body>
<h1>ÍNDICE</h1>
<ul style="page-break-after: always;">
<li><a href="#ch1">STAFF</a></li>
<li><a href="#ch2">OPERATION DATA</a></li>
</ul>
<h1 id="ch1" class="chapter">STAFF</h1>
<p style="page-break-after: always;">....</p>
<h1 id="ch3" class="chapter">OPERATION DATA</h1>
<p style="page-break-after: always;">....</p>
</body>
</html>
And finally, I have a component in my Spring Boot application:
@Component
public class PdfGeneratorUtil {
@Autowired
private TemplateEngine templateEngine;
@Autowired
ServletContext servletContext;
@Autowired
private ApplicationContext context;
@Value("${baseUrl}")
private String baseUrl;
public ByteArrayOutputStream createPdf(String templateName, Map<String, Object> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
Assert.notNull(templateName, "The templateName can not be null");
System.out.println(baseUrl);
map.put("baseUrl", baseUrl);
IWebContext ctx = new SpringWebContext(request, response, servletContext, LocaleContextHolder.getLocale(), map, context);
String processedHtml = templateEngine.process(templateName, ctx);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(processedHtml, os, converterProperties);
System.out.println("PDF created successfully");
}
finally {
if (os != null) {
try {
os.close();
} catch (IOException e) { /*ignore*/ }
}
}
return os;
}
}
iText converts to Pdf fine. But the chapters from table of contens come up without the number of pages. And Log returns "Content property target-counter is either invalid or uses unsupported function."
I saw the file CssContentPropertyResolver.java and I realized that the code not treat the CSS function "target-counter". So, my question is: There is an other way to do that, maybe creating custom CSS appliers like this tutorial? Or maybe other way? If not, anybody know any other library that I could use instead iTextPdf?
css spring-boot itext thymeleaf html2pdf
I am very new to iText7. I am trying to create a pdf from a dynamic HTML string. So far I have been able to create the pdf using HtmlConverter.ConvertToPdf(). But the problem is that I need have a table of contents with chapters and page numbers at begin of the document. To do that, I wrote in my CSS file:
@page {
margin: 40mm 17mm 17mm 17mm;
size: A4 portrait;
@top-center {
content: element(header);
width: 100%;
}
@bottom-right-corner {
content: counter(page);
}
}
a::after {
content: leader('.') target-counter(attr(href), page)
}
And I wrote in my HTML file:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{${baseUrl} + '/static/css/relatorio_fiscalizacao.css'}"/>
</head>
<body>
<h1>ÍNDICE</h1>
<ul style="page-break-after: always;">
<li><a href="#ch1">STAFF</a></li>
<li><a href="#ch2">OPERATION DATA</a></li>
</ul>
<h1 id="ch1" class="chapter">STAFF</h1>
<p style="page-break-after: always;">....</p>
<h1 id="ch3" class="chapter">OPERATION DATA</h1>
<p style="page-break-after: always;">....</p>
</body>
</html>
And finally, I have a component in my Spring Boot application:
@Component
public class PdfGeneratorUtil {
@Autowired
private TemplateEngine templateEngine;
@Autowired
ServletContext servletContext;
@Autowired
private ApplicationContext context;
@Value("${baseUrl}")
private String baseUrl;
public ByteArrayOutputStream createPdf(String templateName, Map<String, Object> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
Assert.notNull(templateName, "The templateName can not be null");
System.out.println(baseUrl);
map.put("baseUrl", baseUrl);
IWebContext ctx = new SpringWebContext(request, response, servletContext, LocaleContextHolder.getLocale(), map, context);
String processedHtml = templateEngine.process(templateName, ctx);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.convertToPdf(processedHtml, os, converterProperties);
System.out.println("PDF created successfully");
}
finally {
if (os != null) {
try {
os.close();
} catch (IOException e) { /*ignore*/ }
}
}
return os;
}
}
iText converts to Pdf fine. But the chapters from table of contens come up without the number of pages. And Log returns "Content property target-counter is either invalid or uses unsupported function."
I saw the file CssContentPropertyResolver.java and I realized that the code not treat the CSS function "target-counter". So, my question is: There is an other way to do that, maybe creating custom CSS appliers like this tutorial? Or maybe other way? If not, anybody know any other library that I could use instead iTextPdf?
css spring-boot itext thymeleaf html2pdf
css spring-boot itext thymeleaf html2pdf
asked Nov 19 '18 at 23:05
Antonio RodriguesAntonio Rodrigues
111
111
1
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18
add a comment |
1
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18
1
1
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383907%2fitext7-dont-work-when-i-use-css3-function-target-counter-in-property-content%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383907%2fitext7-dont-work-when-i-use-css3-function-target-counter-in-property-content%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you please share the GitHub link to the code? It will be really easy to reproduce the issue.
– Kunal Puri
Nov 20 '18 at 2:18