danfickle / danfickle/openhtmltopdf

sizing of inline SVGs ignored

Open
#778 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.2k
Forks
423
PR merge metrics
No merged PRs in 30d

Description

hey,
i am generating a PDF file from HTML string including inline svgs.

i am setting svg width and height via css as well as trying to set width and height via svg tag attribute. both seems to be ignored. what can i do to scale the inline svgs?

here is my html:
html including inline svgs

```html




@page {
/*size: 3508px 2480px;*/
margin: 0;
}
body {
background-color: #fff;
color: #000;
margin: 25px;
}
table {
width: 100%;
}
td {
text-align: center;
vertical-align: middle;
}
.entry {
width: 66%;
overflow: hidden;
border: 5px solid black;
border-radius: 25px;
display: flex;
flex-direction: column;
align-items: center;
text-align: justify;
}
.entry .hint {
padding: 25px;
background-color: black;
color: white;
font-size: 28px;
text-align: center;
width: 100%;
}
svg {
width: 300px;
height: 300px;
display: block;
}










1







2





```

html output aka expected output:
![image](https://user-images.githubusercontent.com/22223458/137601643-a4476f5c-fb10-42df-accb-9bfee77253d1.png)

pdf output:
![image](https://user-images.githubusercontent.com/22223458/137601658-93c37881-8bd2-4769-a757-501731a01fcc.png)

i am using the PdfRenderer like this (in Kotlin):
```kotlin
private fun JsoupDocument.toPdf(): ByteArrayOutputStream = ByteArrayOutputStream().use {
PdfRendererBuilder().apply {
withW3cDocument(W3CDom().fromJsoup(this@toPdf), "/")
toStream(it)
useSVGDrawer(BatikSVGDrawer())
run()
}
it
}
```

i am using following related dependencies:
```kotlin
implementation("com.openhtmltopdf:openhtmltopdf-pdfbox:1.0.10")
implementation("com.openhtmltopdf:openhtmltopdf-java2d:1.0.10")
implementation("com.openhtmltopdf:openhtmltopdf-svg-support:1.0.10")
implementation("com.openhtmltopdf:openhtmltopdf-slf4j:1.0.10")
implementation("org.jsoup:jsoup:1.13.1")
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.