首先提供原稿的word文件和使用aspose.words转换的pdf文件:
word文件是原稿,pdf是使用aspose.words转换来的
files.zip (45.0 KB)
主要问题如下:
1、原稿word的文档样式,下划线都是正常的
2、使用aspose转换后的pdf样式,可以看到下划线空白地方被自动去除了
这个是aspose本身原因还是有参数需要调整?
我使用的代码片段:
public static void ConvertWord2Pdf(
string documentFileName,
string SavePdfName,
string tempSaveDocxPath,
Aspose.Words.Saving.PdfCompliance PdfComplanceOption,
Aspose.Words.Settings.MsWordVersion OptiMizMswVersion,
bool UpdateField,
Aspose.Words.Saving.ColorMode SavePdfColorMode,
bool EmbedFonts,
string DocumentPassword,
bool UseLocalOffice)
{
string DocumentName, SaveDocxName;
if (!UseLocalOffice)
{
//设置加载word文档的时候参数
Aspose.Words.Loading.LoadOptions TempDocuemntLoadOption = new Aspose.Words.Loading.LoadOptions()
{
ConvertMetafilesToPng = false,
MswVersion = OptiMizMswVersion,
Password = DocumentPassword,
};
TempDocuemntLoadOption.LanguagePreferences
.AddEditingLanguage(Aspose.Words.Loading.EditingLanguage.ChinesePRC);
AspWordsWarningCallBack AspCallBack = new AspWordsWarningCallBack();
Aspose.Words.Fonts.FontSettings TempFontSettings = new Aspose.Words.Fonts.FontSettings();
TempFontSettings.SubstitutionSettings.DefaultFontSubstitution.Enabled = true;
TempFontSettings.SubstitutionSettings.TableSubstitution.Enabled = false;
TempFontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = false;
TempFontSettings.SubstitutionSettings.FontConfigSubstitution.Enabled = false;
TempFontSettings.SubstitutionSettings.FontNameSubstitution.Enabled = false;
TempFontSettings.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "SimSun";
TempDocuemntLoadOption.FontSettings = TempFontSettings;
//设置PDF保存参数
Aspose.Words.Saving.PdfSaveOptions TempPdfaveOption = new Aspose.Words.Saving.PdfSaveOptions()
{
AllowEmbeddingPostScriptFonts = true,
EmbedFullFonts = EmbedFonts,
FontEmbeddingMode = Aspose.Words.Saving.PdfFontEmbeddingMode.EmbedAll,
ColorMode = SavePdfColorMode,
ImageColorSpaceExportMode = Aspose.Words.Saving.PdfImageColorSpaceExportMode.Auto,
ImageCompression = Aspose.Words.Saving.PdfImageCompression.Auto,
PageMode = Aspose.Words.Saving.PdfPageMode.UseOutlines,
ZoomBehavior = Aspose.Words.Saving.PdfZoomBehavior.None,
SaveFormat = Aspose.Words.SaveFormat.Pdf,
UseHighQualityRendering = true,
UseAntiAliasing = true,
PreblendImages = true,
JpegQuality = 100,
Compliance = PdfComplanceOption,
ExportGeneratorName = false,
UpdateFields = UpdateField,
};
//设置PDF保存带word中的目录
TempPdfaveOption.OutlineOptions.DefaultBookmarksOutlineLevel = 0;
TempPdfaveOption.OutlineOptions.CreateMissingOutlineLevels = false;
TempPdfaveOption.OutlineOptions.ExpandedOutlineLevels = 3;
TempPdfaveOption.OutlineOptions.HeadingsOutlineLevels = 9;
TempPdfaveOption.HeaderFooterBookmarksExportMode = Aspose.Words.Saving.HeaderFooterBookmarksExportMode.All;
//设置Docx保存参数
Aspose.Words.Saving.OoxmlSaveOptions TempDocxSaveOption = new Aspose.Words.Saving.OoxmlSaveOptions()
{
Compliance = Aspose.Words.Saving.OoxmlCompliance.Iso29500_2008_Transitional,
SaveFormat = Aspose.Words.SaveFormat.Docx,
KeepLegacyControlChars = true,
UpdateFields = UpdateField,
};
Aspose.Words.Document TempDocument = new Aspose.Words.Document(documentFileName, TempDocuemntLoadOption)
{
RemovePersonalInformation = true,
};
TempDocument.CompatibilityOptions.OptimizeFor(OptiMizMswVersion);
TempDocument.CompatibilityOptions.BalanceSingleByteDoubleByteWidth = true;//区分全角和半角字符
DocumentName = System.IO.Path.GetFileNameWithoutExtension(documentFileName);
SaveDocxName = System.IO.Path.Combine(tempSaveDocxPath, $"{DocumentName}.docx");
TempDocument.Save(SaveDocxName, TempDocxSaveOption);
Aspose.Words.Document TempDocxDocument = new Aspose.Words.Document(SaveDocxName, TempDocuemntLoadOption);
TempDocxDocument.WarningCallback = AspCallBack;
//TempDocxDocument.FontSettings = TempFontSettings;
//TempDocxDocument.LayoutOptions.KeepOriginalFontMetrics = true;
TempDocxDocument.Save(SavePdfName, TempPdfaveOption);