להפוך מסמך לתמונה

לפעמים נדרש לקבל תמונה במקום מסמכים בפורמטים אחרים, כגון DOCX או PDF. לדוגמה, אתה צריך להוסיף תצוגה מקדימה של כל דף מסמך לאתר או היישום שלך או ליצור “scan” של מסמך לשלוח חשבונית. זה כאשר ייתכן שיהיה עליך להמיר מסמך בכל עת. פורמט עומס נתמך תמונה, שוב, בכל פורמט Save.

המונחים: Image Format

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

דוגמה לקוד הבא מראה כיצד להמיר את DOCX ל- JPEG:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Load the document from disk.
Document doc = new Document(dataDir + "TestDoc.pdf");
// Save the document in JPEG format.
doc.save(dataDir + "SaveDocx2Jpeg.jpeg");

המונחים: save Options בעת המרת תמונה

Aspose.Words מספק לך את ImageSaveOptions שיעור, אשר נותן יותר שליטה על האופן שבו המסמכים נשמרים בפורמטים שונים של תמונות. כמה תכונות של כיתה זו יורש או overload נכסים של שיעורי בסיס כגון FixedPageSaveOptions או SaveOptions, אבל יש גם אפשרויות ספציפיות להצלת תמונות.

ניתן לציין את הדפים להיות מומרים לתבנית תמונה באמצעות פורמט התמונה באמצעות תבנית. PageSet רכוש. לדוגמה, זה יכול להיות מיושם אם אתה רק צריך תצוגה מקדימה עבור הראשון או עבור דף מוגדר.

כמו כן, ניתן לשלוט על איכות התמונה פלט ואת פורמט פיקסל באמצעות התכונות הבאות - HorizontalResolution, VerticalResolution, Resolution, Scale, PixelFormat, כמו גם להגדיר הגדרות צבע תמונה, באמצעות התכונות הבאות - ImageBrightness, ImageColorMode, ImageContrast, PaperColor.

יש גם תכונות החלות על פורמט מסוים, למשל, JpegQuality או TiffCompression.

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Load the document from disk.
Document doc = new Document(dataDir + "TestDoc.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// Set the "PageSet" to "0" to convert only the first page of a document.
options.setPageSet(new PageSet(0));
// Change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// Change the horizontal resolution.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
// Save the document in JPEG format.
doc.save(dataDir + "SaveDocx2Jpeg.jpeg", options);