convertToPdfStandard method

Future<bool> convertToPdfStandard(
  1. String outputPath,
  2. CPDFPdfStandardType type, {
  3. bool fontSubset = true,
})

Converts the document to type and writes the result to outputPath.

The result is written to outputPath as a new file; the source file and the opened document end up unchanged. Unsaved changes held by the opened document, such as annotations or pending content edits in an attached reader, are included in the output.

On Android the conversion runs on the opened document, which is then reloaded from its original source. On iOS a copy is converted and the opened document is never touched.

  • outputPath may be a file path or, on Android only, a content Uri from ComPDFKit.createUri. A file path must be writable, its parent directory must already exist, and it must differ from the current document path. An existing file at outputPath is overwritten.
  • An encrypted document must be saved without its password first, via saveAs, otherwise a CPDFPdfStandardException with code ENCRYPTED_DOCUMENT_NOT_CONVERTIBLE is thrown.
  • fontSubset controls whether font subsets are written into the output file. It is the only setting the native entry point accepts: the ICC output intent is supplied by the SDK itself, and no PDF/UA language or title can be passed in.
  • iOS cannot convert to CPDFPdfStandardType.pdfE2 or CPDFPdfStandardType.pdf and throws a CPDFPdfStandardException with code UNSUPPORTED_PDF_STANDARD.

Since v3.2.0

example:

await controller.document.convertToPdfStandard(
  '/path/to/contract-pdfa2b.pdf',
  CPDFPdfStandardType.pdfA2b,
);

Implementation

Future<bool> convertToPdfStandard(
  String outputPath,
  CPDFPdfStandardType type, {
  bool fontSubset = true,
}) async {
  if (outputPath.trim().isEmpty) {
    throw const CPDFPdfStandardException(
      'INVALID_OUTPUT_PATH',
      'outputPath must not be empty.',
    );
  }
  try {
    final result = await _channel.invokeMethod('convert_to_pdf_standard', {
      'output_path': outputPath,
      'type': type.value,
      'font_subset': fontSubset,
    });
    return result == true;
  } on PlatformException catch (e) {
    throw CPDFPdfStandardException(e.code, e.message ?? '');
  }
}