I am trying to take in a PDF File which has in the center a vector graphic , however it has text and other logos around the page that i do not need. I need to extract the vector portion of the File only, so far below what i have been able to do is create a CropBox and then convert the cropbox to a bitmap.
This results in extracting the graphic in the center of the page only but the downside is that it is a Bitmap. Once i create the PDF using the cropbox if i open it in windows it shows just what i need, however when i then import it into CorelDraw or Adobe Illustrator it still has all the other data and as i learn the cropbox just hides everything else.
So the question is, how can i go about this with ghostscript or a similar free c# library to turn my crop box PDF section to a new pdf with only that data?
private string CropPDFToBitmap()
{
try
{
CheckOutputPathExists();
string gsPath = @"C:\Program Files (x86)\gs\gs9.50\bin\gswin32c";
string argo = $"-o {this.BaseFileLocation}\\cropped\\{RemoveExtension(TargetFileName)}.pdf -sDEVICE=pdfwrite -c \"[/CropBox[281 197 531 447]\" -c \" /PAGES pdfmark\" -f {this.BaseFileLocation}\\{RemoveExtension(TargetFileName)}.pdf";
string ProductionFile = $"{ this.BaseFileLocation}\\bitmaps\\{RemoveExtension(TargetFileName)}.bmp";
string bitmapArg = $" -dUseCropBox -dNOPAUSE -sDEVICE=bmp256 -r600 -o {ProductionFile} {this.BaseFileLocation}\\cropped\\{RemoveExtension(TargetFileName)}.pdf";
// " -dUseCropBox -dNOPAUSE -sDEVICE=bmp256 -r600 -o C:\\final.bmp C:\\cropped.pdf"
//{this.BaseFileLocation}\cropped\{RemoveExtension(TargetFileName)}.pdf
var cropProcess = Process.Start(gsPath, argo);
cropProcess.WaitForExit();
var bitmapProcess = Process.Start(gsPath, bitmapArg);
bitmapProcess.WaitForExit();
return ProductionFile;
}
catch (Exception ex)
{
Debug.WriteLine("Failed {0}", ex.Message);
throw new Exception(ex.Message);
}
}