Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML export - When image and text divs are rendered one after the other, they are placed next to each other #1274

Open
maayanb180 opened this issue Mar 3, 2025 · 0 comments
Labels

Comments

@maayanb180
Copy link

maayanb180 commented Mar 3, 2025

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:

Image

System

  • OS: Windows 11
  • Used font:
  • OpenPDF version: 2.0.3

Your real name

Maayan Bin Nun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant