Utwórz HTML za pomocą Java biblioteki

Nasza potężna Java biblioteka umożliwia programistom programowe tworzenie HTML w zaledwie kilku krokach

Programiści Java mogą łatwo tworzyć HTML, korzystając tylko z naszego zaawansowanego interfejsu API produktu. Oznacza to, że nasze rozwiązanie zapewni programistom wszystko, czego potrzebują do tworzenia HTML w Java.

Zobacz fragment kodu

Twórz program HTML w Java

Dzięki naszej Java bibliotece programiści mogą łatwo tworzyć HTML od podstaw. Aby to zrobić, programiści Java muszą wykonać tylko kilka kroków:

  1. Dodaj nazwę pliku
  2. Zacznij tworzyć HTML dokument za pomocą Java
  3. Zapisz wyjściowy HTML plik

Warto zauważyć, że technicznie pusty dokument powinien zawierać jeden akapit, więc gdy programowo utworzysz HTML dokument, otrzymasz dokładnie taką podstawową strukturę dokumentu.

Pamiętaj, że możesz natychmiast dodać zawartość do nowo utworzonego HTML pliku. W ten sposób otrzymasz nie tylko pusty dokument, ale dokument zawierający niezbędną treść. Aby uzyskać więcej informacji na temat edycji dokumentu, zobacz stronę Edycja.

Twórz HTML w Java

Ta Java biblioteka umożliwia programowe tworzenie HTML dokumentów. Wypróbuj naszą zaawansowaną funkcjonalność i zobacz, jak tworzyć HTML w niektórych formatach, korzystając z następującego przykładu:

Utwórz nowy HTML za pomocą Java
Wybierz format docelowy z listy
Uruchom kod
// 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>
Kopiuj
// 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')
Kopiuj
// 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>
Kopiuj
// 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"
Kopiuj
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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");
// Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie.
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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);
Uruchom kod

Jak zrobić HTML w Java

  1. Zainstaluj Aspose.Words for Java
  2. Dodaj odniesienie do biblioteki (zaimportuj bibliotekę) do swojego Java projektu
  3. Utwórz nowy HTML dokument
  4. Wywołaj metodę "save()", przekazując nazwę pliku
  5. Uzyskaj wynik jako osobny plik

Java biblioteka do utworzenia HTML

Nasze Java hostujemy w repozytoriach Maven. 'Aspose.Words for Java' to wspólny JAR zawierający kod bajtowy. Postępuj zgodnie z instrukcjami krok po kroku, jak zainstalować go w swoim środowisku programisty Java.

wymagania systemowe

Obsługiwana jest Java SE 7 i nowsze Java Udostępniamy również osobny pakiet dla Java SE 6 na wypadek, gdybyś musiał używać tego przestarzałego JRE.

Nasz Java jest wieloplatformowy i działa na wszystkich systemach operacyjnych z JVM, w tym Microsoft Windows, Linux, macOS, Android i iOS.

Aby uzyskać informacje na temat dodatkowych zależności między pakietami, takich jak JogAmp JOGL, Harfbuzz silnika czcionki, Java Zaawansowane obrazowanie JAI, zapoznaj się z dokumentacją produktu.

Inne obsługiwane formaty plików

Możesz tworzyć dokumenty w innych formatach plików:

5%

Subskrybuj aktualizacje produktów Aspose

Otrzymuj comiesięczne biuletyny i oferty dostarczane bezpośrednio do Twojej skrzynki pocztowej.

© Aspose Pty Ltd 2001-2024. Wszelkie prawa zastrzeżone.