/// <summary> SPIRE_JPEG 左上角有水印 /// 分辨率:1280x 720 /// </summary> /// <param name="filepath"></param> /// <param name="outputPath"></param> /// <returns></returns> List <PPTPage> spirePDF(string filepath, string outputPath) { List <PPTPage> pages = new List <PPTPage>(); Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(filepath); int pageCount = doc.Pages.Count; int width = (int)doc.PageSettings.Width; int height = (int)doc.PageSettings.Height; for (int i = 0; i < pageCount;) { string path = string.Format("{0}/img-{1}.jpeg", outputPath, i); System.Drawing.Image img = doc.SaveAsImage(i); img.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); pages.Add(new PPTPage() { Cover = path }); Console.WriteLine("PDF TO IMAGES - {0}/{1}", ++i, pageCount); } return(pages); }
void PdftoIMG(string pdfpath) { Spire.Pdf.PdfDocument pdfdocument = new Spire.Pdf.PdfDocument(); pdfdocument.LoadFromFile(pdfpath); System.Drawing.Image image = pdfdocument.SaveAsImage(0, 96, 96); image.Save(string.Format(Server.MapPath("~/Images/UIDimage/New.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)); }
public String ConvertPdfToImage(imgformat img, String Route) { string dataDir = Server.MapPath(Route); ////string[] extensions = { ".jpg", ".txt", ".asp", ".css", ".cs", ".xml" }; string[] extensions = { ".pdf" }; String Outfilename = String.Empty; String FinalSaveJPG = String.Empty; try { ////////////// String[] FilesPath = Directory.GetFiles(dataDir, "*.*") ////////////// .Where(f => extensions.Contains(new FileInfo(f).Extension.ToLower())).ToArray(); FileInfo[] FilesPathArray = new DirectoryInfo(dataDir).GetFiles() .OrderBy(f => f.LastWriteTime) .ToArray(); int FilesCount = FilesPathArray.Length; for (int i = 0; i < FilesCount; i++) { Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(); //doc.LoadFromFile(FilesPath[i]); String kookoko = (String.Format("{0}\\{1}", dataDir, FilesPathArray[i])); doc.LoadFromFile(String.Format("{0}\\{1}", dataDir, FilesPathArray[i])); System.Drawing.Image bmp = doc.SaveAsImage(0); System.Drawing.Image emf = doc.SaveAsImage(0, Spire.Pdf.Graphics.PdfImageType.Metafile); System.Drawing.Image zoomImg = new System.Drawing.Bitmap((int)(emf.Size.Width * 2), (int)(emf.Size.Height * 2)); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(zoomImg)) { g.ScaleTransform(2.0f, 2.0f); g.DrawImage(emf, new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), emf.Size), new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), emf.Size), System.Drawing.GraphicsUnit.Pixel); } Outfilename = fileName.Replace(".pdf", ""); FinalSaveJPG = String.Format("{0}\\{1}\\{2}", rootPath, AssignedFolder, IMGexportedPath); fn.CreateFolderUpload(FinalSaveJPG); switch (img) { case imgformat.jpg: zoomImg.Save(Server.MapPath(String.Format("{0}\\{1}[{2}].jpg", FinalSaveJPG, i, Outfilename)), ImageFormat.Jpeg); break; case imgformat.bmp: zoomImg.Save(Server.MapPath(String.Format("{0}\\{1}[{2}].bmp", FinalSaveJPG, i, Outfilename)), ImageFormat.Bmp); break; case imgformat.png: zoomImg.Save(Server.MapPath(String.Format("{0}\\{1}[{2}].png", FinalSaveJPG, i, Outfilename)), ImageFormat.Png); break; case imgformat.tiff: zoomImg.Save(Server.MapPath(String.Format("{0}\\{1}[{2}].tiff", FinalSaveJPG, i, Outfilename)), ImageFormat.Tiff); break; } } return(FinalSaveJPG); } catch (Exception) { return(null); } #region comenteed //String aaa = "asddasdasmkld"; //emf.Save(Server.MapPath(rootPathUpload)+ @"\" + "convertToBmp.jpg", ImageFormat.Jpeg); //emf.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToBmp.bmp", ImageFormat.Bmp); ////System.Diagnostics.Process.Start("convertToBmp.bmp"); //emf.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToEmf.png", ImageFormat.Png); //System.Diagnostics.Process.Start("convertToEmf.png"); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Tiff); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Wmf); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Exif); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Gif); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Icon); //zoomImg.Save(Server.MapPath(rootPathUpload) + @"\" + "convertToZoom.png", ImageFormat.Wmf); //System.Diagnostics.Process.Start("convertToZoom.png"); /////return ""; #endregion }