-
Notifications
You must be signed in to change notification settings - Fork 678
Closed
Labels
Description
Describe the bug
HTML export - When image and text divs are rendered one after the other, they are placed NEXT TO each other, instead of one AFTER the other.
To Reproduce
import com.lowagie.text.Document;
import com.lowagie.text.html.HtmlWriter;
import com.lowagie.text.xml.SAXmyHandler;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
public class Sandbox {
private static final String XML = """
<?xml version="1.0" encoding="UTF-8" ?>
<itext producer="iTextSharpXML">
<paragraph><image url="./my_image.png" plainwidth="400" plainheight="225"></image></paragraph>
<paragraph>ABC</paragraph>
<paragraph>DEF</paragraph>
</itext>
""";
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException {
OutputStream os = new FileOutputStream("output1.html");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Document document = new Document();
HtmlWriter htmlWriter = HtmlWriter.getInstance(document, out);
htmlWriter.setImagepath("./");
ByteArrayInputStream is = new ByteArrayInputStream(XML.getBytes("UTF-8"));
//parsing XML report template
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(is, new SAXmyHandler(document, new HashMap<>()));
os.write(out.toByteArray());
}
public static InputStream convertToInputStream(byte[] s) {
if (s == null) return null;
InputStream is = null;
is = new java.io.ByteArrayInputStream(s);
return is;
}
}
Expected behavior
The image should appear above the text.
Instead, it appears AFTER the text:
System
- OS: Windows 11
- Used font:
- OpenPDF version: 2.0.3
Your real name
Maayan Bin Nun
