Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active January 3, 2022 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/21e71916f06bd82a3c1bc48944aa6209 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/21e71916f06bd82a3c1bc48944aa6209 to your computer and use it in GitHub Desktop.
Convert Emails to PDF using REST API in PHP
// The following code example demonstrates how to add Client id and secret in the code
static $ClientId = '659fe7da-715b-4744-a0f7-cf469a392b73';
static $ClientSecret = 'b377c36cfa28fa69960ebac6b6e36421';
static $ApiBaseUrl = 'https://api.groupdocs.cloud';
static $MyStorage = '';
// This code example demonstrates how to convert Email attachments to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Create ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("Msg_with_attachments.msg");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedAttachments.pdf");
// Define MSG load options
$loadOptions = new GroupDocs\Conversion\Model\MsgLoadOptions();
$loadOptions->setConvertAttachments(true);
// Create document request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code example demonstartes how to download PDF from the cloud.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Initialize API
$apiInstance = new GroupDocs\Conversion\FileApi($configuration);
// Create download request
$request = new GroupDocs\Conversion\Model\Requests\DownloadFileRequest("convertedEML.pdf", self::$MyStorage, null);
// Download file
$response = $apiInstance->downloadFile($request);
// This code example demonstrates how to convert EML to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
$configuration->setApiBaseUrl(self::$ApiBaseUrl);
// Create the new ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("sample.eml");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedEML.pdf");
// Define EML load options
$loadOptions = new GroupDocs\Conversion\Model\EmlLoadOptions();
$loadOptions->setDisplayHeader(true);
$loadOptions->setDisplayFromEmailAddress(true);
$loadOptions->setDisplayToEmailAddress(true);
$loadOptions->setDisplayEmailAddress(true);
$loadOptions->setDisplayCcEmailAddress(true);
$loadOptions->setDisplayBccEmailAddress(true);
$settings->setLoadOptions($loadOptions);
// Define PDF convert options
$convertOptions = new GroupDocs\Conversion\Model\PdfConvertOptions();
$convertOptions->setCenterWindow(true);
$convertOptions->setMarginTop(50);
$convertOptions->setMarginLeft(50);
$convertOptions->setMarginRight(50);
$convertOptions->setMarginBottom(50);
$settings->setConvertOptions($convertOptions);
// Create convert request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code example demonstrates how to convert MSG to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
$configuration->setApiBaseUrl(self::$ApiBaseUrl);
// Create the new ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("sample.msg");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedMSG.pdf");
// Define MSG load options
$loadOptions = new GroupDocs\Conversion\Model\MsgLoadOptions();
$loadOptions->setDisplayCcEmailAddress(true);
$loadOptions->setDisplayBccEmailAddress(true);
$settings->setLoadOptions($loadOptions);
// Create convert request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code sample demonstrates how to upload an EML file to the cloud.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Initialize API
$apiInstance = new GroupDocs\Conversion\FileApi($configuration);
$file = "C:\\Files\\Conversion\\email\\sample.eml";
$request = new GroupDocs\Conversion\Model\Requests\UploadFileRequest("sample.eml", $file, self::$MyStorage, null);
$response = $apiInstance->uploadFile($request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment