Save to stream

On this page

You might need to save a document to any custom file at any location on the local disc or a even a Stream.

The following example demonstrates how to save a document to any location.

const redaction = require('@groupdocs/groupdocs.redaction');
const java = require('java');
const Color = java.import('java.awt.Color');
const FileOutputStream = java.import('java.io.FileOutputStream');

const redactor = new redaction.Redactor('Sample.docx');
try {
  const result = redactor.apply(new redaction.ExactPhraseRedaction(
    'John Doe',
    new redaction.ReplacementOptions(Color.RED)));
  if (result.getStatus() !== redaction.RedactionStatus.Failed) {
    const fileStream = new FileOutputStream('C:\\Temp\\sample_output_file.pdf');
    try {
      const options = new redaction.RasterizationOptions();
      options.setEnabled(true);
      redactor.save(fileStream, options);
    } finally {
      fileStream.close();
    }
  }
} finally {
  redactor.close();
}

On this page