public static void VideoThumbNail() { string inpath = "D:\\"; string inext = ".pdf"; var inp = inpath + "one" + inext; var outp = "D:\\three.jpg"; GhostscriptWrapper.GeneratePageThumb(inp, outp, 6, 110, 90); }
public string GenerateImage(string pathToFile) { string filename = Path.GetFileNameWithoutExtension(pathToFile); string path = "D:\\BookImages\\" + filename + ".png"; Debug.WriteLine(path); GhostscriptWrapper.GeneratePageThumb(pathToFile, path, 1, 120, 250); return(path); }
public static string Generate(string file) { using (ApplicationContext.Current.ProfilingLogger.TraceDuration <ThumbnailGenerator>("Started Creatning Thumbnail", "Completed Creating Thumbnail")) { var fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); var outputUrl = GenerateThumbnailFilename(file); var output = fileSystem.GetFullPath(outputUrl); var temp = Path.ChangeExtension(Path.GetRandomFileName(), "pdf"); var tempFilename = Path.Combine(Path.GetDirectoryName(fileSystem.GetFullPath(fileSystem.GetFullPath(file))), temp); var tempOutputFilename = GenerateThumbnailFilename(tempFilename); try { //var source = fileSystem.GetFullPath(file); fileSystem.CopyFile(file, tempFilename); LogHelper.Info <ThumbnailGenerator>($"Generate {tempFilename} to {tempOutputFilename}"); GhostscriptWrapper.GeneratePageThumb(tempFilename, tempOutputFilename, 1, 100, 100); LogHelper.Info <ThumbnailGenerator>($"Generated {tempFilename} to {tempOutputFilename}"); fileSystem.DeleteFile(tempFilename); fileSystem.CopyFile(tempOutputFilename, output); fileSystem.DeleteFile(tempOutputFilename); return(outputUrl); } catch (Exception ex) { LogHelper.Error <ThumbnailGenerator>("Faled generat pdf thumbnail", ex); return(null); } finally { if (fileSystem.FileExists(tempFilename)) { fileSystem.DeleteFile(tempFilename); } if (fileSystem.FileExists(tempOutputFilename)) { fileSystem.DeleteFile(tempOutputFilename); } } } }
protected override void CreateImage() { GhostscriptUtil.EnsureDll(); string outputFileName = Path.GetTempFileName(); try { string filename = FileSourceHelper.ResolveFileName(SourceFileName); GhostscriptWrapper.GeneratePageThumb(filename, outputFileName, PageNumber, 96, 96); Bitmap = new FastBitmap(File.ReadAllBytes(outputFileName)); } finally { File.Delete(outputFileName); } }
/// <summary> /// Create thumbnail of pdf file /// </summary> /// <param name="mediaFile">pdf file object</param> public string GenerateThumb(MediaFileItem mediaFile) { using (new Tracer()) { try { if (!string.IsNullOrEmpty(mediaFile.ThumbLocation)) { GhostscriptWrapper.GeneratePageThumb(mediaFile.MediaLocation, mediaFile.ThumbLocation, 1, mediaFile.Width, mediaFile.Height); } } catch (Exception ex) { Log.Error(ex); } return(mediaFile.ThumbLocation); } }
public void GenerateSinglePageThumbnail() { GhostscriptWrapper.GeneratePageThumb(TEST_FILE_LOCATION, SINGLE_FILE_LOCATION, 1, 100, 100); Assert.IsTrue(File.Exists(SINGLE_FILE_LOCATION)); }
/// <summary> /// Save document in the server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { try { string pathServerTemp = Server.MapPath("Portals/0/Images/Temp/"); string pathServerThumbImages = Server.MapPath("Portals/0/ModIma/ThumbImages/"); if (IsChallengeFiles) { if (string.IsNullOrEmpty(ValidateSecurity.ValidateString(txtTitle.Text, false))) { rgvtxtTitle.IsValid = false; return; } //Information of the document challengeFileComponent = new ChallengeFileComponent(Guid.NewGuid()); challengeFileComponent.ChallengeFile.Created = DateTime.Now; challengeFileComponent.ChallengeFile.Updated = challengeFileComponent.ChallengeFile.Created; challengeFileComponent.ChallengeFile.ObjectName = txtFileName.Text; challengeFileComponent.ChallengeFile.ObjectType = ddCategory.SelectedItem.Text; challengeFileComponent.ChallengeFile.Size = FileSize; challengeFileComponent.ChallengeFile.ObjectExtension = ExtensionName; challengeFileComponent.ChallengeFile.Language = Language; challengeFileComponent.ChallengeFile.ChallengeReferenceId = ChallengeReference; try { string pathServer = Server.MapPath(ddCategory.SelectedValue); string sourceFile = System.IO.Path.Combine(pathServerTemp, FileName + ExtensionName); string destFile = System.IO.Path.Combine(pathServer, ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false)); if (!Directory.Exists(pathServer)) { Directory.CreateDirectory(pathServer); } if (System.IO.File.Exists(sourceFile)) { if (!System.IO.File.Exists(destFile)) { System.IO.File.Move(sourceFile, destFile); } else { System.IO.File.Delete(destFile); System.IO.File.Move(sourceFile, destFile); } } //Save document information in the database challengeFileComponent.ChallengeFile.ObjectLocation = ddCategory.SelectedValue + ValidateSecurity.ValidateString(txtFileName.Text, false) + ValidateSecurity.ValidateString(lblExtension.Text, false); challengeFileComponent.Save(); } catch { } } else { documentComponent = new DocumentComponent(Guid.NewGuid()); UserPropertyComponent user = new UserPropertyComponent(UserId); documentComponent.Document.Created = DateTime.Now; documentComponent.Document.CreatedBy = UserId; documentComponent.Document.Updated = documentComponent.Document.Created; documentComponent.Document.Views = 0; documentComponent.Document.Version = 1; documentComponent.Document.UploadedBy = user.UserProperty.UserId; documentComponent.Document.Author = string.Empty;// user.UserProperty.FirstName + " " + user.UserProperty.LastName; documentComponent.Document.Name = ValidateSecurity.ValidateString(txtFileName.Text, false); documentComponent.Document.Title = ValidateSecurity.ValidateString(txtTitle.Text, false); documentComponent.Document.FileType = ExtensionName; documentComponent.Document.Deleted = false; documentComponent.Document.Description = ValidateSecurity.ValidateString(txtDescription.Text, false); documentComponent.Document.Size = FileSize; documentComponent.Document.Permission = "0"; documentComponent.Document.Scope = rdbScope.SelectedValue; documentComponent.Document.Status = "published"; documentComponent.Document.Category = ddCategory.SelectedValue; documentComponent.Document.DocumentObject = Bytes; documentComponent.Document.ExternalReference = SolutionId; documentComponent.Document.Folder = Folder; //Save information of the document if (documentComponent.Save() < 0) { throw new Exception(); } if (ExtensionName.ToUpper() == ".PDF") { GhostscriptWrapper.GeneratePageThumb(pathServerTemp + FileName + ExtensionName, pathServerThumbImages + "pdf-" + documentComponent.Document.DocumentId.ToString() + ".jpg", 1, 150, 150, 300, 300); } } FillDataRepeater(); WizardFile.ActiveStepIndex = 0; } catch (Exception exc) { Exceptions. ProcessModuleLoadException( this, exc); } }
public async Task <ActionResult> PDFtoImage(string fileurl, int maxWidth) { string websitePath = ConfigurationManager.AppSettings["portalPath"]; string LogFilePath = ConfigurationManager.AppSettings["logFilePath"]; var sr = new StreamWriter(LogFilePath + "pdfToImage.log"); string timestampedPDF = "error.pdf"; sr.AutoFlush = true; string outwardPath = ""; string currentPDFPath = ""; List <string> PathedArray = new List <string>(); try { sr.WriteLine("fileurl = " + fileurl); sr.WriteLine("beforeInput"); string inputPath = ConfigurationManager.AppSettings["pdfUploadSpot"] + @"\" + fileurl; sr.WriteLine("beforeoutput"); string filename = "tempImage" + UniqueNames.GetTimestamp(DateTime.Now) + ".jpg"; string outputPath = ConfigurationManager.AppSettings["pdfUploadSpot"] + @"\tempPics\" + filename; sr.WriteLine("inputpath = " + inputPath); sr.WriteLine("outputpath = " + outputPath); List <string> outwardPaths = new List <string>(); for (int i = 1; i < 4; i++) { outputPath = outputPath.Replace(".jpg", i + ".jpg"); GhostscriptWrapper.GeneratePageThumb(inputPath, outputPath, i, 120, 120); if (!System.IO.File.Exists(outputPath)) { break; } outwardPaths.Add(outputPath); } foreach (var path in outwardPaths) { ScaleImage(path, maxWidth, 3000); string newPath = path.Substring(path.LastIndexOf('\\') + 1); newPath = ConfigurationManager.AppSettings["portalPath"] + @"/pdfs/gettemppic/" + newPath; PathedArray.Add(newPath); } currentPDFPath = inputPath; timestampedPDF = DateTime.Now.GetTimestamp() + fileurl; string archivePath = ConfigurationManager.AppSettings["pdfArchive"] + @"\PDFs\" + timestampedPDF; //PDFParser parser = new PDFParser(); //string result = parser.ExtractText(currentPDFPath); //moving file sr.WriteLine("Current PDF Path:" + currentPDFPath); sr.WriteLine("Archive PDF Path:" + archivePath); //System.IO.File.Move(currentPDFPath, archivePath); } catch (Exception e) { sr.WriteLine("message = " + e.Message); sr.WriteLine("stacktrace = " + e.StackTrace); } sr.Close(); Task.Factory.StartNew(() => { UploadPDFToAzure(currentPDFPath, timestampedPDF); }); return(Json(new { PathedArray, timestampedPDF })); }