private static bool CanCompineFiles(HttpPostedFileBase[] UploadedFiles, out byte[] Result, out string contentType) { contentType = string.Empty; Result = null; try { if (UploadedFiles == null) { return(false); } if (UploadedFiles.Count() == 1 /*!Images[0].ContentType.Contains("doc")*/) { Constants.Enumerations.UploadFileTypesEnum FileType = GetFileType(UploadedFiles[0]); if (FileType == Constants.Enumerations.UploadFileTypesEnum.Pdf || FileType == Constants.Enumerations.UploadFileTypesEnum.Image) { contentType = UploadedFiles[0].ContentType.Replace("application/octet-stream", "image/jpeg"); Result = ImageProcesses.ReadFully(UploadedFiles[0].InputStream); return(false); } } return(true); } catch { return(false); } }
public static void CompinePDFFiles(bool ImagePDFDocumentCreated, string FullPath, string FullPath_ImagePDF, HttpPostedFileBase[] Images, Random Rnd_FileNames, string Dirpath, List <string> AllCurrentFiles) { using (FileStream stream_FinalFile = new FileStream(FullPath, FileMode.OpenOrCreate)) { Document pdfDoc = new Document(); PdfCopy pdf = new PdfCopy(pdfDoc, stream_FinalFile); pdfDoc.Open(); if (ImagePDFDocumentCreated) { pdf.AddDocument(new PdfReader(FullPath_ImagePDF)); } foreach (var im in Images) { Constants.Enumerations.UploadFileTypesEnum FileType = GetFileType(im); switch (FileType) { case Constants.Enumerations.UploadFileTypesEnum.Pdf: pdf.AddDocument(new PdfReader(im.InputStream)); break; //case Constants.Enumerations.UploadFileTypesEnum.Word: // string RandomFName = GetRandomFileName(Rnd_FileNames); // string CurrentWordRandomFileName = RandomFName + Path.GetExtension(im.FileName); // string NewPdfRandomFileName = RandomFName + ".pdf"; // string CurrentWordFullPath = Dirpath + @"\" + CurrentWordRandomFileName; // string NewPdfFullPath = Dirpath + @"\" + NewPdfRandomFileName; // CovertWordToPDF(im, CurrentWordFullPath, NewPdfFullPath); // AllCurrentFiles.Add(CurrentWordRandomFileName); // AllCurrentFiles.Add(NewPdfRandomFileName); // pdf.AddDocument(new PdfReader(NewPdfFullPath)); // break; default: break; } } pdfDoc.Close(); } }