bool pdfcrop(string inputFileName, string outputFileName, bool use_bp, int page = 1, BoundingBoxPair origbb = null, int version = -1) { return pdfcrop(inputFileName, outputFileName, use_bp, new List<int>() { page }, new List<BoundingBoxPair>() { origbb }, true, true, true, version); }
BoundingBoxPair AddMargineToBoundingBox(BoundingBoxPair bb, bool use_bp) { return new BoundingBoxPair(AddMargineToBoundingBox(bb.bb, use_bp), AddMargineToBoundingBox(bb.hiresbb, use_bp)); }
// origbbには,GhostscriptのsDevice=bboxで得られた値を入れておく。(nullならばここで取得する。) // versionはinputFileNameのpdfバージョン private bool pdf2eps(string inputFileName, string outputFileName, int resolution, int page, int version, BoundingBoxPair origbb = null) { string arg; tempFilesDeleter.AddFile(outputFileName); var tmppdf = TempFilesDeleter.GetTempFileName(".pdf", workingDir); tempFilesDeleter.AddFile(tmppdf); // あらかじめpdf2writeにかけておくと透明にちょっと強くなる if (!pdf2pdf(inputFileName, tmppdf, resolution, version, page)) return false; using (var proc = GetProcess()) { proc.StartInfo.FileName = setProcStartInfo(Properties.Settings.Default.gsPath, out arg); if (proc.StartInfo.FileName == "") { if (controller_ != null) controller_.showPathError("gswin32c.exe", "Ghostscript"); return false; } if (arg != "") arg += " "; proc.StartInfo.Arguments = arg + "-dNOPAUSE -dBATCH -sDEVICE=" + Properties.Settings.Default.gsDevice + " -dFirstPage=1 -dLastPage=1"; if (IsNewGhostscript()) proc.StartInfo.Arguments += " -dNoOutputFonts"; else proc.StartInfo.Arguments += " -dNOCACHE"; proc.StartInfo.Arguments += " -dEPSCrop -sOutputFile=\"" + outputFileName + "\" -r" + resolution + " \"" + tmppdf + "\""; try { printCommandLine(proc); ReadOutputs(proc, Properties.Resources.PDFTOEPS); } catch (Win32Exception) { if (controller_ != null) controller_.showPathError(Properties.Settings.Default.gsPath, "Ghostscript"); return false; } catch (TimeoutException) { return false; } if (proc.ExitCode != 0 || !File.Exists(Path.Combine(workingDir, outputFileName))) { if (controller_ != null) controller_.showGenerateError(); return false; } // BoundingBoxをあらかじめ計測した物に取り替える。 BoundingBoxPair bb; if (origbb == null) bb = readPDFBB(inputFileName, page); else bb = origbb; if (bb == null) return false; Func<BoundingBox, BoundingBox> bbfunc = (b) => bb.bb; Func<BoundingBox, BoundingBox> hiresbbfunc = (b) => bb.hiresbb; rewriteBB(outputFileName, bbfunc, hiresbbfunc); } return true; }
static Size BBToSize(BoundingBoxPair bb, bool hires){ var usebb = hires ? bb.hiresbb : bb.bb; var size = new Size(); size.width = usebb.Width; size.height = usebb.Height; return size; }