我试图在浏览器中将 Word 文档的第一页显示为缩略图,为此我将 docx 转换为 pdf。然而,这需要一些时间,因为它正在转换整个文档,因此我试图通过仅转换将在浏览器上显示的第一页来加快速度。这是否可能而不是转换 docx 文件的每一页?
‘’’
public static void ConvertToPDF(string PathToItemToConvert, string PathToLibrePortable)
{
bool converted = false;
try
{
string fileName = Path.GetFileName(PathToItemToConvert);
string fileDir = Path.GetDirectoryName(PathToItemToConvert);
var pdfProcess = new Process();
pdfProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pdfProcess.StartInfo.FileName = PathToLibrePortable;
pdfProcess.StartInfo.Arguments =
String.Format("--norestore --nofirststartwizard --headless --convert-to pdf \"{0}\""
, fileName);
pdfProcess.StartInfo.WorkingDirectory = fileDir;
pdfProcess.StartInfo.RedirectStandardOutput = true;
pdfProcess.StartInfo.RedirectStandardError = true;
pdfProcess.StartInfo.UseShellExecute = false;
pdfProcess.Start();
string output = pdfProcess.StandardOutput.ReadToEnd();
converted = true;
}
catch (Exception ex)
{
converted = false;
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
或者我应该使用 libreoffice 将 docx 转换为 html,而我的整个方法是有缺陷的,因为我不需要保存的 pdf 副本,因为这些 docx 文件经常更改。
这在命令行中对我有用:
libreoffice --headless --convert-to 'pdf:writer_pdf_Export:{"PageRange":{"type":"string","value":"1"}}' ./FileToConvert.docx
我正在使用 LibreOffice 24.2.5.2 420(内部版本:2)。