# PDFix SDK Package

## PDFix SDK - High Performace PDF library

`keywords: pdf, accessibility, remediation, extraction, html, conversion, render, watermark, redact, sign, forms`

PDFix SDK analyses the key components of the PDF and makes it easily available for you to manipulate. It’s a high-performance library that helps software developers and end-users integrate PDF functionality into their workflows.

## Features
- Automated PDF Tagging and Remediation (PDF/UA)
- Automated Data Extraction (JSON, XML)
- PDF to HTML Conversion (Original, Responsive, by Tags)
- Standard PDF Editing Features (render, watermark, redact, sign, forms, and more)

## Change log
[https://pdfix.net/support/changelog/](https://pdfix.net/support/changelog/)

## Supported platforms
- Linux amd64
- Windows amd64
- macOS amd64, arm64

# Taking Advantages of WebAssembly
Leverage the advantages of the PDFix SDK WebAssembly build for use in both Node.js and web applications. This allows to execute code at near-native speeds. Reduce the need for server-side processing and improve your web app responsiveness.

# Getting Started

Using this package, you can get started either in Node.js or in browser - web environment.

To install the package, run this command:

`npm i pdfix-sdk`

## For use in Node.js

```javascript
const Pdfix = require('pdfix-sdk');

const pdfixSdkWrapper = new Pdfix();
pdfixSdkWrapper.loadPdfixSdk().then(() => {
  const pdfixSdk = pdfixSdkWrapper.getPdfixSdk();
  const pdfix = pdfixSdk.GetPdfix();
  const pdfDoc = pdfixSdkWrapper.openDocumentFromPath("<YOUR_DOCUMENT_PATH>");

  // your code ...

  pdfDoc.Close();
  pdfix.Destroy();
});
```

## For use in Web (browser)

Run this command in the location of installed NPM package to get the package for web:

`npm run get-web-package --path=<OPTIONAL_PATH>`

- If the `--path` option is set, it will put the files for web there.
- You will find those files in `./dist` folder instead.

Use the PDFix SDK accordingly:

```typescript
// replace with your import path
import { Pdfix as PdfixSdkWrapper, PdfixSdk } from './assets/pdfix/index';
import { Pdfix, PdfDoc } from 'PDFIX_WASM';

const pdfixSdkWrapper: PdfixSdkWrapper = new PdfixSdkWrapper();
// provide your "helper" path ('/assets/pdfix/') if your
// web app cannot find wasm binary
pdfixSdkWrapper.loadPdfixSdk('/assets/pdfix/').then(() => {
  const pdfixSdk: PdfixSdk = pdfixSdkWrapper.getPdfixSdk();
  const pdfix: Pdfix = pdfixSdk.GetPdfix();
  const pdfDoc: Promise<PdfDoc> = pdfixSdkWrapper.openDocumentFromUrl('<YOUR_DOCUMENT_URL>');

  // your code ...

  pdfix.Destroy();
});
```

# TypeScript Declaration File & Documentation

The package comes with a TypeScript Declaration File (d.ts) for the pdfix_wasm module. Thus it is recommended to get started with a TypeScript based project. To get more details about any of the functions in the SDK, check in our [Documentation](http://pdfix.net/docs)

# Powerful Solutions

We want to show the world that it is possible to take advantage of all the amazing features that PDF has available without the headache of having to understand them yourself.

## Make PDF Accessible

Make your PDFs PDF/UA compliant in ease.

```typescript
const pdfDoc: PdfDoc = pdfix.openDocumentFromPath('<YOUR_DOCUMENT_PATH>');
const pdfAccessibleParams: PdfAccessibleParams = new pdfixSdk.PdfAccessibleParams();
pdfDoc.MakeAccessible(
  pdfAccessibleParams,
  "Document Title",
  "en-US",
  0,
  0
);
pdfDoc.Close();
```

## Add Tags to PDF

Improve Accessibility in Existing PDF Files.

```typescript
const pdfDoc: PdfDoc = pdfix.openDocumentFromPath('<YOUR_DOCUMENT_PATH>');
const pdfTagsParams: PdfTagsParams = new pdfixSdk.PdfTagsParams();
pdfDoc.AddTags(pdfTagsParams, 0, 0);
pdfDoc.Close();
```

## PDF to HTML, PDF to Responsive HTML

Easily convert any PDF into HTML.

```typescript
function streamToString(sdk: PdfixSdk, stream: PsStream): string {
  const ptr: number = sdk._malloc(stream.GetSize());
  stream.Read(0, ptr as any, stream.GetSize());
  let string: string = '';
  for (let i = 0; i < stream.GetSize(); i++) {
    string += String.fromCharCode((sdk as any).HEAP8[ptr + i])
  }
  return string;
}

const pdfDoc: PdfDoc = pdfix.openDocumentFromPath('<YOUR_DOCUMENT_PATH>');
const pdfToHtmlConversion: PdfHtmlConversion = pdfDoc.CreateHtmlConversion();
let pdfHtmlParams: PdfHtmlParams = new pdfixSdk.PdfHtmlParams();
pdfHtmlParams.flags |= (
  PdfixEnum.kHtmlNoExternalCSS |
  PdfixEnum.kHtmlNoExternalJS |
  PdfixEnum.kHtmlNoExternalIMG |
  PdfixEnum.kHtmlNoExternalFONT
);
pdfHtmlParams.type = PdfHtmlType.kPdfHtmlResponsive;
pdfToHtmlConversion.SetParams(pdfHtmlParams);
pdfToHtmlConversion.AddPage(1, 0, 0);
const stream: PsStream = pdfixSdk.GetPdfix().CreateMemStream();
pdfToHtmlConversion.SaveToStream(stream, 0, 0);
const htmlString = streamToString(pdfixSdk, stream);
stream.Destroy();
pdfToHtmlConversion.Destroy();

console.log(htmlString);
pdfDoc.Close();
```

# Have a question? Need help?
Let us know and we’ll get back to you. Write us to support@pdfix.net or fill the
[contact form](https://pdfix.net/support/).