Skip to content

how to convert to html use go-tika? #27

@imqishi

Description

@imqishi

in java api, we can convert file to html like this:

public static String extractHtml(File file) throws IOException {
    byte[] bytes = Files.toByteArray(file);
    AutoDetectParser tikaParser = new AutoDetectParser();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler handler;
    try {
        handler = factory.newTransformerHandler();
    } catch (TransformerConfigurationException ex) {
        throw new IOException(ex);
    }
    handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
    handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
    handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    handler.setResult(new StreamResult(out));
    ExpandedTitleContentHandler handler1 = new ExpandedTitleContentHandler(handler);
    try {
        tikaParser.parse(new ByteArrayInputStream(bytes), handler1, new Metadata());
    } catch (SAXException | TikaException ex) {
        throw new IOException(ex);
    }
    return new String(out.toByteArray(), "UTF-8");
}

can go-tika do this? when we use

client := tika.NewClient(nil, s.URL())
body, err := client.Parse(context.Background(), f)

what is the body's content? or how to understand this return?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions