Java 라이브러리를 사용하여 PDF 만들기

강력한 Java 라이브러리를 통해 개발자는 단 몇 단계로 프로그래밍 방식으로 PDF을(를) 만들 수 있습니다.

Java 개발자는 강력한 제품 API만 사용하여 PDF을 쉽게 만들 수 있습니다. 이는 우리 솔루션이 프로그래머에게 Java에서 PDF를 생성하는 데 필요한 모든 것을 제공한다는 것을 의미합니다.

코드 스니펫 보기

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

Java 라이브러리를 사용하여 개발자는 처음부터 PDF 를 쉽게 만들 수 있습니다. 이렇게 하려면 Java 개발자는 다음 몇 단계만 수행하면 됩니다.

  1. 파일 이름 추가
  2. Java 를 사용하여 PDF 문서 만들기 시작
  3. 출력 PDF 파일 저장

빈 문서는 기술적으로 하나의 단락을 포함해야 하므로 프로그래밍 방식으로 PDF 문서를 만들 때 기본 문서 구조를 정확히 얻을 수 있습니다.

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

Java 로 PDF 만들기

이 Java 라이브러리를 사용하면 PDF 문서를 프로그래밍 방식으로 만들 수 있습니다. 강력한 기능을 사용해 보고 다음 예제를 사용하여 일부 형식으로 PDF 를 만드는 방법을 확인하십시오.

Java를 사용하여 새 PDF 만들기
목록에서 대상 형식 선택
코드 실행
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.pdf");
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.pdf"); 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.pdf", 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.pdf");
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.pdf"); 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.pdf", 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");

PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);

doc.save("Output.pdf", 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.pdf"); 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.pdf", 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.pdf");
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.pdf"); 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.pdf", saveOptions);
코드 실행

Java에서 PDF 만드는 방법

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

PDF 생성을 위한 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. 판권 소유.