【现象】Save as PDF/X-3/4/5,导出的pdf错误,打不开,文件是空的。
【原因】
我们设置的文字颜色是RGB Color Space,但是我们设置的PDF/X-3/4/5默认的output intent是CMYK的Color Space,所以调用fit_textline函数写文字时,就会抛异常“RGB Color Space requires suitable output intent in pdf/x-3/4/5”。
PDF/X是PDF的一种特殊规格,它比普通PDF规格多一些限制,详见Wiki。
以下是pdflib列出的一些PDF/X的限制:
PDF/X Some options are restricted.
PDF/X-1a: RGB images are notallowed.
PDF/X-1a/3: JBIG2 images are notallowed.
PDF/X-3/4/5: Grayscale imagesrequire that the defaultgray option in PDF_begin_page_
ext( ) must have been set unless theoutput intent is a grayscale or CMYK device.
RGB images require that thedefaultrgb option in PDF_begin_page_ext( ) must have
been set unless the output intent isan RGB device.
CMYK images require that thedefaultcmyk option in PDF_begin_page_ext( ) must
have been set unless the outputintent is a CMYK device.
JPEG 2000 images must satisfycertain conditions; see PDFlib Tutorial for details.
【解决办法】
if(g_lPDFSyle== NS_PDF_X3 || g_lPDFSyle == NS_PDF_X4 || g_lPDFSyle == NS_PDF_X5)
{
TCHARoptlist[MAX_PATH]=_T("");
int icc = pPdf->load_iccprofile(TEXT("sRGB"), _T(""));
_stprintf(optlist,_T("defaultrgb=%d"), icc);
pPdf->begin_page_ext(fPageW,fPageH,optlist);
}
else
{
pPdf->begin_page_ext(fPageW,fPageH,_T(""));
}