pdfHTML: Support attr() function for content property
Background:
Supporting the attr()
CSS function for content property has been a long-requested feature for users of our popular pdfHTML add-on. In previous versions we did not have the ability to support this feature which caused limitations in some use cases.
However, with this release of pdfHTML 3.0.5 we are pleased to announce support for this function has been added.
What is the attr() function?
As the specification explains: "The attr()
CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet. It can also be used on pseudo-elements, in which case the value of the attribute on the pseudo-element's originating element is returned."
As the specification notes however, "support for properties other than content
is experimental, and support for the type-or-unit parameter is sparse." Thus, we currently only support the content property in pdfHTML.
Example Use Case:
Code Snippet:
JAVA:
JAVA
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.kernel.pdf.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
PdfDocument pdfDocument = new PdfDocument(new PdfWriter("cmp_checkAttrFunctionWithTypeTest.pdf"));
HtmlConverter.convertToPdf(new FileInputStream("inputHtml.html"),pdfDocument);
}
}
C#
C#
using iText.Html2pdf;
using System.IO;
namespace Example
{
class Program
{
static void Main(string[] args)
{
using (FileStream htmlSource = File.Open("inputHtml.html", FileMode.Open))
using (FileStream pdfDest = File.Open("output.pdf", FileMode.OpenOrCreate))
{
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
}
}
}
}
Resources
Right-click the link below and select "Save link as..." to download