from C# Aspose : Is there a way to convert PS to PDF ?
Sample PS file
Cause
Currently, Aspose does not provide direct support for converting PostScript (PS) files to PDF format. However, you can use a workaround by first converting the PS file to a compatible format that Aspose.PDF can handle, such as an image format (e.g., PNG or JPEG), and then convert that image to PDF.
Solution
To achieve this, you can use a combination of tools or libraries. First, convert the PS file to an image using a tool like Ghostscript, and then use Aspose.PDF to convert the image to PDF.
Code
Here’s a sample workflow in C#:
- Convert PS to PNG using Ghostscript (make sure Ghostscript is installed):
gs -sDEVICE=pngalpha -o output.png input.ps
- Use Aspose.PDF to convert the PNG to PDF:
using Aspose.Pdf;
public void ConvertImageToPdf(string imagePath, string pdfPath)
{
// Load the image
var pdfDocument = new Document();
var image = new Image();
image.File = imagePath;
// Add the image to the PDF document
pdfDocument.Pages.Add().Paragraphs.Add(image);
// Save the PDF
pdfDocument.Save(pdfPath);
}
// Usage
ConvertImageToPdf("output.png", "output.pdf");
Next Steps
- Install Ghostscript and ensure it’s accessible from your command line.
- Run the Ghostscript command to convert your PS file to an image.
- Use the provided C# code to convert the generated image to a PDF.
If you have any questions or need further assistance, feel free to ask!
Post script file to PDF for the following sample file ?
Getting error : Index was outside the bounds of the array
Can a technical person check and get back ?
~Satheesh.
We tested in our environment using 25.7 version of the API and below code snippet. We noticed that the text was not converted correctly in the output PDF:
string inFile = dataDir + "test.ps";
string outFile = dataDir + "PdfToPostScript_out.pdf";
Document doc = new Document(inFile, new PsLoadOptions() { FontsFolders = new[] { "C:\\Windows\\Fonts" } });
//doc.ProcessParagraphs();
doc.Save(outFile);
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-60332
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.