Aspose.pdf v19.12 水印在linux net core环境里不支持中文

英文水印没有什么问题,只要是中文都会出错

my code
textStamp = new TextStamp(“你好 aspose.pdf”);
Document document = new Document(“test.pdf”);
document.Pages[1].AddStamp(textStamp);

出现的异常是

System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.Font…ctor(#=z$suuRT1fkyC6o7sLZOgoVCo= #=zrItU44g=)
at #=z7bI4GhXHbP5a$tKtZ8fm06BHoRC_OkCVFa6LJsOBCZxTOHyiI6BH0LE=.#=znXZO1csT5yQ2yNa9pEqJE_znjCyF(String #=z1bLSgdQ=, Font #=zrItU44g=, Font& #=zSrZU8_e94X$Wu1iac49Oz2U=)
at Aspose.Pdf.Text.TextSegment.set_Text(String value)
at Aspose.Pdf.Text.TextFragment.set_Text(String value)
at Aspose.Pdf.TextStamp.Put(Page page)
at Aspose.Pdf.Page.AddStamp(Stamp stamp)
at convertapi.Controllers.IndexController.Post(Args args) in G:\dotnet\convertapi\Controllers\IndexController.cs:line 227
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

@bama,

Can you please share source file so that we may further investigate to help you out.

我的代码很简单,就上面这一句,在windows环境测试正常,在linux环境中出现异常

@bama,

您能否分享您正在使用的源PDF文件。

我确定不是pdf的问题,而是aspose.pdf.dll 的问题,在windows环境里正常,而在linux环境里会出错

new_test.pdf (67.8 KB)

@bama

请您确保在Linux环境中执行以下操作:

  • 如果已安装libgdiplus软件包
  • 如果已安装所有MS Core字体

如果您同时满足这两个要求,请告诉我们。我们将进一步为您提供帮助。

我已经安装了libgdiplus软件包,
windows7下的所有字体都已复制到了linux
您说的MS Core字体 指的是?不太理解

@bama

您可以在Linux中使用以下命令安装这些字体:

sudo apt install ttf-mscorefonts-installer

或者,您可以根据您的操作系统运行兼容命令。此外,您还可以在运行代码段之前设置字体路径,如下所示:

String path = "path/to/my/folder";
List<String> fontPaths = com.aspose.pdf.Document.getLocalFontPaths();
fontPaths.add(path);
com.aspose.pdf.Document.setLocalFontPaths(fontPaths);

如果仍然遇到任何问题,请与我们分享您的操作系统名称和版本。我们将进一步为您提供帮助。

好的,我试一下,非常感谢