How to Convert PostScript to PDF in .NET with C#
This .NET walkthrough uses C# and HttpClient to submit the request. It converts a PostScript (.ps) file into PDF through the pdfRest Convert to PDF API Tool and includes a custom .joboptions profile. The complete sample is included below so .NET with C# developers can see the file handling, request construction, and response path together.
Why PostScript to PDF in .NET with C#?
C# can sit between a PostScript-producing system and a PDF-centric line-of-business application. Converting the .ps file at that boundary allows the surrounding .NET workflow to use its usual PDF review, storage, and distribution paths.
A document-assembly service might receive PostScript from a longstanding report engine and apply a team-owned .joboptions profile before returning a PDF to an approval portal. The profile is uploaded with the request, so its selection is explicit and auditable.
When the profile is not supplied, the converter uses default settings. The sample’s optional argument is therefore a configuration choice, not a separate conversion feature that requires another endpoint.
C# Code Example for PostScript to PDF
/* * What this sample does: * - Converts PostScript to PDF with a custom .joboptions profile. * - A .joboptions file contains Adobe Distiller-compatible conversion settings. * The profile is optional; omit job_options to use default settings. * - pdfRest applies a supplied profile with Datalogics PDF Converter SDK. * Datalogics maintains the SDK in partnership with Adobe, using the same * Adobe technology that powers Distiller. * - Pair with /postscript for PDF refrying: PDF -> PostScript -> PDF. Some print and * prepress workflows use this lossy roundtrip to rebuild or normalize page content. * * Setup (environment): * - Set PDFREST_API_KEY=your_api_key_here * - Optional: set PDFREST_URL to override the API region. * * Usage: * dotnet run -- pdf-from-postscript-multipart*/ using System.Net.Http.Headers; namespace Samples.EndpointExamples.MultipartPayload; public static class PdfFromPostscript { public static async Task Execute(string[] args) { var inputPath = args.Length > 0 ? args[0] : "/path/to/sample.ps"; var jobOptionsPath = args.Length > 1 ? args[1] : "/path/to/custom.joboptions"; var apiKey = Environment.GetEnvironmentVariable("PDFREST_API_KEY"); if (string.IsNullOrWhiteSpace(apiKey)) throw new InvalidOperationException("Missing PDFREST_API_KEY"); var baseUrl = Environment.GetEnvironmentVariable("PDFREST_URL") ?? "https://api.pdfrest.com"; using var client = new HttpClient { BaseAddress = new Uri(baseUrl) }; client.DefaultRequestHeaders.TryAddWithoutValidation("Api-Key", apiKey); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using var form = new MultipartFormDataContent(); var inputContent = new ByteArrayContent(await File.ReadAllBytesAsync(inputPath)); inputContent.Headers.ContentType = new MediaTypeHeaderValue("application/postscript"); form.Add(inputContent, "file", Path.GetFileName(inputPath)); var jobOptionsContent = new ByteArrayContent(await File.ReadAllBytesAsync(jobOptionsPath)); jobOptionsContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); form.Add(jobOptionsContent, "job_options", Path.GetFileName(jobOptionsPath)); form.Add(new StringContent("pdf_from_postscript"), "output"); var response = await client.PostAsync("pdf", form); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); if (!response.IsSuccessStatusCode) Environment.ExitCode = 1; } }
Source: View the sample on GitHub
Breaking Down the Code
Configure the service and input
var jobOptionsPath = args.Length > 1 ? args[1] : "/path/to/custom.joboptions";
var apiKey = Environment.GetEnvironmentVariable("PDFREST_API_KEY");
if (string.IsNullOrWhiteSpace(apiKey)) throw new InvalidOperationException("Missing PDFREST_API_KEY");
var baseUrl = Environment.GetEnvironmentVariable("PDFREST_URL") ?? "https://api.pdfrest.com";
using var client = new HttpClient { BaseAddress = new Uri(baseUrl) };
client.DefaultRequestHeaders.TryAddWithoutValidation("Api-Key", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
For this PostScript to PDF example, .NET with C# sends the multipart request to /pdf. The C# samples use framework HttpClient APIs and disposable content objects. API credentials come from PDFREST_API_KEY, keeping the secret out of the source file and request body. The sample’s placeholder path and API key make the moving pieces visible; replace them with a real local path and protected runtime credential before using the request.
Apply the PostScript Conversion Profile
form.Add(inputContent, "file", Path.GetFileName(inputPath));
var jobOptionsContent = new ByteArrayContent(await File.ReadAllBytesAsync(jobOptionsPath));
jobOptionsContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
form.Add(jobOptionsContent, "job_options", Path.GetFileName(jobOptionsPath));
form.Add(new StringContent("pdf_from_postscript"), "output");
var response = await client.PostAsync("pdf", form);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
if (!response.IsSuccessStatusCode) Environment.ExitCode = 1;
}
}
Here, .NET with C# sends the PostScript source and the optional profile as separate files. A .joboptions file contains Adobe Distiller-compatible conversion settings; pdfRest applies a supplied profile with Datalogics PDF Converter SDK, maintained in partnership with Adobe and using the same Adobe technology that powers Distiller. Omitting job_options uses default settings.
Build the multipart request
client.DefaultRequestHeaders.TryAddWithoutValidation("Api-Key", apiKey);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using var form = new MultipartFormDataContent();
var inputContent = new ByteArrayContent(await File.ReadAllBytesAsync(inputPath));
inputContent.Headers.ContentType = new MediaTypeHeaderValue("application/postscript");
form.Add(inputContent, "file", Path.GetFileName(inputPath));
var jobOptionsContent = new ByteArrayContent(await File.ReadAllBytesAsync(jobOptionsPath));
jobOptionsContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
form.Add(jobOptionsContent, "job_options", Path.GetFileName(jobOptionsPath));
form.Add(new StringContent("pdf_from_postscript"), "output");
var response = await client.PostAsync("pdf", form);
For the PostScript to PDF form, MultipartFormDataContent owns the uploaded streams and text values. The .NET runtime calculates the multipart boundary and content type when HttpClient sends the container.
Read the output resource
jobOptionsContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
form.Add(jobOptionsContent, "job_options", Path.GetFileName(jobOptionsPath));
form.Add(new StringContent("pdf_from_postscript"), "output");
var response = await client.PostAsync("pdf", form);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
if (!response.IsSuccessStatusCode) Environment.ExitCode = 1;
}
}
After the PostScript to PDF call, the client reads the response text and reports non-success status through the process exit code. A successful JSON body identifies the managed output resource, while an unsuccessful body should be surfaced to the calling application.
Beyond the Tutorial
You have now used .NET with C# to turn a PostScript source into a managed PDF and make its conversion profile explicit. That gives the surrounding application a deliberate choice between a team-maintained .joboptions file and the service defaults.
Try representative postscript to pdf inputs in API Lab. For the authoritative request fields, accepted values, and response contract, consult the Convert to PDF API Tool documentation. The same request pattern can then be adapted to your .NET with C# application’s error handling, retention policy, and delivery workflow.
A JSON-payload PostScript-to-PDF example is available for .NET with C# as well. That form uploads the .ps and optional .joboptions files first, then passes their resource IDs to /pdf. View the JSON-payload sample on GitHub.