/// <summary> /// Konvertiert die PDF-Datei in Tiff-Dateien. /// Die Dateien werden in den Temp-Ordner des aktuellen Benutzers erzeugt. /// Gibt eine liste mit den Pfaden der Tiff-Dateien zurück. /// </summary> public List <string> ConvertPDFToImage(DocumentParam param) { List <string> list = new List <string>(); try { FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(list); } string pathFolder = FilesFunctions.CreateFolder(fileInfo); if (string.CompareOrdinal(pathFolder, string.Empty) == 0) { return(list); } list = ConvertPDFToImage(pathFolder, true, param); return(list); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(list); } }
private bool SaveCDW_in_Rastr(Document2D doc) { DocumentParam docP = (DocumentParam)kompas.GetParamStruct((short)StructType2DEnum.ko_DocumentParam); if (docP == null) { kompas.ksMessage("Не удалось получить интерфейс DocumentParam"); return(false); } int t = doc.ksGetObjParam(doc.reference, docP); string filename = docP.fileName; filename = filename.Substring(0, filename.Length - 4); RasterFormatParam formatRasret = doc.RasterFormatParam(); //if (formatRasret.Init()) //{ // kompas.ksMessage("Обнулились параметры RasterFormatParam"); //} if (formatRasret == null) { return(false); } if (setting.Format == 20) { formatRasret.format = 4; } else { formatRasret.format = setting.Format; } formatRasret.colorBPP = setting.ColorBPP; formatRasret.colorType = setting.ColorType; formatRasret.extResolution = setting.Resolution; formatRasret.extScale = setting.Scale; formatRasret.greyScale = false; formatRasret.onlyThinLine = false; formatRasret.multiPageOutput = multiTiff; if (kolLists == 1 || multiTiff) { string fileTiff_f = filename + "." + ConvertFormat(setting.Format); if (!doc.SaveAsToRasterFormat(fileTiff_f, formatRasret)) { return(false); } return(true); } for (int i = 1; i < kolLists + 1; i++) { string fileName_f = filename; string fileTiff_f = fileName_f + "." + ConvertFormat(setting.Format); formatRasret.pages = i.ToString() + "-" + i.ToString(); fileTiff_f = fileName_f + "(" + i.ToString() + ")" + "." + ConvertFormat(setting.Format); if (!doc.SaveAsToRasterFormat(fileTiff_f, formatRasret)) { return(false); } } return(true); }
/// <summary> /// Von dem Doc-Dokument wird die erste Seite in tiff konvertiert und gespeichert. /// die funktion liefert den Path zu der neue Datei zurück. /// </summary> public string GetFirstPageAsImageFromDocument(DocumentParam param) { try { string fileName = string.Empty; FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(fileName); } string pathFolder = Path.GetTempPath(); FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff); string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, true, Pdf); using (RichEditDocumentServer richServer = new RichEditDocumentServer()) { richServer.LoadDocument(param.FilePath); //Specify export options: PdfExportOptions options = new PdfExportOptions { Compressed = false, ImageQuality = PdfJpegImageQuality.Highest }; //Export the document to the stream: using (FileStream pdfFileStream = new FileStream(tempName, FileMode.Create)) { richServer.ExportToPdf(pdfFileStream, options); } } var pdf = new PdfTiffConverter(); var parammeter = new DocumentParam { Resolution = param.Resolution, Colour = param.Colour, Compression = param.Compression, Quality = param.Quality, KeepOriginal = param.KeepOriginal, ConTyp = param.ConTyp, Doctyp = param.Doctyp, FilePath = tempName }; fileName = pdf.GetFirstPageAsImageFromDocument(parammeter); return(fileName); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(string.Empty); } }
/// <summary> /// Konvertiert die PDF-Datei in Tiff-Dateien. /// Gibt eine liste mit den Pfaden der Tiff-Dateien zurück. /// </summary> public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param) { List <string> list = new List <string>(); try { if (string.CompareOrdinal(pathFolder, string.Empty) == 0) { return(list); } FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(list); } FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff); // open existing PDF document using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true)) { // set resolution //pdfDocument.RenderingSettings.Resolution = new Resolution(param.Resolution, param.Resolution); //// set rendering mode - optimal balance between rendering speed and quality //pdfDocument.RenderingSettings.RenderingMode = PdfRenderingMode.HighSpeed; for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++) { string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Tiff); // create new TIFF file using (TiffFile tiffFile = new TiffFile(tempName, TiffFileFormat.LittleEndian)) { tiffFile.Pages.EncoderSettings.Compression = TiffCompression.Zip; tiffFile.Pages.Add(pdfDocument.Pages[pageCount].Render()); tiffFile.SaveChanges(); list.Add(tempName); } } } return(list); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(list); } }
/// <summary> /// Konvertiert die PDF-Datei in Jpeg-Dateien. /// Gibt eine liste mit den Pfaden der Jpeg-Dateien zurück. /// </summary> public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param) { List <string> list = new List <string>(); try { if (string.CompareOrdinal(pathFolder, string.Empty) == 0) { return(list); } FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(list); } FilesFunctions.DeleteFilesInFolder(pathFolder, Jpeg); using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true)) { //pdfDocument.RenderingSettings.Resolution = new Resolution(150, 150); JpegEncoder jpeGencoder = new JpegEncoder { Settings = { Quality = param.Quality, SaveAsGrayscale = false } }; for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++) { string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Jpeg); // get image of PDF page as VintasoftImage object using (VintasoftImage vsImage = pdfDocument.Pages[pageCount].Render()) { // save VintasoftImage object as JPEG file vsImage.Save(tempName, jpeGencoder); list.Add(tempName); } } } return(list); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(list); } }
private static int ConvertFile(DocumentParam param) { try { List <string> list = param.Doctyp != eDocumentTyp.NONE ? _converter.ConvertToImage(param) : new List <string>(); return(list.Count); } catch (Exception) { return(0); } }
private int GetCountOhterFiles(ConverterInfos settings, DocumentParam param) { List <FileInfo> fileList = new List <FileInfo>(); DirectoryInfo dir = new DirectoryInfo(settings.PathToFile); FileInfo[] files = dir.GetFiles(settings.FileFilter); if (files.Length == 0) { return(fileList.Count); } string fileBeginnWith = settings.FileFilter.Replace("*.*", ""); string expre = $@"{fileBeginnWith}[0-9]{{3}}[_][0-9]{{4,}}.{param.ConTyp.ToString().ToLower()}"; Regex rx = new Regex(expre, RegexOptions.IgnoreCase); Array.ForEach(files, file => { if (rx.IsMatch(file.Name) == false) { fileList.Add(file); } }); List <string> ext = new List <string> { "pdf", "doc", "docx", "rtf", "safe" }; int count = 0; foreach (FileInfo file in fileList) { var endString = file.FullName.Substring(file.FullName.LastIndexOf('.') + 1).ToLower(); if (ext.Contains(endString)) { continue; } ++count; } return(count); }
//public bool Colour { get; set; } //public int Compression { get; set; } //public bool KeepOriginal { get; set; } /// <summary> /// Von dem PDF-Dokument wird die erste Seite in tiff konvertiert und gespeichert. /// die funktion liefert den Path zu der neue Datei zurück. /// </summary> public string GetFirstPageAsImageFromDocument(DocumentParam param) { try { string fileName = string.Empty; FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(fileName); } string pathFolder = Path.GetTempPath(); using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true)) { // set resolution pdfDocument.RenderingSettings.Resolution = new Resolution(param.Resolution, param.Resolution); // set rendering mode - optimal balance between rendering speed and quality pdfDocument.RenderingSettings.RenderingMode = PdfRenderingMode.HighQuality; string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, true, Tiff); for (int pageCount = 0; pageCount < pdfDocument.Pages.Count; pageCount++) { // create new TIFF file using (TiffFile tiffFile = new TiffFile(tempName, TiffFileFormat.LittleEndian)) { tiffFile.Pages.EncoderSettings.Compression = TiffCompression.Lzw; tiffFile.Pages.Add(pdfDocument.Pages[pageCount].Render()); tiffFile.SaveChanges(); fileName = tempName; } } } return(fileName); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(string.Empty); } }
//public bool Colour { get; set; } //public int Compression { get; set; } //public bool KeepOriginal { get; set; } #region Jpeg /// <summary> /// Von dem PDF-Dokument wird die erste Seite in Jpeg konvertiert und gespeichert. /// die funktion liefert den Path zu der neue Datei zurück. /// </summary> public string GetFirstPageAsImageFromDocument(DocumentParam param) { try { string fileName = string.Empty; FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(fileName); } string pathFolder = Path.GetTempPath(); using (PdfDocument pdfDocument = new PdfDocument(param.FilePath, true)) { pdfDocument.RenderingSettings.Resolution = new Resolution(150, 150); JpegEncoder jpeGencoder = new JpegEncoder { Settings = { Quality = param.Quality, SaveAsGrayscale = false } }; for (int pageCount = 0; pageCount < 1; pageCount++) { string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, true, Jpeg); // get image of PDF page as VintasoftImage object using (VintasoftImage vsImage = pdfDocument.Pages[pageCount].Render()) { // save VintasoftImage object as JPEG file vsImage.Save(tempName, jpeGencoder); fileName = tempName; } } } return(fileName); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(string.Empty); } }
public bool SaveCDW_in_Rastr(IKompasDocument2D doc7) { ksDocument2D doc = (ksDocument2D)Kompas.TransferInterface(doc7, (int)ksAPITypeEnum.ksAPI5Auto, 0); DocumentParam docP = (DocumentParam)Kompas.GetParamStruct((short)StructType2DEnum.ko_DocumentParam); if (docP == null) { //Kompas.ksMessage("Не удалось получить интерфейс DocumentParam"); return(false); } int t = doc.ksGetObjParam(doc.reference, docP); string filename = docP.fileName; filename = filename.Substring(0, filename.Length - 4); RasterFormatParam formatRasret = doc.RasterFormatParam(); //if (formatRasret.Init()) //{ // kompas.ksMessage("Обнулились параметры RasterFormatParam"); //} formatRasret.format = 2; formatRasret.colorBPP = 24; formatRasret.colorType = 1; formatRasret.extResolution = 300; formatRasret.extScale = 1; formatRasret.greyScale = false; formatRasret.onlyThinLine = false; formatRasret.multiPageOutput = false; string fileTiff_f = filename + ".jpg"; if (!doc.SaveAsToRasterFormat(fileTiff_f, formatRasret)) { return(false); } return(true); }
private void Send(long contractId, List <long> documentIds) { //设置接收人,名称、联系方式必填 List <Receiver> receivers = new List <Receiver>(); List <StandardStamper> platestampers = new List <StandardStamper>(); //指定本方签署位置 StandardStamper sealStamper = new StandardStamper(); sealStamper.documentId = documentIds[0]; sealStamper.page = 1; sealStamper.offsetX = 0.5; sealStamper.offsetY = 0.5; sealStamper.type = StandardSignType.SEAL; StandardStamper stStamper = new StandardStamper(); stStamper.documentId = documentIds[0]; stStamper.page = 1; stStamper.offsetX = 0.5; stStamper.offsetY = 0.45; stStamper.type = StandardSignType.SEAL_TIMESTAMP; // StandardStamper lpStamper = new StandardStamper(); // lpStamper.documentId = documentIds[1]; // lpStamper.page = 1; // lpStamper.offsetX = 0.6; // lpStamper.offsetY = 0.2; // lpStamper.type = StandardSignType.LEGAL_PERSON; platestampers.Add(sealStamper); platestampers.Add(stStamper); //platestampers.Add(lpStamper); //需要本方签署,则将本方加入接收者列表 Receiver platform = new Receiver(); platform.type = AccountType.PLATFORM; platform.ordinal = 0; platform.stampers = platestampers; //指定签署位置 platform.legalPersonRequired = false; //指定法人签署 receivers.Add(platform); StandardStamper pStamper = new StandardStamper(); pStamper.documentId = documentIds[0]; pStamper.page = 1; pStamper.offsetX = 0.64; pStamper.offsetY = 0.105; pStamper.type = StandardSignType.PERSONAL; StandardStamper ptStamper = new StandardStamper(); ptStamper.documentId = documentIds[0]; ptStamper.page = 1; ptStamper.offsetX = 0.655; ptStamper.offsetY = 0.058; ptStamper.type = StandardSignType.PERSONAL_TIMESTAMP; StandardStamper pStamper_d = new StandardStamper(); pStamper_d.documentId = documentIds[0]; pStamper_d.page = 1; pStamper_d.offsetX = 0.658; pStamper_d.offsetY = 0.09; pStamper_d.type = StandardSignType.PERSONAL; StandardStamper ptStamper_d = new StandardStamper(); ptStamper_d.documentId = documentIds[0]; ptStamper_d.page = 1; ptStamper_d.keyword = null; ptStamper_d.offsetX = 0.662; ptStamper_d.offsetY = 0.05; ptStamper_d.type = StandardSignType.PERSONAL_TIMESTAMP; List <StandardStamper> personalStampers = new List <StandardStamper>(); personalStampers.Add(pStamper); personalStampers.Add(ptStamper); personalStampers.Add(pStamper_d); personalStampers.Add(ptStamper_d); Receiver receiver = new Receiver(); receiver.name = "张忱昊"; receiver.mobile = "17621699044"; receiver.type = AccountType.PERSONAL; receiver.authLevel = AuthenticationLevel.BASIC; receiver.ordinal = 1; receiver.stampers = personalStampers;//个人签署位置 List <AttachmentRequest> attachments = new List <AttachmentRequest>(); AttachmentRequest attachmentRequest1 = new AttachmentRequest(); attachmentRequest1.title = "附件名称"; attachmentRequest1.required = true; attachmentRequest1.needSign = false; attachments.Add(attachmentRequest1); receiver.attachments = attachments; receivers.Add(receiver); List <DocumentParam> documentParams = new List <DocumentParam>(); DocumentParam documentParam1 = new DocumentParam(); documentParam1.documentId = documentIds[0]; documentParam1.name = "参数名称"; documentParam1.value = "参数默认值"; documentParam1.receiverNo = 1; documentParams.Add(documentParam1); SendRequest request = new SendRequest(); request.contractId = contractId; //指定发起的合同ID request.categoryId = null; //不指定业务分类 request.receivers = receivers; request.documentParams = documentParams; request.receiveType = ReceiveType.SEQ;//设置签署人顺序签署 try { signService.Send(request); Console.WriteLine("合同成功发起!"); } catch (Exception e) { throw e; } }
/// <summary> /// Konvertiert die Doc-Datei in Tiff-Dateien. /// Gibt eine liste mit den Pfaden der Tiff-Dateien zurück. /// </summary> public List <string> ConvertPDFToImage(string pathFolder, bool tempPrefix, DocumentParam param) { List <string> list = new List <string>(); try { FileInfo fileInfo = new FileInfo(param.FilePath); if (fileInfo.Exists == false) { return(list); } FilesFunctions.DeleteFilesInFolder(pathFolder, Tiff); //string tempName = FilesFunctions.GetRandomName(pathFolder, fileInfo, tempPrefix, Pdf); string temp = $@"{Path.GetTempPath()}\Synios\{Path.GetFileNameWithoutExtension(fileInfo.FullName)}{Pdf}"; using (RichEditDocumentServer richServer = new RichEditDocumentServer()) { richServer.LoadDocument(param.FilePath); //Specify export options: PdfExportOptions options = new PdfExportOptions { Compressed = false, ImageQuality = PdfJpegImageQuality.Highest }; //Export the document to the stream: using (FileStream pdfFileStream = new FileStream(temp, FileMode.Create)) { richServer.ExportToPdf(pdfFileStream, options); } } var pdf = new PdfTiffConverter(); var parammeter = new DocumentParam { Resolution = param.Resolution, Colour = param.Colour, Compression = param.Compression, Quality = param.Quality, KeepOriginal = param.KeepOriginal, ConTyp = param.ConTyp, Doctyp = param.Doctyp, FilePath = temp }; list = pdf.ConvertPDFToImage(pathFolder, tempPrefix, parammeter); return(list); } catch (Exception ex) { FileLogger.FileLogger.Instance.WriteExeption(ex); return(list); } }