Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Mar 04, 2025 8:00 am

是否有详细的教程?
Code: Select all
ChromeHtmlConverter converter = new ChromeHtmlConverter(TestUtil.ChromiumPath);
URI uri = new URI(converter.getUrl());
IWebSocketService webSocketService = (IWebSocketService) WebSocketServiceImpl.create(uri);
converter.setWebSocketService(webSocketService);
ConvertOptions options = new ConvertOptions();
options.setTimeout(10 * 1000);
PageSettings pageSettings = new PageSettings();
pageSettings.setPaperFormat(8);//A4
pageSettings.setMarginBottom(0);
pageSettings.setMarginTop(0);
pageSettings.setMarginLeft(0);
pageSettings.setMarginRight(0);
options.setPageSettings(pageSettings);
converter.convertToPdf(inputPath, OutputPath, options);

我看到官方示例是这样,但是其中的TestUtil.ChromiumPath和WebSocketServiceImpl是什么?
使用的产品是spire.pdf for java。
再请问Windows和Linux上面是否有不同?

zhj132171
 
Posts: 9
Joined: Fri Aug 02, 2024 11:33 pm

Tue Mar 04, 2025 9:04 am

您好,

感谢您的咨询。
TestUtil.ChromiumPath和WebSocketServiceImpl参数分别指的是Chrome浏览器的执行程序的路径和WebSocket的实现类。我上传了一个完整的maven项目,其中有关于WebSocketServiceImpl的实现方式,您可以直接运行此项目。此方式转换html到pdf文件需要保证系统上已安装Chrome浏览器,linux和windows一致,如果均采用默认安装方式,TestUtil.ChromiumPath参数可以不用传递值。如果您还有任何疑问,请随时来信。

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron