danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Home Page:https://danfickle.github.io/pdf-templates/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In line font color not printing specified color code,

mgabhishek06kodur opened this issue · comments

I'm tried to print font with color it is not printing specified font color, in inline style

import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.w3c.dom.Document;
import com.lmats.oms.reports.pdfreports.PdfReportUtils;
import com.lmats.oms.reports.pdfreports.ReportPage;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;

private static String htmlToPdf(String inputHTML, String outputPdf) throws IOException {
	Document doc = html5ParseDocument(inputHTML);
	String baseUri = FileSystems.getDefault().getPath(AppConstants.GENERAL_SECTION5TEMP).toUri().toString();
	OutputStream os = new FileOutputStream(outputPdf);
	PdfRendererBuilder builder = new PdfRendererBuilder();
	builder.withUri(outputPdf);
	builder.toStream(os);
	builder.useFont(new File(AppConstants.FOLDER_FONTS + "Calibri.ttf"), "Calibri");
	builder.withW3cDocument(doc, baseUri);
	builder.run();
	logger.debug("PDF generation completed in html to pdf");
	os.close();
	return outputPdf;
}

private static Document html5ParseDocument(String inputHTML) throws IOException {
	org.jsoup.nodes.Document doc;
	logger.debug("parsing ...");
	doc = Jsoup.parse(new File(inputHTML), "UTF-8");
	logger.debug("parsing done ..." + doc);
	return new W3CDom().fromJsoup(doc);
}

Could you post the HTML in question? It should look something like:

<span style="color: #f1f100;">some text</span>
<title>GENTest - Test observations and results</title> <style type="text/css" media="print">
  • {margin:10; padding:0; outline:2px dashed blue}
    body {font-size:12px;font-family:'Calibri'; margin:25px; background:#fff; color:#091f30}
    .testObservationsAndResults {font-size:12px;text-align:justify}
    .testComments {font-size:12px;text-align:justify}
    li{
    font-weight:700;
    font-weight:normal;
    margin-left: 100px;
    }
    ol li ol li{
    margin-left: 20px;
    }

@font-face {
font-family: myFont;
}
.fontclass{
font-family: myFont;
}
@page {
size: 8.5in 11in;
margin: 1in;
}

@page {
size: 8.5in 11in;
margin: 1in;
}

.content-box
{
background-repeat:repeat-y;
background-position: center;
background-attachment:fixed;
background-size:100%;
}
</style>

Test observations and results

? T racking and monitoring orders is perhaps the most fundamental aspect of any OMS . Once an ecommerce brand grows beyond the smallest size, it needs some kind of system to handle orders. Even the most proficient, on-the-ball worker can?t keep all order details in their head.

  1. At heart, an OMS is about making life easier for both a brand and its customers. The correct system can create a more seamless customer experience. It can also make inventory management, logistics, and more processes far more intuitive.

The placement and handling of orders impact many other elements of your business. Every order placed and fulfilled, for instance, affects your inventory. Getting inventory management correct is vital for any ecommerce brand.

If you don?t have an accurate measure of your inventory, a range of issues can arise

  • Overselling ? Accepting orders for products of which you don?t have adequate stock to fulfill. Doing so leads to canceling those orders and disappointing customers.

  • Overstocking ? Thinking you?re short of a product and over-ordering replacement inventory. This means you waste valuable warehouse space and could get left with dead stock.

  • Inaccurate Forecasting ? If you don?t have accurate inventory figures, it?s harder to understand customer demand. You may miss when there?s an uptick in desire for a particular product. That could see you run out of stock when you might have pre-empted the increased demand.



Test comments

Encompass Reverse Logistics

All ecommerce businesses know that returns are an inevitability. Approximately 30% of products bought online get returned. That?s as compared to less than 10% bought in-store. Handling returned items and dealing with the customers who sent them back is vital to order management. With the right OMS, reverse logistics becomes much more straightforward. A top-class system gives you many options in this regard. You may, for instance, be able to clone an original order to create a credit instantly. That makes it more straightforward to manage refunds, replacements or reorders. An OMS, too, makes it more intuitive to fold reverse logistics into inventory management. Depending on what?s returned, the system can give you a range of options. It may write off stock that?s sent back, quarantine it, or add it back to your inventory on-hand.

All ecommerce businesses know that returns are an inevitability. Approximately 30% of products bought online get returned. That?s as compared to less than 10% bought in-store. Handling returned items and dealing with the customers who sent them back is vital to order management. With the right OMS, reverse logistics becomes much more straightforward. A top-class system gives you many options in this regard. You may, for instance, be able to clone an original order to create a credit instantly. That makes it more straightforward to manage refunds, replacements or reorders. An OMS, too, makes it more intuitive to fold reverse logistics into inventory management. Depending on what?s returned, the system can give you a range of options. It may write off stock that?s sent back, quarantine it, or add it back to your inventory on-hand.



The placement and handling of orders impact many other elements of your business. Every order placed and fulfilled, for instance, affects your inventory. Getting inventory management correct is vital for any ecommerce brand.

Hi @mgabhishek06kodur,

We don't support the attributes on the ancient font tag. However, if you can't use CSS instead in your template, you can use a DOM mutator to change the document at runtime. Here is one I just created:

        FSDOMMutator domChanger = (doc) -> {
            NodeList fontTags = doc.getElementsByTagName("font");

            for (int i = 0; i < fontTags.getLength(); i++) {
                Element fontTag = (Element) fontTags.item(i);

                if (fontTag.hasAttribute("color")) {
                    String color = fontTag.getAttribute("color");

                    if (!fontTag.hasAttribute("style")) {
                        fontTag.setAttribute("style", "color: " + color + ';');
                    } else {
                        String oldStyle = fontTag.getAttribute("style");
                        String newStyle = oldStyle + "; color: " + color + ';';

                        fontTag.setAttribute("style", newStyle);
                    }
                }
            }
        };

Then, you can register with:

builder.addDOMMutator(domChanger);

P.S. To paste code or HTML in comments, put it in a code block. A code block starts with four backticks on their own line, followed by the HTML, then four more backticks on their own line. This is a backtick: `

Also added FAQ entry on dom mutators

Assumed solved. Please reopen as required.