Aspose::Words::Document::Save method
Document::Save(const System::SharedPtr<System::IO::Stream>&, Aspose::Words::SaveFormat) method
Saves the document to a stream using the specified format.
System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(const System::SharedPtr<System::IO::Stream> &stream, Aspose::Words::SaveFormat saveFormat)
Parameter | Type | Description |
---|---|---|
stream | const System::SharedPtr<System::IO::Stream>& | Stream where to save the document. |
saveFormat | Aspose::Words::SaveFormat | The format in which to save the document. |
ReturnValue
Additional information that you can optionally use.
Examples
Shows how to save a document to an image via stream, and then read the image from that stream.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Times New Roman");
builder->get_Font()->set_Size(24);
builder->Writeln(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->InsertImage(get_ImageDir() + u"Logo.jpg");
Shows how to save a document to a stream.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Document.docx");
{
auto dstStream = System::MakeObject<System::IO::MemoryStream>();
doc->Save(dstStream, Aspose::Words::SaveFormat::Docx);
// Verify that the stream contains the document.
ASSERT_EQ(u"Hello World!\r\rHello Word!\r\r\rHello World!", System::MakeObject<Aspose::Words::Document>(dstStream)->GetText().Trim());
}
See Also
- Class SaveOutputParameters
- Enum SaveFormat
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(const System::SharedPtr<System::IO::Stream>&, const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&) method
Saves the document to a stream using the specified save options.
System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(const System::SharedPtr<System::IO::Stream> &stream, const System::SharedPtr<Aspose::Words::Saving::SaveOptions> &saveOptions)
Parameter | Type | Description |
---|---|---|
stream | const System::SharedPtr<System::IO::Stream>& | Stream where to save the document. |
saveOptions | const System::SharedPtr<Aspose::Words::Saving::SaveOptions>& | Specifies the options that control how the document is saved. Can be null. If this is null, the document will be saved in the binary DOC format. |
ReturnValue
Additional information that you can optionally use.
See Also
- Class SaveOutputParameters
- Class SaveOptions
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(const System::String&) method
Saves the document to a file. Automatically determines the save format from the extension.
System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(const System::String &fileName)
Parameter | Type | Description |
---|---|---|
fileName | const System::String& | The name for the document. If a document with the specified file name already exists, the existing document is overwritten. |
ReturnValue
Additional information that you can optionally use.
Examples
Shows how to open a document and convert it to .PDF.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Document.docx");
doc->Save(get_ArtifactsDir() + u"Document.ConvertToPdf.pdf");
See Also
- Class SaveOutputParameters
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(const System::String&, Aspose::Words::SaveFormat) method
Saves the document to a file in the specified format.
System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(const System::String &fileName, Aspose::Words::SaveFormat saveFormat)
Parameter | Type | Description |
---|---|---|
fileName | const System::String& | The name for the document. If a document with the specified file name already exists, the existing document is overwritten. |
saveFormat | Aspose::Words::SaveFormat | The format in which to save the document. |
ReturnValue
Additional information that you can optionally use.
Examples
Shows how to convert from DOCX to HTML format.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Document.docx");
doc->Save(get_ArtifactsDir() + u"Document.ConvertToHtml.html", Aspose::Words::SaveFormat::Html);
See Also
- Class SaveOutputParameters
- Enum SaveFormat
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(const System::String&, const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&) method
Saves the document to a file using the specified save options.
System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(const System::String &fileName, const System::SharedPtr<Aspose::Words::Saving::SaveOptions> &saveOptions)
Parameter | Type | Description |
---|---|---|
fileName | const System::String& | The name for the document. If a document with the specified file name already exists, the existing document is overwritten. |
saveOptions | const System::SharedPtr<Aspose::Words::Saving::SaveOptions>& | Specifies the options that control how the document is saved. Can be null. |
ReturnValue
Additional information that you can optionally use.
Examples
Shows how to improve the quality of a rendered document with SaveOptions.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Rendering.docx");
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->get_Font()->set_Size(60);
builder->Writeln(u"Some text.");
System::SharedPtr<Aspose::Words::Saving::SaveOptions> options = System::MakeObject<Aspose::Words::Saving::ImageSaveOptions>(Aspose::Words::SaveFormat::Jpeg);
doc->Save(get_ArtifactsDir() + u"Document.ImageSaveOptions.Default.jpg", options);
options->set_UseAntiAliasing(true);
options->set_UseHighQualityRendering(true);
doc->Save(get_ArtifactsDir() + u"Document.ImageSaveOptions.HighQuality.jpg", options);
Shows how to render one page from a document to a JPEG image.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->Writeln(u"Page 1.");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertImage(get_ImageDir() + u"Logo.jpg");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
auto options = System::MakeObject<Aspose::Words::Saving::ImageSaveOptions>(Aspose::Words::SaveFormat::Jpeg);
// Set the "PageSet" to "1" to select the second page via
// the zero-based index to start rendering the document from.
options->set_PageSet(System::MakeObject<Aspose::Words::Saving::PageSet>(1));
// When we save the document to the JPEG format, Aspose.Words only renders one page.
// This image will contain one page starting from page two,
// which will just be the second page of the original document.
doc->Save(get_ArtifactsDir() + u"ImageSaveOptions.OnePage.jpg", options);
Shows how to render every page of a document to a separate TIFF image.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->Writeln(u"Page 1.");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
builder->Writeln(u"Page 2.");
builder->InsertImage(get_ImageDir() + u"Logo.jpg");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
builder->Writeln(u"Page 3.");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
auto options = System::MakeObject<Aspose::Words::Saving::ImageSaveOptions>(Aspose::Words::SaveFormat::Tiff);
for (int32_t i = 0; i < doc->get_PageCount(); i++)
{
// Set the "PageSet" property to the number of the first page from
// which to start rendering the document from.
options->set_PageSet(System::MakeObject<Aspose::Words::Saving::PageSet>(i));
// Export page at 2325x5325 pixels and 600 dpi.
options->set_Resolution(600.0f);
options->set_ImageSize(System::Drawing::Size(2325, 5325));
doc->Save(get_ArtifactsDir() + System::String::Format(u"ImageSaveOptions.PageByPage.{0}.tiff", i + 1), options);
}
Shows how to configure compression while saving a document as a JPEG.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->InsertImage(get_ImageDir() + u"Logo.jpg");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
auto imageOptions = System::MakeObject<Aspose::Words::Saving::ImageSaveOptions>(Aspose::Words::SaveFormat::Jpeg);
// Set the "JpegQuality" property to "10" to use stronger compression when rendering the document.
// This will reduce the file size of the document, but the image will display more prominent compression artifacts.
imageOptions->set_JpegQuality(10);
doc->Save(get_ArtifactsDir() + u"ImageSaveOptions.JpegQuality.HighCompression.jpg", imageOptions);
// Set the "JpegQuality" property to "100" to use weaker compression when rending the document.
// This will improve the quality of the image at the cost of an increased file size.
imageOptions->set_JpegQuality(100);
doc->Save(get_ArtifactsDir() + u"ImageSaveOptions.JpegQuality.HighQuality.jpg", imageOptions);
See Also
- Class SaveOutputParameters
- Class SaveOptions
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(std::basic_ostream<CharType, Traits>&, Aspose::Words::SaveFormat) method
template<typename CharType,typename Traits> System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(std::basic_ostream<CharType, Traits> &stream, Aspose::Words::SaveFormat saveFormat)
See Also
- Class SaveOutputParameters
- Enum SaveFormat
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++
Document::Save(std::basic_ostream<CharType, Traits>&, System::SharedPtr<Aspose::Words::Saving::SaveOptions>) method
template<typename CharType,typename Traits> System::SharedPtr<Aspose::Words::Saving::SaveOutputParameters> Aspose::Words::Document::Save(std::basic_ostream<CharType, Traits> &stream, System::SharedPtr<Aspose::Words::Saving::SaveOptions> saveOptions)
See Also
- Class SaveOutputParameters
- Class SaveOptions
- Class Document
- Namespace Aspose::Words
- Library Aspose.Words for C++