import com.ironsoftware.ironpdf.*;
import com.ironsoftware.ironpdf.render.*;
import java.io.IOException;
import java.nio.file.Paths;
// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");
// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));
// Create a new ChromePdfRenderOptions object
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
// Set custom options for the generated PDF document (paper size, title, etc.)
renderOptions.setCustomPaperSizeInCentimeters(31.75, 50.80 );
renderOptions.setPrintHtmlBackgrounds(true);
renderOptions.setPaperOrientation(PaperOrientation.LANDSCAPE);
renderOptions.setTitle("My PDF Document Name");
renderOptions.setEnableJavaScript(true);
renderOptions.setWaitFor(new WaitFor(50)); // time in milliseconds
renderOptions.setCssMediaType(CssMediaType.SCREEN);
renderOptions.UseScaledRendering(100); // 100 is zoom percentage
renderOptions.setCreatePdfFormsFromHtml(true);
// Customize PDF Margins by specifying sizes in millimeters
renderOptions.setMarginTop(40);
renderOptions.setMarginBottom(40);
renderOptions.setMarginLeft(20);
renderOptions.setMarginRight(20);
// Render the HTML document as a PDF using the specified rendering options.
try {
PdfDocument pdf = PdfDocument.renderHtmlFileAsPdf("wikipedia.html", renderOptions);
pdf.saveAs(Paths.get("assets/wikipedia.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
HTML을 PDF로 변환하기 위한 렌더링 설정
이 코드 예제는 IronPDF HTML 콘텐츠를 PDF 문서로 변환하는 데 있어 개발자에게 제공하는 강력하고 유연한 기능을 보여줍니다.
ChromePdfRenderOptions는 개발자가 웹 페이지를 PDF로 변환하는 방식을 완벽하게 제어할 수 있도록 보장합니다.
ChromePdfRenderOptions 클래스를 사용하면 개발자는 페이지 여백을 사용자 지정하고, 페이지 방향을 지정하고, 주석을 추가하고, 책갈피를 포함하고, 문서 메타데이터를 변경하며, 확대/축소 비율을 조정하고, CSS 규칙 세트를 수정하는 등 다양한 작업을 수행할 수 있습니다. 정의된 후, 이 클래스의 객체는 IronPDF가 웹사이트 콘텐츠를 해석하는 방법과 이러한 메서드 실행 중 PDF 콘텐츠를 렌더링하는 방법을 변경하기 위해 정적 PDF 문서 렌더링 메서드(renderHtmlAsPdf, renderHtmlFileAsPdf, 및 renderUrlAsPdf) 중 하나에 두 번째(선택적) 매개변수로 제공될 수 있습니다.