本文整理汇总了C#中Document.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Close方法的具体用法?C# Document.Close怎么用?C# Document.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCreatePdfA_2
virtual public void TestCreatePdfA_2()
{
bool exceptionThrown = false;
Document document;
PdfAWriter writer;
try
{
string filename = OUT + "TestCreatePdfA_1.pdf";
FileStream fos = new FileStream(filename, FileMode.Create);
document = new Document();
writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1A);
writer.CreateXmpMetadata();
document.Open();
Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 12, Font.BOLD);
document.Add(new Paragraph("Hello World", font));
FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
iccProfileFileStream.Close();
writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
document.Close();
}
catch (PdfAConformanceException)
{
exceptionThrown = true;
}
if (!exceptionThrown)
Assert.Fail("PdfAConformance exception should be thrown");
}
示例2: buttonMerge_Click
private void buttonMerge_Click(object sender, RoutedEventArgs e)
{
//new Document
Document doc = new Document();
doc.LoadFromFile(@"..\..\..\..\..\Data\Fax.doc");
String[] fieldNames
= new String[] { "Contact Name", "Fax", "From", "Date", "Subject", "Content" };
DateTime faxDate
= this.datePickerFaxDate.SelectedDate.HasValue ?
this.datePickerFaxDate.SelectedDate.Value : DateTime.Now;
String[] fieldValues
= new String[]
{
this.textBoxTo.Text,
this.textBoxFax.Text,
this.textBoxFrom.Text,
faxDate.ToShortDateString(),
this.textBoxSubject.Text,
this.textBoxContent.Text
};
doc.MailMerge.Execute(fieldNames, fieldValues);
bool? result = this.saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
{
using (Stream stream = this.saveFileDialog.OpenFile())
{
doc.SaveToStream(stream, FileFormat.Doc);
doc.Close();
}
}
}
示例3: ExtractTextFromImage
/// <summary>
/// Reason : To get Text from image
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public string ExtractTextFromImage(string fileName)
{
try
{
GC.WaitForPendingFinalizers();
string ExtractedTest = "";
string filePath = fileName.Trim() != "" ? @fileName : @"C:\Users\Cuelogic\Desktop\sample images\Untitled.png";
Document doc = new Document();
doc.Create(filePath);
Thread.Sleep(500);
try
{
Thread.BeginCriticalRegion();
doc.OCR(MiLANGUAGES.miLANG_ENGLISH, true, true);
}
catch (Exception) { return ""; }
MODI.Image modiImage = (doc.Images[0] as MODI.Image);
ExtractedTest = modiImage.Layout.Text;
doc.Close();
Thread.EndCriticalRegion();
return ExtractedTest;
}
catch (Exception)
{
return "";
}
finally
{
GC.Collect();
}
}
示例4: ExtractTextFromImage
/// <summary>
/// Reason : To get Text from image
/// </summary>
/// <param name="fileName">Input file name</param>
/// <returns>Return Text from image</returns>
public string ExtractTextFromImage(string fileName)
{
try
{
if (fileName.Trim() == "")
return "File name can not be null";
string ExtractedTest = "";
Document doc = new Document();
GC.WaitForPendingFinalizers();
doc.Create(fileName);
Thread.Sleep(500);
try
{
Thread.BeginCriticalRegion();
doc.OCR(MiLANGUAGES.miLANG_ENGLISH, true, true);
}
catch (Exception) { return ""; }
MODI.Image modiImage = (doc.Images[0] as MODI.Image);
ExtractedTest = modiImage.Layout.Text;
doc.Close();
Thread.EndCriticalRegion();
return ExtractedTest;
}
catch (Exception)
{
return "";
}
finally
{
GC.Collect();
}
}
示例5: Read
public override string Read(FileInfo fileInfo)
{
object nullobj = System.Reflection.Missing.Value;
object readOnly = true;
object noEncodingDialog = true;
object confirmConversions = false;
object visible = false;
object filePath = fileInfo.FullName;
object openAndRepair = false;
object openFormat = WdOpenFormat.wdOpenFormatAuto;
_wordDoc = WordApp.Documents.Open(
ref filePath, ref confirmConversions, ref readOnly, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref openFormat,
ref nullobj, ref visible, ref openAndRepair, ref nullobj, ref noEncodingDialog,
ref nullobj);
// Make this document the active document.
_wordDoc.Activate();
string result = WordApp.ActiveDocument.Content.Text;
_wordDoc.Close(ref nullobj, ref nullobj, ref nullobj);
return result;
}
示例6: MetadaCheckTest
public void MetadaCheckTest() {
FileStream fos = new FileStream(OUT + "metadaPDFA2CheckTest1.pdf", FileMode.Create);
Document document = new Document();
PdfWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_2B);
document.Open();
PdfContentByte canvas = writer.DirectContent;
canvas.SetColorFill(BaseColor.LIGHT_GRAY);
canvas.MoveTo(writer.PageSize.Left, writer.PageSize.Bottom);
canvas.LineTo(writer.PageSize.Right, writer.PageSize.Bottom);
canvas.LineTo(writer.PageSize.Right, writer.PageSize.Top);
canvas.LineTo(writer.PageSize.Left, writer.PageSize.Bottom);
canvas.Fill();
FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
iccProfileFileStream.Close();
writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
bool exceptionThrown = false;
try {
document.Close();
}
catch (PdfAConformanceException exc) {
exceptionThrown = true;
}
if (!exceptionThrown)
Assert.Fail("PdfAConformance exception should be thrown on unknown blend mode.");
}
示例7: Document_Class
public Document_Class()
{
_doc = _DocApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
foreach (Microsoft.Office.Interop.Word.Section section in _doc.Sections)
{
Range headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
headerRange.Font.ColorIndex = WdColorIndex.wdBlue;
headerRange.Font.Size = 10;
headerRange.Text = "TEST";
}
foreach (Microsoft.Office.Interop.Word.Section wordSection in _doc.Sections)
{
Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed;
footerRange.Font.Size = 10;
footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
footerRange.Text = "Footer TEST";
}
_doc.Content.SetRange(0, 0);
_doc.Content.Text = "Text TEST";
object filename = @"c:\temp1.docx";
_doc.SaveAs2(ref filename);
_doc.Close(ref missing, ref missing, ref missing);
_doc = null;
_DocApp.Quit(ref missing, ref missing, ref missing);
_DocApp = null;
//MessageBox.Show("Document created successfully !");
}
示例8: btnCreatePDF_Click
protected void btnCreatePDF_Click(object sender, EventArgs e)
{
// create a PDF document
Document document = new Document();
// set the license key
document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE=";
// add a page to the PDF document
PdfPage firstPage = document.AddPage();
string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), "Images");
// display image in the available space in page and with a auto determined height to keep the aspect ratio
ImageElement imageElement1 = new ImageElement(0, 0, System.IO.Path.Combine(imagesPath, "evologo-250.png"));
AddElementResult addResult = firstPage.AddElement(imageElement1);
// display image with the specified width and the height auto determined to keep the aspect ratio
// the images is displayed to the right of the previous image and the bounds of the image inside the current page
// are taken from the AddElementResult object
ImageElement imageElement2 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100,
System.IO.Path.Combine(imagesPath, "evologo-250.png"));
addResult = firstPage.AddElement(imageElement2);
// Display image with the specified width and the specified height. It is possible for the image to not preserve the aspect ratio
// The images is displayed to the right of the previous image and the bounds of the image inside the current page
// are taken from the AddElementResult object
ImageElement imageElement3 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100, 50,
System.IO.Path.Combine(imagesPath, "evologo-250.png"));
addResult = firstPage.AddElement(imageElement3);
try
{
// get the PDF document bytes
byte[] pdfBytes = document.Save();
// send the generated PDF document to client browser
// get the object representing the HTTP response to browser
HttpResponse httpResponse = HttpContext.Current.Response;
// add the Content-Type and Content-Disposition HTTP headers
httpResponse.AddHeader("Content-Type", "application/pdf");
httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=ImageElement.pdf; size={0}", pdfBytes.Length.ToString()));
// write the PDF document bytes as attachment to HTTP response
httpResponse.BinaryWrite(pdfBytes);
// Note: it is important to end the response, otherwise the ASP.NET
// web page will render its content to PDF document stream
httpResponse.End();
}
finally
{
// close the PDF document to release the resources
document.Close();
}
}
示例9: ExtractTextFromImage
private string ExtractTextFromImage(string filePath)
{
Document modiDocument = new Document();
modiDocument.Create(filePath);
modiDocument.OCR(MiLANGUAGES.miLANG_ENGLISH);
MODI.Image modiImage = (modiDocument.Images[0] as MODI.Image);
string extractedText = modiImage.Layout.Text;
modiDocument.Close();
return extractedText;
}
示例10: Parse
public void Parse(object src, object dest)
{
if (src == null || string.IsNullOrEmpty(src.ToString()))
{
throw new ArgumentNullException("源文件不能为空");
}
if (dest == null || string.IsNullOrEmpty(dest.ToString()))
{
throw new ArgumentNullException("目标路径不能为空");
}
try
{
doc = wordApp.Documents.Open(ref src, ref paraMissing, ref paraMissing
, ref paraMissing, ref paraMissing
, ref paraMissing, ref paraMissing
, ref paraMissing, ref paraMissing, ref paraMissing, ref paraMissing
, ref paraMissing, ref paraMissing, ref paraMissing, ref paraMissing
, ref paraMissing);
int startPage = 0;
int endPage = doc.ComputeStatistics(WdStatistic.wdStatisticPages, ref paraMissing);
if (doc != null)
{
doc.ExportAsFixedFormat(dest.ToString(), WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForOnScreen
, WdExportRange.wdExportAllDocument, startPage, endPage, WdExportItem.wdExportDocumentWithMarkup,
true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, true, ref paraMissing);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (doc != null)
{
doc.Close(ref paraMissing, ref paraMissing, ref paraMissing);
doc = null;
}
if (wordApp != null)
{
wordApp.Quit(ref paraMissing, ref paraMissing, ref paraMissing);
wordApp = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例11: ToCht
public string ToCht(string chs)
{
var doc = new Document();
doc.Content.Text = chs;
doc.Content.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
string des = doc.Content.Text;
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
GC.Collect();
return des;
}
示例12: ConvertUsingWord
///
/// 使用 Office Word (Microsoft.Office.Interop.Word) 進行轉換
///
public static string ConvertUsingWord(string argSource, bool argIsCht)
{
var doc = new Document();
doc.Content.Text = argSource;
doc.Content.TCSCConverter(
argIsCht
? WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC
: WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
var ret = doc.Content.Text;
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
return ret;
}
示例13: FileTrailer
virtual public void FileTrailer()
{
MemoryStream baos = new MemoryStream();
Document document = new Document();
PdfWriter.GetInstance(document, baos);
document.Open();
document.Add(new Chunk("Hello World"));
document.Close();
byte[] bytes = baos.ToArray();
String str = Encoding.UTF8.GetString(bytes, bytes.Length - 6, 6);
Assert.AreEqual("%%EOF\n", str);
PdfReader reader = new PdfReader(baos.ToArray());
Assert.IsNotNull(reader.Trailer.Get(PdfName.ID));
reader.Close();
}
示例14: FileHeader
virtual public void FileHeader()
{
MemoryStream baos = new MemoryStream();
Document document = new Document();
PdfWriter.GetInstance(document, baos);
document.Open();
document.Add(new Chunk("Hello World"));
document.Close();
byte[] bytes = baos.ToArray();
Assert.AreEqual(bytes[0], '%');
Assert.IsTrue((sbyte)bytes[10] < 0);
Assert.IsTrue((sbyte)bytes[11] < 0);
Assert.IsTrue((sbyte)bytes[12] < 0);
Assert.IsTrue((sbyte)bytes[13] < 0);
}
示例15: ImageOCR
public ImageOCR(string filename)
{
_filename = filename;
ConvertToTiffIfNeeded();
_modi = new Document();
try
{
_modi.Create(_filename);
_modi.OCR(MiLANGUAGES.miLANG_SYSDEFAULT, true, true);
GetWords();
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
_modi.Close(false);
_modi = null;
}
}