Skip to content
DemoAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
React Native Guides Pdf standard conversion

PDF Standard Detection and Conversion ​

Before conversion, finish loading the document and prepare a writable output path different from the source. Its parent directory must exist.

Read and Convert ​

ts
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';

async function convertStandard(reader: CPDFReaderView, outputPath: string) {
  const document = reader._pdfDocument;
  const currentType = await document.getPdfStandardType();
  if (!await reader.save()) throw new Error('Failed to save the document');
  const success = await document.convertToPdfStandard(
    outputPath, 'pdf_a_2b', true,
  );
  if (!success) throw new Error('PDF standard conversion failed');
  return { currentType, outputPath };
}

getPdfStandardType() reads the document's declared standard; it does not perform a full conformance check. convertToPdfStandard(outputPath, type, fontSubset) returns boolean. fontSubset defaults to true and controls font subsetting when saving.

Conversion Targets ​

Standardtype
PDF/A-1pdf_a_1a, pdf_a_1b
PDF/A-2pdf_a_2a, pdf_a_2u, pdf_a_2b
PDF/A-3pdf_a_3a, pdf_a_3u, pdf_a_3b
PDF/Xpdf_x_1a, pdf_x_3, pdf_x_4
PDF/Epdf_e_1
PDF/UApdf_ua_1
PDF/VTpdf_vt_1, pdf_vt_2

Saving and Result Handling ​

  • Save pending edits first. Android converts from the saved source file, so unsaved edits are excluded. iOS uses an in-memory copy of the current document.
  • Before converting an encrypted file, use saveAs(path, true, true) to output an unencrypted copy, then open that copy for conversion. Obtain the necessary document permissions first.
  • The output path must differ from the source. Android also supports target content:// URIs with write access.
  • Conversion does not open the output automatically. On success, call document.open(outputPath) if needed, then read the type or inspect the output.
  • Invalid parameters, encryption state, or save failures may return false or reject the Promise. Use the output only after confirming success.