Mac电脑上指定字库报异常

我用的是mac电脑, 一下是我的程序

   FontSettings.addFontsFolder("/System/Library/Fonts");
    Document pdfDocument = new Document("/Volumes/下载/386.pdf");
	// Loop through all the pages of PDF file
	for (int pageCount = 1; pageCount <= 4; pageCount++) {
		// Create stream object to save the output image
		java.io.OutputStream imageStream = new java.io.FileOutputStream("/Volumes/下载/Converted_Image" + pageCount + ".jpg");
		// Create Resolution object
		Resolution resolution = new Resolution(300);
		// Create JpegDevice object where second argument indicates the quality of resultant image
		JpegDevice jpegDevice = new JpegDevice(resolution, 100);
		// Convert a particular page and save the image to stream
		jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
		// Close the stream
		imageStream.close();
	}

以下是报的异常

2021-07-08 15:19:48.520 [http-nio-9010-exec-1] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is class com.aspose.pdf.internal.imaging.coreexceptions.FrameworkException: missing head table —> java.awt.FontFormatException: missing head table
— End of inner exception stack trace —
com.aspose.pdf.internal.imaging.FontSettings.addFontsFolder(Unknown Source)
com.bill.controller.PageController.p2iAsp(PageController.java:145)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:564)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:142)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)

请问 在mac的字库不能识别,只能用windows字库吗?

@mxudong

您能否分享示例 PDF 文件以供我们参考,以便我们可以在我们的环境中测试该场景并相应地解决它?

其实和文档无关, 只要是中文文档就会有这个问题, 当然给你们pdf没问题. 关键是 windows上能跑, mac上跑不了386.pdf (1.3 MB)

@mxudong

我在 MAC OS 上复制了异常,并在我们的问题跟踪系统中创建了 ID PDFJAVA-40683 的票证,以进一步调查和解决问题。 此线程已与问题相关联,以便在问题解决后您可能会收到通知。

@mxudong

FontSettings 是一个内部类。您不能使用内部类。在 Aspose.Pdf for Java 的 22.2 版中,此类访问不可用。
此外,要使用字体设置某些文件夹,您必须使用下一个代码片段:

com.aspose.pdf.FontRepository.addLocalFontPath("/System/Library/Fonts");

在 22.2 版本的 Aspose.Pdf for Java (MacOS Big Sur 11.5.2) 下一段代码完全成功:

 public static void TestPDFtoImage() throws IOException
    {
        String path="//Users//mudassirkhan//Downloads//";
           com.aspose.pdf.FontRepository.addFontsFolder("/System/Library/Fonts");
            Document pdfDocument = new Document(path+"386.pdf");
            // Loop through all the pages of PDF file
            for (int pageCount = 1; pageCount <= 4; pageCount++) {
                // Create stream object to save the output image
                java.io.OutputStream imageStream = new java.io.FileOutputStream(path+"/Converted_Image" + pageCount + ".jpg");
                // Create Resolution object
                Resolution resolution = new Resolution(300);
                // Create JpegDevice object where second argument indicates the quality of resultant image
                JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                // Convert a particular page and save the image to stream
                jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
                // Close the stream
                imageStream.close();
            }
    }