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.

Wed Jul 12, 2023 6:55 am

Hi! I'm working on macBook 2018 with OS Ventura 13.4.
I get NPE
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.indexOf(String)" because "com.spire.pdf.graphics.PdfFontBase.spr▌–().spr”" is null
, but it's working on WIN PC.
I'm uploading .xps file and my converter code:
Code: Select all
public class Converter {
    public static String convert(String inputDirectoryPath) {
        File inputDirectory = new File(inputDirectoryPath);
        if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
            throw new IllegalArgumentException("The specified input directory does not exist or is not a directory");
        }
        File[] xpsFiles = inputDirectory.listFiles((dir, name) -> name.toLowerCase().endsWith(".xps"));
        if (xpsFiles == null) {
            throw new IllegalArgumentException("The specified input directory does not exist or is not a directory");
        }
        if (xpsFiles.length == 0) {
            throw new IllegalArgumentException("The specified input directory does not contain any XPS files");
        }
        String outputDirectoryPath = "%s/output-%s/".formatted(inputDirectory.getAbsolutePath(), getFormattedDate());
        new File(outputDirectoryPath).mkdir();
        System.out.println("Converting XPS files from folder " + inputDirectoryPath + " to PDF files to folder " + outputDirectoryPath);
        Arrays.stream(xpsFiles).forEach(xpsFile -> convertXpsToPdf(outputDirectoryPath, xpsFile));
        System.out.println("Done converting XPS files to PDF files");
        return outputDirectoryPath;
    }

    private static void convertXpsToPdf(String outputDirectoryPath, File xpsFile) {
        String absolutePath = xpsFile.getAbsolutePath();
        String destinationFilePath = outputDirectoryPath + getFileName(absolutePath) + ".pdf";
        System.out.println("Converting file '" + absolutePath + "' to PDF...");
        PdfDocument pdfDocument = new PdfDocument();
        pdfDocument.loadFromXPS(absolutePath);
        pdfDocument.saveToFile(destinationFilePath, PDF);
        pdfDocument.close();
    }

    private static String getFileName(String sourceFilePath) {
        return new File(sourceFilePath).getName().replaceFirst("[.][^.]+$", "");
    }


    private static String getFormattedDate() {
        return new SimpleDateFormat("dd-MM-yyyy").format(new Date());
    }
}

kotamadeo
 
Posts: 1
Joined: Wed Jul 12, 2023 6:48 am

Wed Jul 12, 2023 10:16 am

Hello,

Thank you for your inquiry.
I tested your Word file and did reproduce the issue you mentioned. I have logged the issue into our bug tracking system with the ticket number SPIREPDF-6156. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely,
Wenly
E-iceblue support team
User avatar

Wenly.Zhang
 
Posts: 149
Joined: Tue May 16, 2023 2:19 am

Return to Spire.PDF