המונחים: save Options

בעת שמירת מסמך, באפשרותך להגדיר כמה תכונות מתקדמות. Aspose.Words מספק לך את SaveOptions מעמד, המאפשר שליטה מדויקת יותר של תהליך החיסכון. יש עומסים של Save שיטה שמקבלת SaveOptions אובייקט - זה צריך להיות אובייקט של מעמד נגזר מן SaveOptions מעמד. לכל פורמט שמור יש מעמד מתאים המחזיק אפשרויות לתבנית זו, לדוגמה, יש. PdfSaveOptions כדי לחסוך בפורמט PDF, MarkdownSaveOptions כדי להציל Markdown פורמט, או ImageSaveOptions להציל תמונה מאמר זה מספק דוגמאות של עבודה עם כמה אפשרויות כיתות נגזרות SaveOptions.

לדוגמה הקוד הבא מראה כיצד להגדיר את אפשרויות החיסכון לפני שמירת המסמך ל- HTML:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string fileName = "TestFile RenderShape.docx";
Document doc = new Document(dataDir + fileName);
// This is the directory we want the exported images to be saved to.
string imagesDir = Path.Combine(dataDir, "Images");
// The folder specified needs to exist and should be empty.
if (Directory.Exists(imagesDir))
Directory.Delete(imagesDir, true);
Directory.CreateDirectory(imagesDir);
// Set an option to export form fields as plain text, not as HTML input elements.
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
options.ExportTextInputFormFieldAsText = true;
options.ImagesFolder = imagesDir;
dataDir = dataDir + "Document.SaveWithOptions_out.html";
doc.Save(dataDir, options);

המאמר מתאר כמה תכונות אתה יכול לשלוט בעת שמירת מסמך.

הצפנה מסמך עם סיסמה

השתמש Password רכוש כדי לקבל או להגדיר סיסמה עבור מסמך מוצפן. השתמש Password נכס של הכיתה המקבילה לעבוד עם פורמט המסמך שנבחר.

לדוגמה, בעת שמירת מסמך DOC או DOT פורמט, השתמש Password רכוש DocSaveOptions מעמד.

הדוגמה הבאה של הקוד מראה כיצד להגדיר סיסמה להצפין מסמך באמצעות שיטת הצפנה של ה-RC4:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(dataDir + "Document.docx");
DocSaveOptions docSaveOptions = new DocSaveOptions();
docSaveOptions.Password = "password";
dataDir = dataDir + "Document.Password_out.docx";
doc.Save(dataDir, docSaveOptions);

בעת שמירת מסמך לתבנית Odt, השתמש Password רכוש OdtSaveOptions מעמד.

הדוגמה הקודית הבאה מראה כיצד לטעון ולהציל את OpenDocument מוצפנת עם סיסמה:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(dataDir + @"encrypted.odt", new Aspose.Words.LoadOptions("password"));
doc.Save(dataDir + "out.odt", new OdtSaveOptions("newpassword"));

לא כל הפורמטים תומכים הצפנה והשימוש Password רכוש.

תוצאות חיפוש: Saving Progress Notifications

Aspose.Words מספק את היכולת להשתמש ProgressCallback לרכוש הודעות על ההתקדמות של שמירת מסמכים.

זה זמין עכשיו בעת שמירת DOCX, FlatOpc, DOCM, DOTM, DOTX, HTML, MHTML, EPUB, XamlFlow, XamlFlowPack או TXT פורמטים.

עדכון זמן יצירת המסמכים

Aspose.Words מספק יכולת להשתמש CreatedTime לרכוש או להגדיר את תאריך יצירת המסמך ב- UTC. אתה יכול גם לעדכן את הערך הזה לפני שמירת השימוש UpdateCreatedTimeProperty אפשרות.

דוגמה לקוד הבא מראה כיצד לעדכן את זמן יצירת המסמך:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(MyDir + "Rendering.docx");
PdfSaveOptions saveOptions = new PdfSaveOptions { UpdateLastPrintedProperty = true };
doc.Save(ArtifactsDir + "WorkingWithPdfSaveOptions.UpdateIfLastPrinted.pdf", saveOptions);

עדכון אחרון

Aspose.Words מספק יכולת להשתמש UpdateLastSavedTimeProperty לרכוש או לקבוע ערך לקבוע אם LastSavedTime הנכס מעודכן לפני החיסכון.

הדוגמה הבאה של הקוד מראה כיצד להגדיר את הנכס הזה ולהציל את המסמך:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
Document doc = new Document(dataDir + "Document.docx");
OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.UpdateLastSavedTimeProperty = true;
dataDir = dataDir + "UpdateLastSavedTimeProperty_out.docx";
// Save the document to disk.
doc.Save(dataDir, ooxmlSaveOptions);

בקרת משאבים חיצוניים בעת שמירת מסמך ל- HTML או SVG

כדי להמיר HTML או SVG ל- PDF, פשוט להשתמש Save שיטה וסימון שם קובץ עם הרחבה “.PDF”. אם אתה רוצה לטעון תמונות, CSS, וכו ' ממקורות חיצוניים, אתה יכול להשתמש IResourceSavingCallback.

הדוגמה הבאה של הקוד מראה כיצד להמיר את HTML ל- PDF ולטעום תמונות ממקורות חיצוניים:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
public class ImageLoadingWithCredentialsHandler : IResourceLoadingCallback
{
public ImageLoadingWithCredentialsHandler()
{
mWebClient = new WebClient();
}
public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
{
if (args.ResourceType == ResourceType.Image)
{
Uri uri = new Uri(args.Uri);
if (uri.Host == "www.aspose.com")
mWebClient.Credentials = new NetworkCredential("User1", "akjdlsfkjs");
else
mWebClient.Credentials = new NetworkCredential("SomeOtherUserID", "wiurlnlvs");
// Download the bytes from the location referenced by the URI.
byte[] imageBytes = mWebClient.DownloadData(args.Uri);
args.SetData(imageBytes);
return ResourceLoadingAction.UserProvided;
}
else
{
return ResourceLoadingAction.Default;
}
}
private WebClient mWebClient;
}

שמור שחור ולבן תמונה עם אחד bit Per Pixel

כדי לשלוט באפשרויות שמירת תמונות, ImageSaveOptions הכיתה משמשת. לדוגמה, אתה יכול להשתמש PixelFormat רכוש להגדיר את פורמט פיקסל עבור התמונות שנוצרו. אנא שימו לב כי פורמט פיקסל של תמונת הפלט עשוי להיות שונה מהערך הסט בגלל העבודה של GDI+.

הדוגמה הבאה של הקוד מראה כיצד להציל תמונה שחורה ולבן עם קצת לתבנית פיקסל:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.Png);
PageSet pageSet = new PageSet(new PageRange(1, 1));
opt.PageSet = pageSet;
opt.ImageColorMode = ImageColorMode.BlackAndWhite;
opt.PixelFormat = ImagePixelFormat.Format1bppIndexed;
dataDir = dataDir + "Format1bppIndexed_Out.Png";
doc.Save(dataDir, opt);