Skip to main content
Version: 9.0

wsclient for TypeScript

The webPDF wsclient library for TypeScript provides a simplified and optimized API for implementing a client to use the webPDF server.

It strictly complies to the "Generalized Usage Pattern".

LanguageTypeScript
RepositoryGitHub
ProtocolsREST

Download​

The wsclient library can be downloaded from npmjs, by adding the dependency to your project:

yarn add @softvision/webpdf-wsclient-typescript
npm install @softvision/webpdf-wsclient-typescript

Usage​

Using the wsclient a request to the webPDF Converter webservice could be as simple as:

// Initialize the session context:
let sessionContext: SessionContext = new SessionContext(WebServiceProtocol.REST, new URL("http://localhost:8080/webPDF/"));
// (Advanced options such as the configuration of a client truststore, a TLS-context and client side proxies are available.)

// Select an AuthProvider for the session:
let authProvider: AuthProvider = new AnonymousAuthProvider();

try {
// Establish a session with the webPDF server:
let session: RestSession<RestDocument> = await SessionFactory.createInstance(sessionContext, authProvider);

// Use the document manager to upload/download/delete/rename and access the history of documents in your session:
let restDocument: RestDocument = await session.getDocumentManager().uploadDocument(sourceDocument, "filename");

// Select the webservice you want to call:
let webService: ConverterRestWebService<RestDocument> = session.createWebServiceInstance(WebServiceType.CONVERTER);

// Parameterize the webservice call. (Using predefined objects, that preselect and suggest which values may be set where):
webService.setOperationParameters(
Converter.fromJson({
pages: "1-4",
embedFonts: true
} as ConverterInterface)
);

// Execute the webservice call and receive a reference to the result document:
let resultDocument: RestDocument | undefined = await webService.process(restDocument);

// Download the result document to your local file system:
let downloadedFile: Buffer = await resultDocument!.downloadDocument();

// Handle the downloaded file...
} catch (ex: any) {
let resultException: ResultException = ex;

// Handle server fail states using actual Exceptions, without having to parse the server´s responses yourself:
let msg: string = resultException.getMessage();
let error: WsclientError = resultException.getClientError();
let errorCode: number = resultException.getErrorCode();
let cause: Error | undefined = resultException.getCause();
}

Documentation and examples​

You can find further documentation and usage examples in the project´s GitHub wiki.