Java에서 PDF 또는 Word 문서 만들기

충실도가 높은 Java 라이브러리를 사용하여 프로그래밍 방식으로 거의 모든 형식의 새 문서를 만듭니다.

Java 개발자는 프로그래밍 API를 사용하여 단 몇 줄의 코드로 PDF, DOC, DOCX, HTML, EPUB 및 기타 여러 형식으로 문서를 쉽게 만들 수 있습니다.

코드 스니펫 보기

Java 를 사용하여 문서 만들기

주어진 강력한 API를 사용하여 Java 개발자는 거의 모든 형식으로 문서를 작성할 수 있습니다. 이렇게 하려면 Java 라이브러리를 사용하여 몇 가지 단계를 수행해야 합니다.

  1. 파일 이름 추가
  2. Java 를 사용하여 문서 작성 시작
  3. 생성된 문서를 선택한 형식으로 저장

빈 문서는 기술적으로 하나의 단락을 포함해야 하므로 프로그래밍 방식으로 문서를 만들 때 정확히 그 기본 문서 구조를 얻게 된다는 점은 주목할 가치가 있습니다.

새로 만든 문서에 콘텐츠를 즉시 추가할 수 있습니다. 따라서 빈 문서뿐만 아니라 필요한 내용이 포함된 문서를 얻게 됩니다. 문서 편집 방법에 대한 자세한 내용은 편집 페이지를 참조하십시오.

프로그래밍 방식으로 Java 로 문서 만들기

주어진 Java 라이브러리를 사용하면 PDF, DOCX, DOC, RTF, ODT, EPUB, HTML 및 기타 지원되는 모든 형식의 문서를 프로그래밍 방식으로 만들 수 있습니다.

강력한 기능을 사용해 보고 다음 예를 사용하여 일부 형식으로 문서를 만드는 방법을 확인하십시오.

Java를 사용하여 새 문서 만들기
목록에서 대상 형식 선택
코드 실행
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.docx");
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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. 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.docx", 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.docx");
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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. 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.docx", 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");
// NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다.
if (secondRun.getNextSibling() != null)
    builder.moveTo(secondRun.getNextSibling());
else
    builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");

doc.save("Output.docx");
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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. 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.docx", 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.docx");
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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // NextSibling null인 경우 이것이 단락의 마지막 Run 일 가능성이 높습니다. 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.docx", saveOptions);
코드 실행

Java에서 문서를 만드는 방법

  1. Aspose.Words for Java 설치
  2. Java 프로젝트에 라이브러리 참조 추가(라이브러리 가져오기)
  3. 새 문서 만들기
  4. 파일 이름을 전달하여 save() 메서드를 호출합니다.
  5. 결과를 별도의 파일로 가져오기

문서를 만들기 위한 Java 라이브러리

Maven Java 패키지를 호스팅합니다. 'Aspose.Words for Java' 는 바이트 코드를 포함하는 일반적인 JAR Java 개발자 환경에 설치하는 방법에 대한 단계별 지침 을 따르십시오.

시스템 요구 사항

Java SE 7 및 최신 Java 버전이 지원됩니다. JRE 를 사용해야 하는 경우를 대비 Java SE 6 용 별도 패키지를 제공합니다.

Java Microsoft Windows, Linux, macOS, Android 및 iOS를 포함하여 JVM 구현된 모든 운영 체제에서 실행됩니다.

JogAmp JOGL, Harfbuzz 글꼴 엔진, Java Advanced Imaging JAI 와 같은 선택적 패키지 종속성에 대한 정보는 제품 설명서 를 참조하십시오.

가장 많이 사용되는 파일 형식

5%

Aspose 제품 업데이트 구독

월간 뉴스레터와 제안을 우편함으로 직접 받으십시오.

© Aspose Pty Ltd 2001-2024. 판권 소유.