175 lines
6.9 KiB
C#
175 lines
6.9 KiB
C#
/*
|
|
* (c) Copyright Ascensio System SIA 2010-2023
|
|
*
|
|
* This program is a free software product. You can redistribute it and/or
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
* of any third-party rights.
|
|
*
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
|
* street, Riga, Latvia, EU, LV-1050.
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
*
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
* well as technical writing content are licensed under the terms of the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
//using Microsoft.Office.Interop.Word;
|
|
|
|
namespace WindowsFormsApplication1
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
|
|
/*
|
|
object paramSourceDocPath = @"C:\Users\Oleg.Korshul\Downloads\eu.docx";
|
|
string paramExportFilePath = @"C:\DEST\Test.pdf";
|
|
WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
|
|
bool paramOpenAfterExport = false;
|
|
WdExportOptimizeFor paramExportOptimizeFor =
|
|
WdExportOptimizeFor.wdExportOptimizeForOnScreen;
|
|
WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
|
|
int paramStartPage = 0;
|
|
int paramEndPage = 0;
|
|
WdExportItem paramExportItem = WdExportItem.wdExportDocumentWithMarkup;
|
|
bool paramIncludeDocProps = true;
|
|
bool paramKeepIRM = true;
|
|
WdExportCreateBookmarks paramCreateBookmarks =
|
|
WdExportCreateBookmarks.wdExportCreateWordBookmarks;
|
|
bool paramDocStructureTags = true;
|
|
bool paramBitmapMissingFonts = true;
|
|
bool paramUseISO19005_1 = false;
|
|
object paramMissing = Type.Missing;
|
|
|
|
ApplicationClass wordApplication = new ApplicationClass();
|
|
Document wordDocument = null;
|
|
|
|
try
|
|
{
|
|
// Open the source document.
|
|
wordDocument = wordApplication.Documents.Open(
|
|
ref paramSourceDocPath, ref paramMissing, ref paramMissing,
|
|
ref paramMissing, ref paramMissing, ref paramMissing,
|
|
ref paramMissing, ref paramMissing, ref paramMissing,
|
|
ref paramMissing, ref paramMissing, ref paramMissing,
|
|
ref paramMissing, ref paramMissing, ref paramMissing,
|
|
ref paramMissing);
|
|
|
|
// Export it in the specified format.
|
|
if (wordDocument != null)
|
|
wordDocument.ExportAsFixedFormat(paramExportFilePath,
|
|
paramExportFormat, paramOpenAfterExport,
|
|
paramExportOptimizeFor, paramExportRange, paramStartPage,
|
|
paramEndPage, paramExportItem, paramIncludeDocProps,
|
|
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
|
|
paramBitmapMissingFonts, paramUseISO19005_1,
|
|
ref paramMissing);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Respond to the error
|
|
}
|
|
finally
|
|
{
|
|
// Close and release the Document object.
|
|
if (wordDocument != null)
|
|
{
|
|
wordDocument.Close(ref paramMissing, ref paramMissing,
|
|
ref paramMissing);
|
|
wordDocument = null;
|
|
}
|
|
|
|
// Quit Word and release the ApplicationClass object.
|
|
if (wordApplication != null)
|
|
{
|
|
wordApplication.Quit(ref paramMissing, ref paramMissing,
|
|
ref paramMissing);
|
|
wordApplication = null;
|
|
}
|
|
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
}
|
|
*/
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (openFileDialog1.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
textBox1.Text = openFileDialog1.FileName;
|
|
|
|
using (FileStream fsSource = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read))
|
|
{
|
|
// Read the source file into a byte array.
|
|
byte[] bytes = new byte[fsSource.Length];
|
|
int numBytesToRead = (int)fsSource.Length;
|
|
int numBytesRead = 0;
|
|
while (numBytesToRead > 0)
|
|
{
|
|
// Read may return anything from 0 to numBytesToRead.
|
|
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);
|
|
|
|
// Break when the end of the file is reached.
|
|
if (n == 0)
|
|
break;
|
|
|
|
numBytesRead += n;
|
|
numBytesToRead -= n;
|
|
}
|
|
numBytesToRead = bytes.Length;
|
|
|
|
//textBox2.Text = Convert.ToBase64String(bytes, Base64FormattingOptions.None);
|
|
string s = "static const unsigned char c_res[" + Convert.ToString(bytes.Length) + "] = {";
|
|
int nLen = bytes.Length;
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
s += Convert.ToString(bytes[i]);
|
|
if (i != (nLen - 1))
|
|
s += ",";
|
|
}
|
|
s += "};";
|
|
textBox2.Text = s;
|
|
}
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
byte[] resBinary = Convert.FromBase64String(textBox2.Text);
|
|
StreamWriter oW = new StreamWriter("E:\\123.bin");
|
|
oW.BaseStream.Write(resBinary, 0, resBinary.Length);
|
|
oW.Close();
|
|
}
|
|
}
|
|
}
|