Skip to content

输出预览 (Output Preview)

自 7.4 版本起,福昕 PDF SDK 引入了强大的输出预览功能,为开发者提供了精准的色彩管理工具。该功能不仅支持分色预览,还能模拟和测试不同的颜色配置文件,确保 PDF 文档在不同输出设备上的色彩准确性。

核心优势:

  • 分色预览: 开发者可以逐个查看文档中的分色,确保印刷输出的色彩准确性。
  • 颜色配置文件测试: 支持模拟不同的颜色配置文件,预览文档在不同输出条件下的色彩表现,避免色彩偏差。
  • 提升印刷质量: 通过精准的色彩预览,有效减少印刷过程中的色彩问题,提升最终印刷品的质量。

该功能广泛应用于印刷、出版、设计等对色彩精度要求高的行业,帮助开发者实现专业的色彩管理。

开发者可通过查阅详细的 输出预览示例配置与运行指南,快速了解配置步骤和运行示例,轻松掌握该功能的使用方法。

以下代码演示如何使用福昕 PDF SDK 的 OutputPreview 功能,通过设置 ICC 配置文件和分色显示,生成 PDF 页面的色彩模拟预览位图。这对于印刷、出版等需要精确色彩管理的场景非常有用。

使用 OutputPreview 类进行输出预览

c++
#include "include/common/fs_common.h"
#include "include/pdf/fs_outputpreview.h"

// Make sure that SDK has already been initialized successfully.

// Set folder path which contains default icc profile files.
Library::SetDefaultICCProfilesPath(default_icc_folder_path);

// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.

OutputPreview output_preview(pdf_doc);
WString simulation_icc_file_path = input_path + L"icc_profile/USWebCoatedSWOP.icc";
output_preview.SetSimulationProfile(simulation_icc_file_path);
output_preview.SetShowType(OutputPreview::e_ShowAll);
StringArray process_plates = output_preview.GetPlates(OutputPreview::e_ColorantTypeProcess);
StringArray spot_plates = output_preview.GetPlates(OutputPreview::e_ColorantTypeSpot);
// Set check status of process plate to be true, if there's any process plate.
for (int i = 0; i < (int)process_plates.GetSize(); i++) {
	output_preview.SetCheckStatus(process_plates[i], true);
}
// Set check status of spot plate to be true, if there's any spot plate.
for (int i = 0; i < (int)spot_plates.GetSize(); i++) {
	output_preview.SetCheckStatus(spot_plates[i], true);
}

// Generate preview bitmap
Bitmap preview_bitmap = output_preview.GeneratePreviewBitmap(pdf_page, display_matrix, renderer);
C
#include "include/fs_common_c.h"
#include "include/fs_outputpreview_c.h"

// Make sure that SDK has already been initialized successfully.

// Set folder path which contains default icc profile files.
FSErrorCode error_code = FSDK_Library_SetDefaultICCProfilesPath(default_icc_folder_path);

// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.

FS_OUTPUTPREVIEW_HANDLE output_preview;
FSDK_OutputPreview_Create(pdf_doc, &output_preview);
wchar_t simulation_icc_file_path[MAX_FILE_PATH] = { 0 };
swprintf_s(simulation_icc_file_path, MAX_FILE_PATH, L"%lsicc_profile/USWebCoatedSWOP.icc", input_path);
FSDK_OutputPreview_SetSimulationProfile(output_preview, simulation_icc_file_path);
FSDK_OutputPreview_SetShowType(output_preview, e_FSShowAll);

FS_UINT32 process_plates_length = 0;
FSDK_OutputPreview_GetPlates(output_preview, e_FSColorantTypeProcess, NULL, &process_plates_length);
process_plates = (FS_BSTR*)malloc(sizeof(FS_BSTR) * process_plates_length);
FSDK_OutputPreview_GetPlates(output_preview, e_FSColorantTypeProcess, process_plates, process_plates_length);

