Vytvořte HTML pomocí knihovny Java

Naše výkonná knihovna Java umožňuje vývojářům programově vytvářet HTML v několika krocích

Vývojáři z Java mohou snadno vytvořit HTML pouze pomocí našeho výkonného rozhraní API. To znamená, že naše řešení poskytne programátorům vše, co potřebují k vytvoření HTML v Java.

Zobrazit fragment kódu

Vytvořte HTML v Java programově

S naší knihovnou Java mohou vývojáři snadno vytvořit HTML od nuly. K tomu potřebují vývojáři Java provést jen několik kroků:

  1. Přidejte název souboru
  2. Začněte vytvářet HTML dokument pomocí Java
  3. Uložte výstupní HTML soubor

Za zmínku stojí, že prázdný dokument má technicky obsahovat jeden odstavec, takže když programově vytvoříte HTML dokument, získáte přesně tu základní strukturu dokumentu.

Všimněte si, že můžete okamžitě přidat obsah do nově vytvořeného HTML souboru. Získáte tak nejen prázdný dokument, ale dokument obsahující potřebný obsah. Další informace o úpravě dokumentu naleznete na stránce Úpravy.

Vytvořte HTML v Java

Tato knihovna Java umožňuje programově vytvářet HTML dokumenty. Vyzkoušejte naše výkonné funkce a pomocí následujícího příkladu se podívejte, jak vytvořit HTML v některých formátech:

Vytvořit nový HTML pomocí Java
Vyberte cílový formát ze seznamu
Spustit kód
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>aspose-words</artifactId>
  <version>ver</version>
  <classifier>jdk17</classifier>
</dependency>
Kopírovat
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
Kopírovat
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
 <artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
Kopírovat
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
Kopírovat
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Font font = builder.getFont();
font.setName("Courier New");
font.setColor(Color.BLUE);
font.setSize(36);
font.setHighlightColor(Color.YELLOW);

builder.write("Morbi enim nunc faucibus a.");

doc.save("Output.html");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.html"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.html", saveOptions);
import com.aspose.words.*;

Document doc = new Document();

Run run = new Run(doc, "Proin eros metus, sagittis sed.");
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(run);

Comment comment = new Comment(doc);
comment.setAuthor("John Doe");
comment.setInitial("JD");
comment.setDateTime(new Date());
comment.setText("Quisque fringilla leo.");

CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.getId());
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.getId());

run.getParentNode().insertBefore(commentRangeStart, run);
run.getParentNode().insertAfter(commentRangeEnd, run);
commentRangeEnd.getParentNode().insertAfter(comment, commentRangeEnd);

comment.addReply("Jane Doe", "JD", new Date(), "Pellentesque vel sapien justo.");

doc.save("Output.html");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.html"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.html", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);

builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci.
if (secondRun.getNextSibling() != null)
    builder.moveTo(secondRun.getNextSibling());
else
    builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");

doc.save("Output.html");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.html"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.html", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertChart(ChartType.PIE, 432, 252);
Chart chart = shape.getChart();
chart.getTitle().setText("Demo Chart");

chart.getSeries().clear();
chart.getSeries().add("Series 1",
        new String[] { "Category1", "Category2", "Category3" },
        new double[] { 2.7, 3.2, 0.8 });

doc.save("Output.html");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.html"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Pokud je NextSibling null, pak je to s největší pravděpodobností poslední Run v odstavci. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.html", saveOptions);
Spustit kód

Jak vyrobit HTML v Java

  1. Nainstalovat Aspose.Words for Java
  2. Přidejte odkaz na knihovnu (importujte knihovnu) do svého Java projektu
  3. Vytvořte nový HTML dokument
  4. Zavolejte metodu save() a předejte název souboru
  5. Získejte výsledek jako samostatný soubor

Knihovna Java k vytvoření HTML

Naše balíčky Java hostujeme v úložištích Maven. 'Aspose.Words for Java' je běžný JAR obsahující bajtový kód. Postupujte prosím podle pokynů krok za krokem, jak jej nainstalovat do vašeho vývojářského prostředí Java.

Požadavky na systém

Podporována je Java SE 7 a novější Java Poskytujeme také samostatný balíček pro Java SE 6 pro případ, že jste povinni používat toto zastaralé JRE.

Náš Java je multiplatformní a běží na všech operačních systémech s JVM, včetně Microsoft Windows, Linux, macOS, Android a iOS.

Informace o volitelných závislostech balíčků, jako je JogAmp JOGL, Harfbuzz písem Java Advanced Imaging JAI, naleznete v dokumentaci produktu.

Další podporované formáty souborů

Můžete vytvářet dokumenty v jiných formátech souborů:

5%

Přihlaste se k odběru aktualizací produktu Aspose

Získejte měsíční zpravodaje a nabídky přímo do vaší poštovní schránky.

© Aspose Pty Ltd 2001-2024. Všechna práva vyhrazena.