Comments (5)
openhtmltopdf does not support opacity
it looks like you may be using the alpha channel here as an analogue for HSL-style "lightness". you can achieve this effect by rendering the html as you would expect in a browser, and then using an eyedropper tool to get the RGB value of the rendered color
from openhtmltopdf.
BTW, the community is in the process of transitioning to a new repo at https://github.com/openhtmltopdf/openhtmltopdf because danfickle is no longer maintaining this repository.
from openhtmltopdf.
The following method converts rgba in html to rgb
public static final Color BACK_GROUND = new Color(255, 255, 255);
public static final String RGBA_REGEX = "rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)";
public static final Pattern PATTERN = Pattern.compile(RGBA_REGEX);
public static String rgbaToRgb(String htmlString) {
Matcher matcher = PATTERN.matcher(htmlString);
// Replace the matching RGBA color to RGB format
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
int red = Integer.parseInt(matcher.group(1));
int green = Integer.parseInt(matcher.group(2));
int blue = Integer.parseInt(matcher.group(3));
// alpha
float alpha = Float.parseFloat(matcher.group(4));
red = (int) (red * alpha + BACK_GROUND.getRed() * (1 - alpha));
green = (int) (green * alpha + BACK_GROUND.getGreen() * (1 - alpha));
blue = (int) (blue * alpha + BACK_GROUND.getBlue() * (1 - alpha));
// Convert RGBA to RGB
String rgbColor = "rgb(" + red + ", " + green + ", " + blue + ")";
matcher.appendReplacement(sb, rgbColor);
}
matcher.appendTail(sb);
return sb.toString();
}
from openhtmltopdf.
from openhtmltopdf.
Feel free to open an issue at the other repo with this code snippet. It would be cool if we could add transparency support.
from openhtmltopdf.
Related Issues (20)
- Upgrade pdfbox to 3.0.0 HOT 1
- can we use this in browser like sandbox?
- Suggestion: Image not rendering inside JAR in container Docker
- Tamil character using @font-face Noto-sans-tamil is not rendering properly
- Batch processing stuck in openhtmltopdf(PdfBoxFontResolver.java)
- en-dash – character can not show in pdf
- LGPL vs Apache 2 HOT 2
- Large Html conversion consume much memory HOT 2
- > Using separate resources can be achieved by providing your own FSStreamFactory: HOT 1
- Evaluation for error observation for accuracy in total transparency of my own financial documents of transitory experience....
- Button group with tick HOT 5
- There is a problem with converting the href tag to pdf HOT 3
- how to handle text with \n
- Is the Project actively supported HOT 3
- tables with CSS transform scale are not rendered
- Find out computed element CSS style value
- "modules": ["expo.modules.backgroundfetch.BackgroundFetchModule"] HOT 1
- Support for attachment files HOT 2
- base64 images not loaded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openhtmltopdf.