Show / Hide Table of Contents

Class CreatePDFOperation

An Operation that converts a non-PDF file to a PDF file. Some source formats may have associated conversion parameters which can be set in the SetOptions(CreatePDFOptions) method.

The supported source media types are listed here. The CreatePDFOperation.SupportedSourceFormat class can be used to map file extensions to their corresponding media types when creating FileRef instances for the source files.

  • image/bmp
  • application/msword
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • image/gif
  • text/html (see "Special handling for HTML inputs" below)
  • image/jpeg
  • image/png
  • application/vnd.ms-powerpoint
  • application/vnd.openxmlformats-officedocument.presentationml.presentation
  • text/rtf
  • image/tiff
  • text/plain
  • application/vnd.ms-excel
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • application/zip (see "Special handling for HTML inputs" below)

Special handling for HTML inputs:

An HTML input can be provided either as a public hosted web page URL or a local zip archive.

When creating the corresponding FileRef instance, the media type must be "text/html" for the URL and "application/zip" for the local zip archive. Zip archives must have the following structure:
  • The main HTML file must be named "index.html".
  • "index.html" must exist at the top level of zip archive, not in a folder.

Sample Layout:
html_files.zip
|__index.html
|__referenced_file_1.css
|__referenced_file_2.jpeg
|__subfolder_1
|_____referenced_file_3.jpeg
Inheritance
System.Object
CreatePDFOperation
Implements
IOperation
Namespace: Adobe.DocumentCloud.Services.pdfops
Assembly: Adobe.DocumentCloud.Services.Doc.dll
Syntax
public class CreatePDFOperation : IOperation
Examples

Sample Usage:

ClientContext context = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew();
createPdfOperation.SetInput(FileRef.CreateFromLocalFile("createPdfInput.docx", CreatePDFOperation.SupportedSourceFormat.DOCX.GetMediaType()));
FileRef result = createPdfOperation.Execute(context);
result.SaveAs("CreatePDFOutput.pdf");

Methods

CreateNew()

Constructs a CreatePDFOperation instance

Declaration
public static CreatePDFOperation CreateNew()
Returns
Type Description
CreatePDFOperation

a new CreatePDFOperation instance

Execute(ClientContext)

Executes this operation synchronously using the supplied context and returns a new FileRef instance for the resulting PDF file.

The resulting file may be stored in the system temporary directory. See FileRef for how temporary resources are cleaned up.

Declaration
public FileRef Execute(ClientContext context)
Parameters
Type Name Description
ClientContext context

the context in which to execute the operation

Returns
Type Description
FileRef

the resultant PDF file

Exceptions
Type Condition
ServiceApiException

if an API call results in an error response

SDKException

this is thrown for client-side errors

System.IO.FileNotFoundException

if the client conifg file or the input source does not exist in a specified path

System.IO.IOException

if there is an error in reading either the input source or the resulting file

System.ArgumentException

thrown when any of the inputs provided is not valid

System.InvalidOperationException

thrown when operation instance is invoked more than once

SetInput(FileRef)

Sets an input file.

Declaration
public void SetInput(FileRef sourceFileRef)
Parameters
Type Name Description
FileRef sourceFileRef

an input file

SetOptions(CreatePDFOptions)

Sets the conversion parameters for this operation. See CreatePDFOptions for how to specify the conversion parameters for the different source media types.

Declaration
public void SetOptions(CreatePDFOptions createPdfOptions)
Parameters
Type Name Description
CreatePDFOptions createPdfOptions

conversion parameters; use null for default values

Implements

IOperation
Back to top Copyright © 2019 Adobe. All rights reserved.