public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); //open the source PDF document Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf"); // 1. // saving using direct method // save the file into MS document format pdfDocument.Save(dataDir + "simpleOutput.doc", SaveFormat.Doc); // 2. // save using save options // create DocSaveOptions object DocSaveOptions saveOptions = new DocSaveOptions(); // set the recognition mode as Flow saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow; // set the Horizontal proximity as 2.5 saveOptions.RelativeHorizontalProximity = 2.5f; // enable the value to recognize bullets during conversion process saveOptions.RecognizeBullets = true; // save the resultant DOC file pdfDocument.Save(dataDir + "saveOptionsOutput.doc", saveOptions); }
public void UpdateLastPrintedProperty(bool isUpdateLastPrintedProperty) { //ExStart //ExFor:SaveOptions.UpdateLastPrintedProperty //ExSummary:Shows how to update a document's "Last printed" property when saving. Document doc = new Document(); doc.BuiltInDocumentProperties.LastPrinted = new DateTime(2019, 12, 20); // This flag determines whether the last printed date, which is a built-in property, is updated. // If so, then the date of the document's most recent save operation // with this SaveOptions object passed as a parameter is used as the print date. DocSaveOptions saveOptions = new DocSaveOptions(); saveOptions.UpdateLastPrintedProperty = isUpdateLastPrintedProperty; // In Microsoft Word 2003, this property can be found via File -> Properties -> Statistics -> Printed. // It can also be displayed in the document's body by using a PRINTDATE field. doc.Save(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.doc", saveOptions); // Open the saved document, then verify the value of the property. doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.doc"); Assert.AreNotEqual(isUpdateLastPrintedProperty, new DateTime(2019, 12, 20) == doc.BuiltInDocumentProperties.LastPrinted); //ExEnd }
public void AlwaysCompressMetafiles(bool compressAllMetafiles) { //ExStart //ExFor:DocSaveOptions.AlwaysCompressMetafiles //ExSummary:Shows how to change metafiles compression in a document while saving. // Open a document that contains a Microsoft Equation 3.0 formula. Document doc = new Document(MyDir + "Microsoft equation object.docx"); // When we save a document, smaller metafiles are not compressed for performance reasons. // We can set a flag in a SaveOptions object to compress every metafile when saving. // Some editors such as LibreOffice cannot read uncompressed metafiles. DocSaveOptions saveOptions = new DocSaveOptions(); saveOptions.AlwaysCompressMetafiles = compressAllMetafiles; doc.Save(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx", saveOptions); if (compressAllMetafiles) { Assert.That(10000, Is.LessThan(new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length)); } else { Assert.That(30000, Is.AtLeast(new FileInfo(ArtifactsDir + "DocSaveOptions.AlwaysCompressMetafiles.docx").Length)); } //ExEnd }
public void SaveAsDoc() { //ExStart //ExFor:DocSaveOptions //ExFor:DocSaveOptions.#ctor //ExFor:DocSaveOptions.#ctor(SaveFormat) //ExFor:DocSaveOptions.Password //ExFor:DocSaveOptions.SaveFormat //ExFor:DocSaveOptions.SaveRoutingSlip //ExSummary:Shows how to set save options for classic Microsoft Word document versions. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Hello world!"); // DocSaveOptions only applies to Doc and Dot save formats DocSaveOptions options = new DocSaveOptions(SaveFormat.Doc); // Set a password with which the document will be encrypted, and which will be required to open it options.Password = "******"; // If the document contains a routing slip, we can preserve it while saving by setting this flag to true options.SaveRoutingSlip = true; doc.Save(ArtifactsDir + "DocSaveOptions.SaveAsDoc.doc", options); //ExEnd }
public static void SaveUsingSaveOptions() { // ExStart:SaveUsingSaveOptions // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); // Open the source PDF document Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf"); // Save using save options // Create DocSaveOptions object DocSaveOptions saveOptions = new DocSaveOptions(); // Set the recognition mode as Flow saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow; // Set the Horizontal proximity as 2.5 saveOptions.RelativeHorizontalProximity = 2.5f; // Enable the value to recognize bullets during conversion process saveOptions.RecognizeBullets = true; // Save the resultant DOC file pdfDocument.Save(dataDir + "saveOptionsOutput_out.doc", saveOptions); // ExEnd:SaveUsingSaveOptions }
/// <summary>转换为WORD文档</summary> public static void ToDocx(Stream sourceStream, Stream destStream) { using (var pdf = new Document(sourceStream)) { var options = new DocSaveOptions(); options.Format = DocSaveOptions.DocFormat.DocX; pdf.Save(destStream, options); } }
public static void SavePictureBullet(string dataDir) { //ExStart:SavePictureBullet Document doc = new Document(dataDir + "in.doc"); DocSaveOptions saveOptions = (DocSaveOptions)SaveOptions.CreateSaveOptions(SaveFormat.Doc); saveOptions.SavePictureBullet = false; doc.Save(dataDir + "out.doc", saveOptions); //ExEnd:SavePictureBullet Console.WriteLine("\nThe document is saved with SavePictureBullet setting to false. \nFile saved at " + dataDir); }
protected byte[] GetBytes(Document doc) { byte[] bytes; using (MemoryStream ms = new MemoryStream()) { DocSaveOptions opts = new DocSaveOptions(SaveFormat.Doc); doc.Save(ms, opts); bytes = ms.ToArray(); } return(bytes); }
public static void AlwaysCompressMetafiles(string dataDir) { //ExStart:AlwaysCompressMetafiles Document doc = new Document(dataDir + "Document.doc"); DocSaveOptions saveOptions = new DocSaveOptions(); saveOptions.AlwaysCompressMetafiles = false; doc.Save("SmallMetafilesUncompressed.doc", saveOptions); //ExEnd:AlwaysCompressMetafiles Console.WriteLine("\nThe document is saved with AlwaysCompressMetafiles setting to false. \nFile saved at " + dataDir); }
public void DoNotCompressSmallMetafiles() { //ExStart:DoNotCompressSmallMetafiles Document doc = new Document(MyDir + "Microsoft equation object.docx"); DocSaveOptions saveOptions = new DocSaveOptions { AlwaysCompressMetafiles = false }; doc.Save(ArtifactsDir + "WorkingWithDocSaveOptions.NotCompressSmallMetafiles.docx", saveOptions); //ExEnd:DoNotCompressSmallMetafiles }
public void DoNotSavePictureBullet() { //ExStart:DoNotSavePictureBullet Document doc = new Document(MyDir + "Image bullet points.docx"); DocSaveOptions saveOptions = new DocSaveOptions { SavePictureBullet = false }; doc.Save(ArtifactsDir + "WorkingWithDocSaveOptions.DoNotSavePictureBullet.docx", saveOptions); //ExEnd:DoNotSavePictureBullet }
public static void EncryptDocumentWithPassword(string dataDir) { //ExStart:EncryptDocumentWithPassword Document doc = new Document(dataDir + "Document.doc"); DocSaveOptions docSaveOptions = new DocSaveOptions(); docSaveOptions.Password = "******"; dataDir = dataDir + "Document.Password_out.doc"; doc.Save(dataDir, docSaveOptions); //ExEnd:EncryptDocumentWithPassword Console.WriteLine("\nThe password of document is set using RC4 encryption method. \nFile saved at " + dataDir); }
public static void LoadEncryptedDocument() { //Specify decryption password in a new LoadOptions object to open passwrd-encrypted documents var doc = new Document(MailMergeGoblaDocumentSettings.MailMergeOutputFileName, new LoadOptions("password")); //Change the password var saveOptions = new DocSaveOptions { Password = "******" }; //Save a new document with new password doc.Save(MailMergeGoblaDocumentSettings.NewEncryptedDocumentOutputFileName, saveOptions); }
public void EncryptDocumentWithPassword() { //ExStart:EncryptDocumentWithPassword Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Hello world!"); DocSaveOptions saveOptions = new DocSaveOptions { Password = "******" }; doc.Save(ArtifactsDir + "WorkingWithDocSaveOptions.EncryptDocumentWithPassword.docx", saveOptions); //ExEnd:EncryptDocumentWithPassword }
public static void Run() { // ExStart:HTMLtoDOCandDOCX // The path to the documents directory string dataDir = RunExamples.GetDataDir_Data(); // Source HTML document HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); DocSaveOptions options = new DocSaveOptions(); options.DocumentFormat = Rendering.Doc.DocumentFormat.DOCX; Converter.ConvertHTML(htmlDocument, options, dataDir + "HTMLtoDOCX_out.docx"); // ExEnd:HTMLtoDOCandDOCX }
public static void Run() { // ExStart:DetermineProgress // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Open document Document pdfDocument = new Document(dataDir + "AddTOC.pdf"); DocSaveOptions saveOptions = new DocSaveOptions(); saveOptions.CustomProgressHandler = new UnifiedSaveOptions.ConversionProgressEventHandler(ShowProgressOnConsole); dataDir = dataDir + "DetermineProgress_out.pdf"; pdfDocument.Save(dataDir, saveOptions); Console.ReadLine(); // ExEnd:DetermineProgress }
public void ConvertEPUBToDOCXTest() { // Open an existing EPUB file for reading using var stream = File.OpenRead(DataDir + "input.epub"); // Prepare a path to save the converted file string savePath = Path.Combine(OutputDir, "input-output.docx"); // Create an instance of DocSaveOptions var options = new DocSaveOptions(); // Call the ConvertEPUB method to convert EPUB to DOCX Converter.ConvertEPUB(stream, options, savePath); Assert.True(File.Exists(savePath)); }
public void PictureBullets() { //ExStart //ExFor:DocSaveOptions.SavePictureBullet //ExSummary:Shows how to remove PictureBullet data from the document. Document doc = new Document(MyDir + "Document.PictureBullets.docx"); // Word 97 cannot work correctly with PictureBullet data // To remove PictureBullet data, set the option to "false" DocSaveOptions saveOptions = new DocSaveOptions(SaveFormat.Doc); saveOptions.SavePictureBullet = false; doc.Save(ArtifactsDir + "Document.PictureBullets.doc", saveOptions); //ExEnd }
public static void ConvertToDOCX() { // ExStart:ConvertToDOCX // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); // Open the source PDF document Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf"); // Instantiate DocSaveOptions object DocSaveOptions saveOptions = new DocSaveOptions(); // Specify the output format as DOCX saveOptions.Format = DocSaveOptions.DocFormat.DocX; // Save document in docx format pdfDocument.Save("ConvertToDOCX_out.docx", saveOptions); // ExEnd:ConvertToDOCX }
public void ConvertSVGtoDOCXTest() { // Prepare SVG code var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + "<circle cx ='100' cy ='100' r ='50' fill='none' stroke='red' stroke-width='10' />" + "</svg>"; // Prepare a path for converted file saving string savePath = Path.Combine(OutputDir, "circle.docx"); // Initialize DocSaveOptions var options = new DocSaveOptions(); // Convert SVG to DOCX Converter.ConvertSVG(code, ".", options, savePath); Assert.True(File.Exists(Path.Combine(OutputDir, "circle.docx"))); }
public void EPUBtoDOCXWithDocSaveOptionsTest() { // Open an existing EPUB file for reading using var stream = File.OpenRead(DataDir + "input.epub"); // Prepare a path to save the converted file string savePath = Path.Combine(OutputDir, "input-options.docx"); // Create an instance of DocSaveOptions. Set A5 as a page-size var options = new DocSaveOptions(); options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(Length.FromInches(8.3f), Length.FromInches(5.8f))); // Call the ConvertEPUB method to convert EPUB to DOCX Converter.ConvertEPUB(stream, options, savePath); Assert.True(File.Exists(savePath)); }
/// <summary>生成PDF文件</summary> public override bool Execute(string sourceFile, string pdfFile, string destFile) { var stream = new MemoryStream(); using (var pdf = new Document(sourceFile)) { var options = new DocSaveOptions(); options.Format = DocSaveOptions.DocFormat.DocX; pdf.Save(stream, options); } stream.Position = 0; using (var document = Novacode.DocX.Load(stream)) { var content = document.Text; File.WriteAllText(destFile, content, Encoding.UTF8); } return(true); }
public void ConvertHTMLtoDOCXTest() { // Prepare a path to a source HTML file string documentPath = Path.Combine(DataDir, "canvas.html"); // Prepare a path for converted file saving string savePath = Path.Combine(OutputDir, "canvas-output.docx"); // Initialize an HTML document from the file using var document = new HTMLDocument(documentPath); // Initialize DocSaveOptions var options = new DocSaveOptions(); // Convert HTML to DOCX Converter.ConvertHTML(document, options, savePath); Assert.True(File.Exists(savePath)); }
public static void ToWord(this Document docConvert) { var pathSave = Path.Combine(GetPath(), "Convert - " + docConvert.Name + ".docx"); if (docConvert.FileType == FileType.PDF) { var pdfFile = new Aspose.Pdf.Document(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType)); DocSaveOptions opt = new DocSaveOptions() { Format = DocSaveOptions.DocFormat.DocX }; pdfFile.Save(pathSave, opt); } else if (docConvert.FileType == FileType.HTML) { var htmlFile = new HTMLDocument(Path.Combine(GetPath(), docConvert.Name + "." + docConvert.FileType)); //TODO: convert } }
public void UpdateLastPrintedProperty(bool isUpdateLastPrintedProperty) { //ExStart //ExFor:SaveOptions.UpdateLastPrintedProperty //ExSummary:Shows how to update BuiltInDocumentProperties.LastPrinted property before saving. Document doc = new Document(); // Aspose.Words update BuiltInDocumentProperties.LastPrinted property by default DocSaveOptions saveOptions = new DocSaveOptions(); saveOptions.UpdateLastPrintedProperty = isUpdateLastPrintedProperty; doc.Save(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.docx", saveOptions); //ExEnd doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.docx"); Assert.AreNotEqual(isUpdateLastPrintedProperty, DateTime.Parse("1/1/0001 00:00:00") == doc.BuiltInDocumentProperties.LastPrinted.Date); }
public void TempFolder() { //ExStart //ExFor:SaveOptions.TempFolder //ExSummary:Shows how to save a document using temporary files. Document doc = new Document(MyDir + "Rendering.doc"); // We can use a SaveOptions object to set the saving method of a document from a MemoryStream to temporary files // While saving, the files will briefly pop up in the folder we set as the TempFolder attribute below // Doing this will free up space in the memory that the stream would usually occupy DocSaveOptions options = new DocSaveOptions(); options.TempFolder = ArtifactsDir + "TempFiles"; // Ensure that the directory exists and save Directory.CreateDirectory(options.TempFolder); doc.Save(ArtifactsDir + "DocSaveOptions.TempFolder.doc", options); //ExEnd }
public void HTMLtoDOCXWithDocSaveOptionsTest() { // Prepare a path to a source HTML file string documentPath = Path.Combine(DataDir, "canvas.html"); // Prepare a path for converted file saving string savePath = Path.Combine(OutputDir, "canvas-output-options.docx"); // Initialize an HTML document from the file using var document = new HTMLDocument(documentPath); // Initialize DocSaveOptions. Set up the page-size 600x400 pixels and margins var options = new DocSaveOptions(); options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(600, 400), new Margin(10, 10, 10, 10)); // Convert HTML to DOCX Converter.ConvertHTML(document, options, savePath); Assert.True(File.Exists(savePath)); }
// ExStart:ShowProgressOnConsole public static void ShowProgressOnConsole(DocSaveOptions.ProgressEventHandlerInfo eventInfo) { switch (eventInfo.EventType) { case DocSaveOptions.ProgressEventType.TotalProgress: Console.WriteLine(String.Format("{0} - Conversion progress : {1}% .", DateTime.Now.ToLongTimeString(), eventInfo.Value.ToString())); break; case DocSaveOptions.ProgressEventType.SourcePageAnalized: Console.WriteLine(String.Format("{0} - Source page {1} of {2} analyzed.", DateTime.Now.ToLongTimeString(), eventInfo.Value.ToString(), eventInfo.MaxValue.ToString())); break; case DocSaveOptions.ProgressEventType.ResultPageCreated: Console.WriteLine(String.Format("{0} - Result page's {1} of {2} layout created.", DateTime.Now.ToLongTimeString(), eventInfo.Value.ToString(), eventInfo.MaxValue.ToString())); break; case DocSaveOptions.ProgressEventType.ResultPageSaved: Console.WriteLine(String.Format("{0} - Result page {1} of {2} exported.", DateTime.Now.ToLongTimeString(), eventInfo.Value.ToString(), eventInfo.MaxValue.ToString())); break; default: break; } }
public void ConvertMDtoDOCXWithDocSaveOptionsTest() { // Prepare a path to a source Markdown file string sourcePath = Path.Combine(DataDir, "nature.md"); // Prepare a path for converted DOCX file saving string savePath = Path.Combine(OutputDir, "nature-output.docx"); // Convert Markdown to HTML using var document = Converter.ConvertMarkdown(sourcePath); // Initialize DocSaveOptions. Set up the page-size 500x1000 pixels and margins var options = new DocSaveOptions(); options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(500, 1000), new Margin(20, 20, 10, 10)); // Convert the HTML document to DOCX file format Converter.ConvertHTML(document, options, savePath); Assert.True(File.Exists(savePath)); }
public void SVGtoDOCXWithDocSaveOptionsTest() { // Prepare a path to a source SVG file string documentPath = Path.Combine(DataDir, "shapes.svg"); // Prepare a path for converted file saving string savePath = Path.Combine(OutputDir, "shapes-options.docx"); // Initialize an SVG document from the file using var document = new SVGDocument(documentPath); // Initialize DocSaveOptions. Set up the page-size and margins var options = new DocSaveOptions(); options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(500, 500), new Margin(30, 10, 10, 10)); // Convert SVG to DOCX Converter.ConvertSVG(document, options, savePath); Assert.True(File.Exists(Path.Combine(OutputDir, "shapes-options.docx"))); }
public void PictureBullets() { //ExStart //ExFor:DocSaveOptions.SavePictureBullet //ExSummary:Shows how to remove PictureBullet data from the document. Document doc = new Document(MyDir + "Image bullet points.docx"); Assert.NotNull(doc.Lists[0].ListLevels[0].ImageData); //ExSkip // Word 97 cannot work correctly with PictureBullet data // To remove PictureBullet data, set the option to "false" DocSaveOptions saveOptions = new DocSaveOptions(SaveFormat.Doc); saveOptions.SavePictureBullet = false; doc.Save(ArtifactsDir + "DocSaveOptions.PictureBullets.doc", saveOptions); //ExEnd doc = new Document(ArtifactsDir + "DocSaveOptions.PictureBullets.doc"); Assert.Null(doc.Lists[0].ListLevels[0].ImageData); }