문서를 이미지로 변환

때로는 다음과 같은 다른 형식의 문서 대신 이미지를 가져와야 합니다. DOCX 또는 PDF. 예를 들어,당신은 당신의 웹 사이트 또는 응용 프로그램에 문서 페이지의 미리보기를 추가하거나 송장을 보낼 수있는 문서의"스캔"을 만들어야합니다. 당신이 어떤에서 문서를 변환해야 할 수도 있습니다 때이다 supported load format 이미지에,다시,어떤 supported save format.

이미지 형식으로 변환

이미 설명한 모든 변환 예제와 마찬가지로 새 문서를 만들거나 기존 문서를 지원되는 형식으로 로드하고 필요한 내용을 변경한 다음 사용 가능한 이미지 형식으로 저장해야 합니다., JPEG, PNG,또는 BMP.

다음 코드 예제에서는 변환하는 방법을 보여 줍니다 DOCX 에 JPEG:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Load the document from disk.
System::SharedPtr<Document> doc = System::MakeObject<Document>(MyDir + u"TestDoc.docx");
// Save the document in JPEG format.
doc->Save(ArtifactsDir + u"SaveDocx2Jpeg.jpeg");

이미지로 변환할 때 저장 옵션 지정

Aspose.Words 당신을 제공합니다 ImageSaveOptions 문서를 다양한 이미지 형식으로 저장하는 방법을 더 잘 제어 할 수있는 클래스. 이 클래스의 일부 속성은 다음과 같은 기본 클래스의 속성을 상속하거나 오버로드합니다 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-C
// Load the document from disk.
auto doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
auto imageSaveOptions = System::MakeObject<ImageSaveOptions>(SaveFormat::Jpeg);
// Set the "PageSet" to "0" to convert only the first page of a document.
auto pageRange = System::MakeObject<PageRange>(0, 0);
imageSaveOptions->set_PageSet(System::MakeObject<PageSet>(System::MakeArray<System::SharedPtr<PageRange>>({ pageRange })));
// Change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
imageSaveOptions->set_ImageBrightness(0.3f);
imageSaveOptions->set_ImageContrast(0.7f);
// Change the horizontal resolution.
// The default value for these properties is 96.0, for a resolution of 96dpi.
imageSaveOptions->set_HorizontalResolution(72.0f);
// Save the document in JPEG format.
doc->Save(outputDataDir + u"SaveDocx2Jpeg.jpeg", imageSaveOptions);