private void ConvertToPdf(string fileIN, string fileOUT) { //string projectDir = Server.MapPath("~/"); NameValueCollection commonLoggingproperties = new NameValueCollection(); commonLoggingproperties["showDateTime"] = "false"; commonLoggingproperties["level"] = "INFO"; Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties); Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger(); log.Info("Hello from Common Logging"); // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs ikvm.runtime.Startup.addBootClassPathAssembly( System.Reflection.Assembly.GetAssembly( typeof(org.slf4j.impl.StaticLoggerBinder))); // Configure to find docx4j.properties // .. add as URL the dir containing docx4j.properties (not the file itself!) Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(Server.MapPath("~/src/samples/resources/")); //org.docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart.getTemporaryEmbeddedFontsDir() // OK, do it.. org.docx4j.openpackaging.packages.WordprocessingMLPackage wordMLPackage = org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(new java.io.File(fileIN)); java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File(fileOUT)); org.docx4j.Docx4J.toPDF(wordMLPackage, fos); fos.close(); }
private void UnzipFile(string zipFileName) { try { string fileName; fileName = "EQ" + dateTimePicker1.Value.Day.ToString("00") + dateTimePicker1.Value.Month.ToString("00") + dateTimePicker1.Value.Year.ToString().Replace("20", "") + ".CSV";; sbyte[] buf = new sbyte[1024]; int len; //filename = "EQ" + dateTimePicker1.Value.Day.ToString("00") + dateTimePicker1.Value.Month.ToString("00") + dateTimePicker1.Value.Year.ToString("00") + ".csv" ; //filename = filename.Replace("zip", "CSV"); java.io.FileInputStream fis = new java.io.FileInputStream(zipFileName); java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(fis); java.util.zip.ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { if (fileName == ze.getName()) { // File name format in zip file is: // folder/subfolder/filename // Let's check... int index = fileName.LastIndexOf('/'); if (index > 1) { string folder = fileName.Substring(0, index); DirectoryInfo di = new DirectoryInfo(folder); // Create directory if not exists if (!di.Exists) { di.Create(); } } java.io.FileOutputStream fos = new java.io.FileOutputStream(fileName); while ((len = zis.read(buf)) >= 0) { fos.write(buf, 0, len); } fos.close(); } } zis.close(); fis.close(); } catch (Exception ex) { MessageBox.Show("Error" + ex.Message.ToString()); } finally { // Close everything } }
static void Main(string[] args) { string projectDir = System.IO.Directory.GetParent( System.IO.Directory.GetParent( Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\"; string fileIN = projectDir + @"src\samples\resources\sample-docx.docx"; string fileOUT = projectDir + @"OUT\sample-docx2.html"; string imageDirPath = projectDir + @"OUT\sample-docx2_files"; System.IO.Directory.CreateDirectory(projectDir + "OUT"); System.IO.Directory.CreateDirectory(imageDirPath); string imageTargetUri = imageDirPath; // Programmatically configure Common Logging // (alternatively, you could do it declaratively in app.config) NameValueCollection commonLoggingproperties = new NameValueCollection(); commonLoggingproperties["showDateTime"] = "false"; commonLoggingproperties["level"] = "INFO"; LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties); ILog log = LogManager.GetCurrentClassLogger(); log.Info("Hello from Common Logging" ); // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs ikvm.runtime.Startup.addBootClassPathAssembly( System.Reflection.Assembly.GetAssembly( typeof(org.slf4j.impl.StaticLoggerBinder))); // Configure to find docx4j.properties // .. add as URL the dir containing docx4j.properties (not the file itself!) Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir +@"src\samples\resources\"); // OK, do it.. WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(new java.io.File(fileIN)); java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File(fileOUT)); org.docx4j.Docx4J.toHTML(wordMLPackage, imageDirPath, imageTargetUri, fos); fos.close(); Console.WriteLine("done!"); }
static void Main(string[] args) { string projectDir = System.IO.Directory.GetParent( System.IO.Directory.GetParent( Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\"; string fileIN = projectDir + @"src\samples\resources\sample-docx.docx"; string fileOUT = projectDir + @"OUT\sample-docx2.html"; string imageDirPath = projectDir + @"OUT\sample-docx2_files"; System.IO.Directory.CreateDirectory(projectDir + "OUT"); System.IO.Directory.CreateDirectory(imageDirPath); string imageTargetUri = imageDirPath; // Programmatically configure Common Logging // (alternatively, you could do it declaratively in app.config) NameValueCollection commonLoggingproperties = new NameValueCollection(); commonLoggingproperties["showDateTime"] = "false"; commonLoggingproperties["level"] = "INFO"; LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties); ILog log = LogManager.GetCurrentClassLogger(); log.Info("Hello from Common Logging"); // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs ikvm.runtime.Startup.addBootClassPathAssembly( System.Reflection.Assembly.GetAssembly( typeof(org.slf4j.impl.StaticLoggerBinder))); // Configure to find docx4j.properties // .. add as URL the dir containing docx4j.properties (not the file itself!) Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir + @"src\samples\resources\"); // OK, do it.. WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(new java.io.File(fileIN)); java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File(fileOUT)); org.docx4j.Docx4J.toHTML(wordMLPackage, imageDirPath, imageTargetUri, fos); fos.close(); Console.WriteLine("done!"); }
public static bool writeObjectToFile(string fileName, object obj) { try { java.io.File f = new java.io.File(fileName); f.setWritable(true); java.io.FileOutputStream fout = new java.io.FileOutputStream(f); java.io.ObjectOutputStream oo = new java.io.ObjectOutputStream(fout); oo.writeObject(obj); fout.close(); return(true); } catch (System.Exception) { return(false); } }
/// <summary> /// AUTHOR: Ashok Kolwal /// COMPANY: VITRANA /// Version: 1.0 /// Description: The IDfSysObject.getContent() command lets you get the contents of a document as a ByteArrayInputStream /// Last Modified date: 11 Jul,2017 /// </summary> /// <param name="sessionManager"></param> /// <param name="repositoryName"></param> /// <param name="objectIdString"></param> /// <returns></returns> public bool GetContent(IDfSessionManager sessionManager, String repositoryName, String objectIdString, String outputFolderPath) { IDfSession mySession = null; bool result = false; try { mySession = sessionManager.getSession(repositoryName); // Get the object ID based on the object ID string. IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + objectIdString + "'"); // Instantiate an object from the ID. IDfSysObject sysObj = (IDfSysObject)mySession.getObject(idObj); // This is file output path plus file name. string fileFullPath = string.Concat(outputFolderPath, "\\", sysObj.getObjectName(), ".", sysObj.getContentType()); java.io.ByteArrayInputStream inputByteStrm = sysObj.getContent(); java.io.InputStream inputStrm = inputByteStrm; java.io.OutputStream outputStrm = new java.io.FileOutputStream(fileFullPath); // Transfer bytes from in to out byte[] byteArry = new byte[30720]; int len = 0; while ((len = inputStrm.read(byteArry)) > 0) { outputStrm.write(byteArry, 0, len); } inputStrm.close(); outputStrm.close(); result = true; // Console.WriteLine("Document has been exported with Name: " + Path.GetFileName(fileFullPath)); } // Handle any exceptions. catch (Exception ex) { // Console.WriteLine(ex.Message); throw new Exception("[GetContent] Error: " + ex.Message, ex); } // Always, always, release the session in the "finally" clause. finally { sessionManager.release(mySession); } return(result); }
/// <summary> /// Extract the first file from a Zip file in the form of a byte array /// </summary> /// <param name="ba"></param> /// <param name="outputFile"></param> public static void ExtractFirstFile( byte[] ba, string outputFile) { string tempZipFile = TempFile.GetTempFileName(); // temp file for zip file FileStream fs = new FileStream(tempZipFile, FileMode.Create); fs.Write(ba, 0, ba.Length); fs.Close(); ZipFile currentFile = new ZipFile(tempZipFile); foreach (ZipEntry entry in new EnumerationAdapter(new EnumerationMethod(currentFile.entries))) { // extract first file from the .zip file if (entry.isDirectory()) { continue; } java.io.InputStream s = currentFile.getInputStream(entry); try { java.io.FileOutputStream dest = new java.io.FileOutputStream(outputFile); try { ZipUtils.CopyStream(s, dest); } finally { dest.close(); } } finally { s.close(); FileUtil.DeleteFile(tempZipFile); } break; } }
static void Main(string[] args) { // set up logging clog = LoggingConfigurator.configureLogging(); clog.Info("Hello from Common Logging"); string projectDir = System.IO.Directory.GetParent( System.IO.Directory.GetParent( Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\"; string fileIN = projectDir + @"src\samples\resources\sample-docx.docx"; string fileOUT = projectDir + @"OUT\sample-docx2.html"; string imageDirPath = projectDir + @"OUT\sample-docx2_files"; System.IO.Directory.CreateDirectory(projectDir + "OUT"); System.IO.Directory.CreateDirectory(imageDirPath); string imageTargetUri = imageDirPath; // Configure to find docx4j.properties // .. add as URL the dir containing docx4j.properties (not the file itself!) Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir +@"src\samples\resources\"); // OK, do it.. WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(new java.io.File(fileIN)); java.io.FileOutputStream fos = new java.io.FileOutputStream(new java.io.File(fileOUT)); org.docx4j.Docx4J.toHTML(wordMLPackage, imageDirPath, imageTargetUri, fos); fos.close(); Console.WriteLine("done!"); }
/// <summary> /// Extract files from a ZipFile to a file folder /// </summary> /// <param name="file"></param> /// <param name="path"></param> /// <param name="filter"></param> public static void ExtractZipFile( ZipFile file, string path, FilterEntryMethod filter = null) { foreach (ZipEntry entry in new EnumerationAdapter(new EnumerationMethod(file.entries))) { if (!entry.isDirectory()) { if ((filter == null || filter(entry))) { java.io.InputStream s = file.getInputStream(entry); try { string fname = System.IO.Path.GetFileName(entry.getName()); string newpath = System.IO.Path.Combine(path, System.IO.Path.GetDirectoryName(entry.getName())); System.IO.Directory.CreateDirectory(newpath); java.io.FileOutputStream dest = new java.io.FileOutputStream(System.IO.Path.Combine(newpath, fname)); try { CopyStream(s, dest); } finally { dest.close(); } } finally { s.close(); } } } } }
private void CreateUeBF(string putanjaDoKnjige) { java.io.FileOutputStream fos = new java.io.FileOutputStream(putanjaDoKnjige); java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(fos); string[] priv = path.Substring(3).Replace('\\', '/').Split('/'); AddToZip(fos, zos, path, priv[priv.Length - 1]); saveMeta(fos, zos); /* if (path.Contains("pdf")) { CreateSWF(path); string swfPath = Application.StartupPath + "\\" + isbn + ".swf"; while (!File.Exists(swfPath)) { Thread.Sleep(2000); }; AddToZip(fos, zos, swfPath, isbn + ".swf"); System.IO.File.Delete(swfPath); } */ zos.close(); fos.close(); }