حفظ مستند
تتضمن معظم المهام التي تحتاج إلى تنفيذها باستخدام Aspose.Words حفظ مستند. لحفظ مستند Aspose.Words يوفر طريقة Save لفئة Document. يمكن حفظ المستند بأي تنسيق حفظ يدعمه Aspose.Words. للحصول على قائمة بجميع تنسيقات الحفظ المدعومة، راجع SaveFormat تعداد.
حفظ في ملف
ببساطة استخدام طريقة Save مع اسم الملف. Aspose.Words سيحدد تنسيق الحفظ من امتداد الملف الذي تحدده.
يوضح مثال التعليمات البرمجية التالية كيفية تحميل مستند وحفظه في ملف:
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); |
حفظ في دفق
قم بتمرير كائن دفق إلى طريقة Save. من الضروري تحديد تنسيق الحفظ بشكل صريح عند الحفظ في دفق.
يوضح مثال التعليمات البرمجية التالية كيفية تحميل مستند وحفظه في دفق:
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()); |
يمكنك تنزيل ملف القالب لهذا المثال من Aspose.Words GitHub.
حفظ إلى PCL
Aspose.Words يدعم حفظ مستند في PCL (لغة أمر الطابعة). Aspose.Words يمكن حفظ المستندات في PCL 6 (PCL 6 تعزيز أو PCL XL) الشكل. يمكن استخدام فئة PclSaveOptions
لتحديد خيارات إضافية عند حفظ مستند في تنسيق PCL.
يوضح مثال الكود التالي كيفية حفظ مستند إلى PCL باستخدام خيارات الحفظ:
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); |