FS_UINT32 spot_plates_length = 0;
FSDK_OutputPreview_GetPlates(output_preview, e_FSColorantTypeSpot, NULL, &spot_plates_length);
spot_plates = (FS_BSTR*)malloc(sizeof(FS_BSTR) * spot_plates_length);
FSDK_OutputPreview_GetPlates(output_preview, e_FSColorantTypeSpot, spot_plates, &spot_plates_length);

// Set check status of process plate to be true, if there's any process plate.
for (int i = 0; i < (int)process_plates_length; i++) {
	error_code = FSDK_OutputPreview_SetCheckStatus(output_preview, process_plates[i], true);
}
free(process_plates);

// Set check status of spot plate to be true, if there's any spot plate.
for (int i = 0; i < (int)spot_plates_length; i++) {
	error_code = FSDK_OutputPreview_SetCheckStatus(output_preview, spot_plates[i], true);
}
free(spot_plates);

// Generate preview bitmap
FS_BITMAP_HANDLE preview_bitmap;
error_code = FSDK_OutputPreview_GeneratePreviewBitmap(output_preview, pdf_page, display_matrix, renderer, &preview_bitmap);
java
import com.foxit.sdk.common.Library;
import com.foxit.sdk.common.Renderer;
import com.foxit.sdk.common.fxcrt.Matrix2D;
import com.foxit.sdk.pdf.OutputPreview;
 
// Make sure that SDK has already been initialized successfully.
 
// Set folder path which contains default icc profile files.
Library.setDefaultICCProfilesPath(default_icc_folder_path);
 
// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.
 
OutputPreview output_preview = new OutputPreview(pdf_doc);
String simulation_icc_file_path = input_path + "icc_profile/USWebCoatedSWOP.icc";
output_preview.setSimulationProfile(simulation_icc_file_path);
output_preview.setShowType(OutputPreview.e_ShowAll);
ArrayList<String> process_plates = output_preview.getPlates(OutputPreview.e_ColorantTypeProcess);
ArrayList<String> spot_plates = output_preview.getPlates(OutputPreview.e_ColorantTypeSpot);
 
// Set check status of process plate to be true, if there's any process plate.
for (int i = 0; i < (int)process_plates.size(); i++) {
    output_preview.setCheckStatus(process_plates.get(i), true);
}
 
// Set check status of spot plate to be true, if there's any spot plate.
for (int i = 0; i < (int)spot_plates.size(); i++) {
    output_preview.setCheckStatus(spot_plates.get(i), true);
}
 
Bitmap preview_bitmap = output_preview.generatePreviewBitmap(pdf_page, display_matrix, renderer);
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Make sure that SDK has already been initialized successfully.

# Set folder path which contains default icc profile files.
Library.SetDefaultICCProfilesPath(default_icc_folder_path)

# Load a PDF document; Get a PDF page and parse it.
# Prepare a Renderer object and the matrix for rendering.

output_preview = OutputPreview(pdf_doc)
simulation_icc_file_path = input_path + "icc_profile/USWebCoatedSWOP.icc"
output_preview.SetSimulationProfile(simulation_icc_file_path)
output_preview.SetShowType(OutputPreview.e_ShowAll)
process_plates = output_preview.GetPlates(OutputPreview.e_ColorantTypeProcess)
spot_plates = output_preview.GetPlates(OutputPreview.e_ColorantTypeSpot)
process_size = int(process_plates.GetSize())
# Set check status of process plate to be true, if there's any process plate.
for i in range(0, process_size):
    output_preview.SetCheckStatus(process_plates[i], True)

spot_size = int(spot_plates.GetSize())
# Set check status of spot plate to be true, if there's any spot plate.
for i in range(0, spot_size):
    output_preview.SetCheckStatus(spot_plates[i], True)

# Generate preview bitmap
preview_bitmap = output_preview.GeneratePreviewBitmap(pdf_page, display_matrix, renderer)
objc
#include "include/FSPDFObjC.h"
 
// Make sure that SDK has already been initialized successfully.
 
// Set folder path which contains default icc profile files.
[FSLibrary setDefaultICCProfilesPath:default_icc_folder_path];
 
// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.
 
