/// <summary> /// convert document to some format if the format specified. /// </summary> /// <param name="name">The document name.</param> /// <param name="format">PDF Document convert format</param> /// <param name="folder">The document folder.</param> /// <param name="outPath">Path to save result. It can be local (e.g. c:\out.doc) or cloud storage path (MyFolder\out.doc). The conversion result for TeX and HTML formats can contain multiple files so it is returned as zip archive.</param> /// <param name="storage">The document storage.</param> public void ConvertToSomeFormat(string name, PDFDocumentConvertFormat format, string folder, string outPath, string storage = "") { // GET pdf/{name}?appSid={appSid}&format={format}&storage={storage}&folder={folder}&outPath={outPath} if (format == PDFDocumentConvertFormat.Tex || format == PDFDocumentConvertFormat.Html) outPath = outPath.Replace(Path.GetExtension(outPath), ".zip"); string apiUrl = string.Format(@"pdf/{0}?format={1}&storage={2}&folder={3}&outPath={4}", name, format, storage, folder, (outPath.Contains(@":\") ? string.Empty : outPath)); if (!string.IsNullOrEmpty(outPath) && Directory.Exists(Path.GetDirectoryName(outPath))) { using (Stream responseStream = ServiceController.GetStream(apiUrl, AppSid, AppKey)) using (Stream file = File.OpenWrite(outPath)) { ServiceController.CopyStream(responseStream, file); } } else { ServiceController.Get(apiUrl, AppSid, AppKey); } }
/// <summary> /// Convert document from URL. /// </summary> /// <param name="format">PDF Document convert format</param> /// <param name="inputFilePath">URL of the pdf file</param> /// <param name="outPath">Path to save result. It must be a local path (e.g. c:\out.doc).</param> public void ConvertDocument(PDFDocumentConvertFormat format, string inputFilePath, string outPath) { // PUT pdf/convert?appSid={appSid}&format={format}&url={url}&outPath={outPath} if (format == PDFDocumentConvertFormat.Tex || format == PDFDocumentConvertFormat.Html) outPath = outPath.Replace(Path.GetExtension(outPath), ".zip"); string apiUrl = string.Format(@"pdf/convert?format={0}&outPath={1}", format, (outPath.Contains(@":\") ? string.Empty : outPath)); if (!string.IsNullOrEmpty(outPath) && Directory.Exists(Path.GetDirectoryName(outPath))) { using (Stream responseStream = ServiceController.GetStreamWithPut(apiUrl, AppSid, AppKey, File.ReadAllBytes(inputFilePath))) using (Stream file = File.OpenWrite(outPath)) { ServiceController.CopyStream(responseStream, file); } } }