Generate PDF usage reports with the Document Converter Services API
This guide explains how to use the instrumentation features in the Document Converter Services API to generate PDF reports based on usage data.
The below code uses the OpenService
and CloseService
methods from PDF Converter API - Document Converter Service Client sample code.
static void Main(string[] args) { // Output result file name string reportFile = Path.GetFullPath("report.pdf"); // Target folder string targetFolder = @"c:\temp"; // Document Converter Services end point string serviceURL = "http://localhost:41734/Muhimbi.DocumentConverter.WebService/"; // Create and populate Report Request ReportRequest reportRequest = new ReportRequest(); reportRequest.Total = BooleanEnum.True; reportRequest.StartDate = "2024-01-01"; reportRequest.EndDate = "2025-01-01"; // Get the report bool success = GetPDFReport(reportFile, reportRequest); } /// <summary> /// Get a PDF report /// </summary> /// <param name="reportOutputFile">Report file name</param> /// <param name="reportRequest">Report Request settings</param> /// <returns></returns> static bool GetPDFReport(string reportOutputFile, ReportRequest reportRequest) { bool success = false; DocumentConverterServiceClient client = null; try { // Open the client client = new DocumentConverterServiceClient(); // If the directory exists, if (Directory.Exists(Path.GetDirectoryName(reportOutputFile))) { // If the report file exists, delete it if (File.Exists(reportOutputFile)) { File.Delete(reportOutputFile); } } // Otherwise create it else { Directory.CreateDirectory(Path.GetDirectoryName(reportOutputFile)); } // Get the report byte[] report = client.GetPDFReport(reportRequest); if (report != null) { // ** Write the result back to the file reportOutputFile. File.WriteAllBytes(reportOutputFile, report); Console.WriteLine($"Result saved to {reportOutputFile}"); success = true; } else { Console.WriteLine("Returned null"); success = false; } } finally { // If the client is not null, if (client != null) { // Close the client client.Close(); } } // Return success status return success; }