FSOutputPreview* output_preview = [[FSOutputPreview alloc] initWithPdf_doc:pdf_doc];
NSString* simulation_icc_file_path = [input_path stringByAppendingPathComponent:@"icc_profile/USWebCoatedSWOP.icc"];
[output_preview setSimulationProfile:simulation_icc_file_path];
[output_preview setShowType:FSOutputPreviewShowAll];
NSArray<NSString *>* process_plates = [output_preview getPlates:FSOutputPreviewColorantTypeProcess];
NSArray<NSString *>* spot_plates = [output_preview getPlates:FSOutputPreviewColorantTypeSpot];
 
// Set check status of process plate to be true, if there's any process plate.
for (int i = 0; i < [process_plates count]; i++) {
    [output_preview setCheckStatus:[process_plates objectAtIndex:i] to_check:true];
}
 
// Set check status of spot plate to be true, if there's any spot plate.
for (int i = 0; i < [spot_plates count]; i++) {
    [output_preview setCheckStatus:[spot_plates objectAtIndex:i] to_check:true];
}
 
FSBitmap* preview_bitmap = [output_preview generatePreviewBitmap:pdf_page matrix:display_matrix renderer:renderer];
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");

...
// Make sure that SDK has already been initialized successfully.

// Set folder path which contains default icc profile files.
FSDK.Library.SetDefaultICCProfilesPath(default_icc_folder_path);

// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.
let output_preview = new FSDK.OutputPreview(pdf_doc);
let simulation_icc_file_path = input_path + "icc_profile/USWebCoatedSWOP.icc";
output_preview.SetSimulationProfile(simulation_icc_file_path);
output_preview.SetShowType(FSDK.OutputPreview.e_ShowAll);
let process_plates = output_preview.GetPlates(FSDK.OutputPreview.e_ColorantTypeProcess);
let spot_plates = output_preview.GetPlates(FSDK.OutputPreview.e_ColorantTypeSpot);
// Set check status of spot plate to be true, if there's any spot plate.
for (let i = 0; i < spot_plates.GetSize(); i++) {
  output_preview.SetCheckStatus(spot_plates.GetAt(i), true);
}

// Generate preview bitmap
// Only set one process plate to be checked each time and generate the preview bitmap.
for (let i = 0; i < process_plates.GetSize(); i++) {
  if (0 != i)
    output_preview.SetCheckStatus(process_plates.GetAt(i-1), false);
  output_preview.SetCheckStatus(process_plates.GetAt(i), true);
let preview_bitmap = output_preview.GeneratePreviewBitmap(pdf_page, display_matrix, renderer);
}
csharp
using foxit.common;
using foxit.pdf;
 
// Make sure that SDK has already been initialized successfully.
 
// Set folder path which contains default icc profile files.
Library.SetDefaultICCProfilesPath(default_icc_folder_path);
 
// Load a PDF document; Get a PDF page and parse it.
// Prepare a Renderer object and the matrix for rendering.

using (OutputPreview output_preview = new OutputPreview(pdf_doc))
{
string simulation_icc_file_path = input_path + "icc_profile/USWebCoatedSWOP.icc";
    output_preview.SetSimulationProfile(simulation_icc_file_path);
    output_preview.SetShowType(OutputPreview.ShowType.e_ShowAll);
    StringArray process_plates = output_preview.GetPlates(OutputPreview.ColorantType.e_ColorantTypeProcess);
    StringArray spot_plates = output_preview.GetPlates(OutputPreview.ColorantType.e_ColorantTypeSpot);
 
    // Set check status of process plate to be true, if there's any process plate.
    for (uint i = 0; i<process_plates.GetSize(); i++)
    {
        output_preview.SetCheckStatus(process_plates.GetAt(i), true);
    }
 
    // Set check status of spot plate to be true, if there's any spot plate.
    for (uint i = 0; i<spot_plates.GetSize(); i++)
    {
        output_preview.SetCheckStatus(spot_plates.GetAt(i), true);
}
 
    using (foxit.common.Bitmap preview_bitmap = output_preview.GeneratePreviewBitmap(pdf_page, display_matrix, renderer))
    {
        ...// Use preview bitmap or save it.
    }
}