Stoor'n Dokument
Die meeste van die take wat u met Aspose.Words moet uitvoer, behels die stoor van’n dokument. Om’n dokument te stoor Aspose.Words bied die Save metode van die Document klas. Die dokument kan gestoor word in enige stoor formaat ondersteun deur Aspose.Words. Vir die lys van alle ondersteunde stoor formate, sien die SaveFormat opsomming.
Stoor na’n Lêer
Gebruik eenvoudig die Save metode met’n lêernaam. Aspose.Words sal die stoorformaat bepaal uit die lêeruitbreiding wat u spesifiseer.
Die volgende kode voorbeeld toon hoe om te laai en stoor’n dokument na’n lêer:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// The path to the documents directories. | |
System::String inputDataDir = GetInputDataDir_LoadingAndSaving(); | |
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving(); | |
// Load the document from the absolute path on disk. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.docx"); | |
System::String outputPath = outputDataDir + u"LoadAndSaveToDisk.docx"; | |
// Save the document as DOC document."); | |
doc->Save(outputPath); |
Stoor na’n Stroom
Gee’n stroom voorwerp na die Save metode. Dit is nodig om die stoor formaat uitdruklik spesifiseer wanneer die stoor na’n stroom.
Die volgende kode voorbeeld toon hoe om te laai en stoor’n dokument na’n stroom:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// The path to the documents directories. | |
System::String inputDataDir = GetInputDataDir_LoadingAndSaving(); | |
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving(); | |
// Open the stream. Read only access is enough for Aspose.Words to load a document. | |
System::SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(inputDataDir + u"Document.docx"); | |
// Load the entire document into memory. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(stream); | |
// You can close the stream now, it is no longer needed because the document is in memory. | |
stream->Close(); | |
// ... do something with the document | |
// Convert the document to a different format and save to stream. | |
System::SharedPtr<System::IO::MemoryStream> dstStream = System::MakeObject<System::IO::MemoryStream>(); | |
doc->Save(dstStream, SaveFormat::Doc); | |
// Rewind the stream position back to zero so it is ready for the next reader. | |
dstStream->set_Position(0); | |
// Save the document from stream, to disk. Normally you would do something with the stream directly, | |
// For example writing the data to a database. | |
System::String outputPath = outputDataDir + u"LoadAndSaveToStream.docx"; | |
System::IO::File::WriteAllBytes(outputPath, dstStream->ToArray()); |
Jy kan die sjabloon lêer van hierdie voorbeeld aflaai van Aspose.Words GitHub.
Stoor na PCL
Aspose.Words ondersteun die stoor van’n dokument in PCL (Printer Command Language). Aspose.Words kan dokumente stoor in PCL 6 (PCL 6 Verbeterde of PCL XL) formaat. Die PclSaveOptions
klas kan gebruik word om addisionele opsies te spesifiseer wanneer’n dokument in die PCL formaat gestoor word.
Die volgende kode voorbeeld toon hoe om’n dokument te stoor om PCL met behulp van stoor opsies:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// The path to the documents directories. | |
System::String inputDataDir = GetInputDataDir_LoadingAndSaving(); | |
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving(); | |
// Load the document from disk. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Test File (docx).docx"); | |
System::SharedPtr<PclSaveOptions> saveOptions = System::MakeObject<PclSaveOptions>(); | |
saveOptions->set_SaveFormat(SaveFormat::Pcl); | |
saveOptions->set_RasterizeTransformedElements(false); | |
// Export the document as an PCL file. | |
doc->Save(outputDataDir + u"ConvertDocumentToPCL.pcl", saveOptions); |