JAVA용 IRONPDF 사용 Java를 사용하여 PDF 문서에서 표를 만드는 방법(튜토리얼) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF 메이븐 다운로드 JAR 다운로드 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 This article will demonstrate how to create tables inside a PDF document using Java. It is necessary to have a third-party library for creating tables in PDF documents using a Java program. There are multiple libraries available that can be used to create tables inside PDFs using a Java program. However, they can be expensive, challenging to use, or have performance issues. It can be tricky to find a library that is easy to use, free for development, and performs effectively. IronPDF is one library that's very useful for manipulating PDF files. You can find more information about IronPDF by clicking on the IronPDF Official Java Page. The following steps are covered in this article: Create a new project Install IronPDF Library Create a new PDF document Create a table for it Add dynamic values to the PDF document Create a New Java Project Open your preferred IDE. IntelliJ is recommended in this article, so the steps to create a new project may differ using another IDE. Open IntelliJ IDE, click on File > New Project from the top menu bar. Name your project, select the location, language, build system, and JDK as shown below. IntelliJ IDE New Project Window Click on the Create Project button, and a new project will be created. Install IronPDF Library Now, install the IronPDF library in the newly created project. Continue with the following steps. Open the pom.xml file and add the necessary dependencies and repositories to use IronPDF. The specific content for the pom.xml is not provided in this article, but make sure to properly include the IronPDF library using Maven's dependency management. <dependencies> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>VERSION_NUMBER</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>VERSION_NUMBER</version> </dependency> </dependencies> XML Type the following command into your terminal and press enter to install the specified Maven dependencies. mvn install mvn install SHELL This will install IronPDF in this project. Add the following import statement for using IronPDF classes. import com.ironsoftware.ironpdf.*; import com.ironsoftware.ironpdf.*; JAVA First of all, we will learn to create simple PDF documents in Java. Create a PDF document The following example code will create a new PDF document. public static void main(String[] args) throws IOException { // Create a PDF document from an HTML string PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("This is a sample PDF file"); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } public static void main(String[] args) throws IOException { // Create a PDF document from an HTML string PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("This is a sample PDF file"); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } JAVA The renderHtmlAsPdf method takes a string as an argument and converts that string into an instance of a PDF document. The saveAs function takes a file path as an argument and saves the newly created PDF document to the file path specified in the argument. A PDF is created from the above code, shown in the following image. New PDF Document Create table for the PDF file The following code will create a table in PDF. public static void main(String[] args) throws IOException { // HTML content for creating a table String tableContent = "<table>\n" + " <tr>\n" + " <th>Company</th>\n" + " <th>Contact</th>\n" + " <th>Country</th>\n" + " </tr>\n" + " <tr>\n" + " <td>Alfreds Futterkiste</td>\n" + " <td>Maria Anders</td>\n" + " <td>Germany</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Centro comercial Moctezuma</td>\n" + " <td>Francisco Chang</td>\n" + " <td>Mexico</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Ernst Handel</td>\n" + " <td>Roland Mendel</td>\n" + " <td>Austria</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Island Trading</td>\n" + " <td>Helen Bennett</td>\n" + " <td>UK</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Laughing Bacchus Winecellars</td>\n" + " <td>Yoshi Tannamuri</td>\n" + " <td>Canada</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Magazzini Alimentari Riuniti</td>\n" + " <td>Giovanni Rovelli</td>\n" + " <td>Italy</td>\n" + " </tr>\n" + "</table>"; // Create a PDF document with table content PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1>Example of adding table in a PDF</h1>" + tableContent); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } public static void main(String[] args) throws IOException { // HTML content for creating a table String tableContent = "<table>\n" + " <tr>\n" + " <th>Company</th>\n" + " <th>Contact</th>\n" + " <th>Country</th>\n" + " </tr>\n" + " <tr>\n" + " <td>Alfreds Futterkiste</td>\n" + " <td>Maria Anders</td>\n" + " <td>Germany</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Centro comercial Moctezuma</td>\n" + " <td>Francisco Chang</td>\n" + " <td>Mexico</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Ernst Handel</td>\n" + " <td>Roland Mendel</td>\n" + " <td>Austria</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Island Trading</td>\n" + " <td>Helen Bennett</td>\n" + " <td>UK</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Laughing Bacchus Winecellars</td>\n" + " <td>Yoshi Tannamuri</td>\n" + " <td>Canada</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Magazzini Alimentari Riuniti</td>\n" + " <td>Giovanni Rovelli</td>\n" + " <td>Italy</td>\n" + " </tr>\n" + "</table>"; // Create a PDF document with table content PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1>Example of adding table in a PDF</h1>" + tableContent); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } JAVA The above code uses simple HTML tags to create a table in PDF using Java. So, to create a table, you must have basic knowledge of using HTML tags. Almost every Java programmer has knowledge of HTML, so it is very easy to create a new table and table cells using HTML tags. The PDF file generated by this program is shown in the following image: PDF document containing a table from HTML It's a simple table with no styling. Now let's add some styling to this table, such as set table width, margin, layout, font, background color, and more. Add Styling to the Table The following sample code will format our table and add styling to our cells. public static void main(String[] args) throws IOException { // HTML and CSS content for styling the table String htmlStyle = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<style>\n" + "table {\n" + " font-family: arial, sans-serif;\n" + " border-collapse: collapse;\n" + " width: 100%;\n" + "}\n" + "\n" + "td, th {\n" + " border: 1px solid #dddddd;\n" + " text-align: left;\n" + " padding: 8px;\n" + "}\n" + "\n" + "tr:nth-child(even) {\n" + " background-color: #dddddd;\n" + "}\n" + "</style>\n" + "</head>\n" + "<body>"; String tableContent = "<table>\n" + " <tr>\n" + " <th>Company</th>\n" + " <th>Contact</th>\n" + " <th>Country</th>\n" + " </tr>\n" + " <tr>\n" + " <td>Alfreds Futterkiste</td>\n" + " <td>Maria Anders</td>\n" + " <td>Germany</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Centro comercial Moctezuma</td>\n" + " <td>Francisco Chang</td>\n" + " <td>Mexico</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Ernst Handel</td>\n" + " <td>Roland Mendel</td>\n" + " <td>Austria</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Island Trading</td>\n" + " <td>Helen Bennett</td>\n" + " <td>UK</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Laughing Bacchus Winecellars</td>\n" + " <td>Yoshi Tannamuri</td>\n" + " <td>Canada</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Magazzini Alimentari Riuniti</td>\n" + " <td>Giovanni Rovelli</td>\n" + " <td>Italy</td>\n" + " </tr>\n" + "</table>\n</body>\n" + "</html>"; // Create a PDF document with styled table content PdfDocument myPdf = PdfDocument.renderHtmlAsPdf(htmlStyle + "Sample PDF" + tableContent); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } public static void main(String[] args) throws IOException { // HTML and CSS content for styling the table String htmlStyle = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<style>\n" + "table {\n" + " font-family: arial, sans-serif;\n" + " border-collapse: collapse;\n" + " width: 100%;\n" + "}\n" + "\n" + "td, th {\n" + " border: 1px solid #dddddd;\n" + " text-align: left;\n" + " padding: 8px;\n" + "}\n" + "\n" + "tr:nth-child(even) {\n" + " background-color: #dddddd;\n" + "}\n" + "</style>\n" + "</head>\n" + "<body>"; String tableContent = "<table>\n" + " <tr>\n" + " <th>Company</th>\n" + " <th>Contact</th>\n" + " <th>Country</th>\n" + " </tr>\n" + " <tr>\n" + " <td>Alfreds Futterkiste</td>\n" + " <td>Maria Anders</td>\n" + " <td>Germany</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Centro comercial Moctezuma</td>\n" + " <td>Francisco Chang</td>\n" + " <td>Mexico</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Ernst Handel</td>\n" + " <td>Roland Mendel</td>\n" + " <td>Austria</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Island Trading</td>\n" + " <td>Helen Bennett</td>\n" + " <td>UK</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Laughing Bacchus Winecellars</td>\n" + " <td>Yoshi Tannamuri</td>\n" + " <td>Canada</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Magazzini Alimentari Riuniti</td>\n" + " <td>Giovanni Rovelli</td>\n" + " <td>Italy</td>\n" + " </tr>\n" + "</table>\n</body>\n" + "</html>"; // Create a PDF document with styled table content PdfDocument myPdf = PdfDocument.renderHtmlAsPdf(htmlStyle + "Sample PDF" + tableContent); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } } JAVA The added CSS is used for styling the table in the PDF. Hence, it is very efficient to use CSS for styling as needed. Following is the PDF generated by this program. PDF document containing a table from HTML and styled with CSS This above code looks very messy. But it can be cleaned by moving all the HTML content into an HTML file and then generating the PDF from that file. Create a table using an HTML file in PDF using Java Create a new HTML file and add all your HTML content to that file as shown below: HTML moved into its own HTML file Add the following code to the Java program. // Create a PDF document from an HTML file PdfDocument myPdf = PdfDocument.renderHtmlFileAsPdf("Create_Table.html"); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } // Create a PDF document from an HTML file PdfDocument myPdf = PdfDocument.renderHtmlFileAsPdf("Create_Table.html"); try { // Save the created PDF document to a file myPdf.saveAs(Paths.get("html_saved.pdf")); } catch (IOException e) { throw new RuntimeException(e); } JAVA We can see how easy it is to generate a PDF using an HTML document. If you need to create PDF files in Java, the easiest way is to create a separate HTML document with content and styling and then just convert your HTML document into PDF with a single line of code. Final PDF document with styling Summary This tutorial demonstrated how to create a styled table in a PDF file using Java and learned to convert HTML files into PDF files. IronPDF for Java also offers functionality to add images to the PDF file, split PDF files, add headers and footers, apply digital signatures, and much more. Explore IronPDF Documentation to learn more about these features and additional capabilities. Remove the IronPDF watermark from your generated PDF documents by purchasing a license key or by registering for a free trial. 자주 묻는 질문 PDF를 만들기 위한 새 Java 프로젝트를 시작하려면 어떻게 해야 하나요? PDF를 만들기 위한 새 Java 프로젝트를 시작하려면 IntelliJ와 같은 IDE를 사용할 수 있습니다. 먼저 프로젝트를 설정하고 Maven을 통해 IronPDF 라이브러리를 설치하여 PDF 생성 및 조작을 처리합니다. Java에서 HTML 콘텐츠를 PDF로 변환하려면 어떤 단계가 필요하나요? Java에서 HTML 콘텐츠를 PDF로 변환하려면 IronPDF의 PdfDocument.renderHtmlAsPdf 메서드를 사용할 수 있습니다. 여기에는 HTML 콘텐츠를 작성하고 선택적으로 CSS로 스타일을 지정한 다음 PDF로 렌더링하는 작업이 포함됩니다. Java로 생성된 PDF에서 CSS를 사용하여 표 스타일을 지정할 수 있나요? 예, IronPDF를 사용하여 PDF로 렌더링하기 전에 HTML 콘텐츠 내에 CSS를 포함시켜 PDF의 표 스타일을 지정할 수 있습니다. 이를 통해 글꼴, 테두리, 색상 등을 정의할 수 있습니다. Java를 사용하여 외부 HTML 파일에서 PDF를 만들려면 어떻게 해야 하나요? Java로 외부 HTML 파일에서 PDF를 만들려면 전체 HTML 파일을 PDF 문서로 변환하는 IronPDF의 PdfDocument.renderHtmlFileAsPdf 메서드를 사용할 수 있습니다. Java에서 PDF를 생성할 때 타사 라이브러리를 사용하면 어떤 이점이 있나요? IronPDF와 같은 타사 라이브러리를 사용하면 HTML에서 PDF로의 변환, 표 스타일링, 이미지 및 디지털 서명 지원과 같은 추가 기능을 제공하여 Java에서 PDF 생성 프로세스를 간소화할 수 있습니다. Java 라이브러리를 사용하여 PDF 문서에 이미지를 포함하려면 어떻게 해야 하나요? IronPDF를 사용하여 PDF로 렌더링하는 HTML 콘텐츠 내에 이미지를 삽입하여 PDF 문서에 이미지를 포함할 수 있습니다. 이 방법을 사용하면 시각적 요소를 매끄럽게 통합할 수 있습니다. Java에서 PDF를 분할하는 데 사용할 수 있는 옵션에는 어떤 것이 있나요? IronPDF는 PDF를 분할하는 옵션을 제공하여 하나의 PDF를 여러 문서로 나눌 수 있습니다. 이 기능은 대용량 문서를 관리하거나 특정 섹션을 추출할 때 특히 유용할 수 있습니다. Java를 사용하여 PDF에 디지털 서명을 적용하려면 어떻게 해야 하나요? 문서 보안과 신뢰성을 강화하기 위해 디지털 서명을 추가할 수 있는 IronPDF의 기본 제공 기능을 사용하여 PDF에 디지털 서명을 적용할 수 있습니다. PDF 문서에 워터마크가 있는 경우 어떻게 해야 하나요? IronPDF로 만든 PDF 문서에 워터마크가 있는 경우 라이선스 키를 구매하거나 무료 평가판 라이선스에 등록하여 워터마크를 제거할 수 있습니다. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 6월 22, 2025 Java에서 TIFF를 PDF로 변환하는 방법 이 포괄적인 가이드는 IronPDF를 사용하여 Java에서 TIFF 이미지를 PDF로 원활하게 변환하는 방법에 대한 단계를 안내합니다. 더 읽어보기 업데이트됨 7월 28, 2025 Java에서 PDF를 PDFA로 변환하는 방법 이 문서에서는 IronPDF를 사용하여 Java에서 PDF 파일을 PDF/A 형식으로 변환하는 방법을 살펴봅니다. 더 읽어보기 업데이트됨 7월 28, 2025 Java로 PDF 문서를 만드는 방법 이 문서에서는 주요 개념, 최고의 라이브러리 및 예제를 다루는 Java에서 PDF 작업에 대한 포괄적인 가이드를 제공합니다. 더 읽어보기 Java에서 PNG를 PDF로 변환하는 방법(튜토리얼)Java용 PDF 크리에이터(단계...
업데이트됨 6월 22, 2025 Java에서 TIFF를 PDF로 변환하는 방법 이 포괄적인 가이드는 IronPDF를 사용하여 Java에서 TIFF 이미지를 PDF로 원활하게 변환하는 방법에 대한 단계를 안내합니다. 더 읽어보기
업데이트됨 7월 28, 2025 Java에서 PDF를 PDFA로 변환하는 방법 이 문서에서는 IronPDF를 사용하여 Java에서 PDF 파일을 PDF/A 형식으로 변환하는 방법을 살펴봅니다. 더 읽어보기
업데이트됨 7월 28, 2025 Java로 PDF 문서를 만드는 방법 이 문서에서는 주요 개념, 최고의 라이브러리 및 예제를 다루는 Java에서 PDF 작업에 대한 포괄적인 가이드를 제공합니다. 더 읽어보기