// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java // The path to the documents directory. String dataDir = Utils.getDataDir(); String fontDir = dataDir + "necessary_fonts/"; // Open an XPS Document final XpsDocument doc = new XpsDocument(dataDir + "Sample3.xps"); try { // Create a font final InputStream fontStream = new FileInputStream(fontDir + "arialbd.ttf"); try { // Create options for conversion to PDF PdfSaveOptions options = new PdfSaveOptions(); // Set the filter for the pages that need conversion options.setPageNumbers(new int[] { 2, 6, 7, 13 }); // Add the event handler that will execute right before the conversion of each page options.getBeforePageSavingEventHandlers().add(new NavigationInjector(doc.createFont(fontStream), options.getPageNumbers())); // Save resultant XPS document doc.saveAsPdf(dataDir + "ModifyPageOnConversion_out.pdf", options); } finally { if (fontStream != null) fontStream.close(); } } finally { if (doc != null) doc.close(); }