Copy link to clipboard
Copied
I have created an Acrobat Plugin using Visual Studio 2013 and C++.
In that plugin, I am doing the following:
The saved document has the 2 images with the proper values (bit depth, dimensions), except for 'Filters'. The 1-bit monochrome image shows JBIG2 as a filter, but I want to use CCITT.
Can I change the compression for a PDEImage element before I save the PDF file?
Note: I am not using PDEImageCreate because AVConversionConvertToPDF handles all types of image formats already. The resulting PDF file is fine, except for the image's compression.
Copy link to clipboard
Copied
Update: I just found out that the use of JBIG2 compression was based on the Preferences / Convert to PDF / TIF settings.
I can change it there to CCITT and get what I want.
Now, how can I change that value programmatically?
Or my original question still stands: How can I convert the PDEImage to be CCITT encoded?
Copy link to clipboard
Copied
You can change the settings in the AVConversionConvertToPDF API call to specify which compression algorithm to use
Copy link to clipboard
Copied
Thanks for the reply.
I looked at the function closer, and see no settings options like compression algorithms. The AVConversionConvertToPDF method has 5 parameters:
flags, for thing like asynchronous operation or display or not display dialogs.
inPath, for the input filename
inFileSys, for the input file system (looks promising but I see nothing regards to compression)
outPDDoc, for the output PDDoc
statusMonitor, for a status monitor.
Where would I change the compression specification?
Copy link to clipboard
Copied
In the ASCab of settings.
Copy link to clipboard
Copied
Thank you again. I hate to sound dense, but in the ASCab of what?
I do not see an ASCab or 'Settings' in the AVConversionConvertToPDF method.
Would it be possible to provide me with a few lines of pseudo code?
Copy link to clipboard
Copied
There is an example in the SDK of using this API which shows off how to change setttings…
Copy link to clipboard
Copied
Thanks again for the reply. I had looked at the SDK but found nothing extra for AVConversionConvertToPDF.
But looking further, it appears that AVConversionConvertToPDFWithHandler has the ASCab settings parameter you spoke of.
So I assume I have to use AVConversionEnumToPDFConverters to locate the TIF handler for ToPDF conversions, and use that as the handler for AVConversionConvertToPDFWithHandler. But I still don't know what settings to put into the ASCab settings. I see lots of 'ASCabPut$$$' method examples in the SDK, but nothing I can trace to TIF compression settings.
Copy link to clipboard
Copied
There is a sample in the SDK that shows how to use the AVConversion APIs. It’s called PDFBinder and you will find code in PDFBinder.cpp for how to do all this…and all the possible settings are defined in a header in the SDK (referenced from that sample)
Copy link to clipboard
Copied
The PDFBinder example is where much of my existing code came from. But, I see no call to AVConversionConvertToPDFWithHandler, only AVConversionConvertToPDF. In fact, PDFBinder.cpp has a comment: "It works with function AVConversionConvertToPDFWithHandler. It's not used now, but kept for user's reference."
I am currently looking at AVConversionToPDFHandler.defaultSettings as a means to retrieve the current default settings for the handler. The code looks something like this:
ACCB1 ASBool ACCB2 CDocument::myAVConversionToPDFEnumProc(AVConversionToPDFHandler handler, AVConversionEnumProcData data)
{
for (ASInt32 i = 0; i < handler->convFilter.numFileDescs; i++) {
if (strlen(handler->convFilter.fileDescs.extension) > 0) {
if (!strcmp(handler->convFilter.fileDescs.extension, "tif") ) {
TIFFToPDFHandler = handler;
TIFFToPDFHandlerSettings = handler->defaultSettings(handler->uniqueID, NULL); // Get ASCab for settings?
return false;
}
}
}
return true;
}
However, the ASCab returned by handler->defaultSettings() is NULL. TIFFToPDFXHandler and TIFFHandlerSettings are static members of my class.
Copy link to clipboard
Copied
Another day and no luck. I believe I need to specify the compression settings for AVConversionConvertToPDFWithHandler to achieve what I want, but I have no idea what the setting keys/names are that I need to set. I have not been successful in trying to get the default settings.
Can anyone offer any further direction in figuring out how to get the ASCab with the current settings for things like the 'ToPDF' TIFF compression settings?
Thanks in advance.
Copy link to clipboard
Copied
They are all documented in a header file – I don’t have the name handy right now
Copy link to clipboard
Copied
My final solution was to get the default settings (properly) from the default TIF handler, and then look up those values and how they could be changed. The documentation doesn't really spell this stuff out to well IMHO, especially things like the strings and options to be provided. In any case, what I did is below (thanks again to all who helped):
Some globals:
AVConversionToPDFHandler TIFFToPDFHandler = NULL;
ASCab TIFFToPDFHandlerSettings;
In some init code I call AVConversionEnumToPDFConverters to locate the TIF handler:
AVConversionEnumToPDFConverters(myAVConversionToPDFEnumProc, NULL);
The myAVConversionToPDFEnumProc method stores the TIF handler and TIF ASCab settings in the global variables:
ACCB1 ASBool ACCB2 CDocument::myAVConversionToPDFEnumProc(AVConversionToPDFHandler handler, AVConversionEnumProcData data)
{
for (ASInt32 i = 0; i < handler->convFilter.numFileDescs; i++) {
if (strlen(handler->convFilter.fileDescs.extension) > 0) {
if (!strcmp(handler->convFilter.fileDescs.extension, "tif") ) {
TIFFToPDFHandler = handler;
TIFFToPDFHandlerSettings = handler->defaultSettings(handler->uniqueID, handler->clientData); // Get ASCab for settings?
return false;
}
}
}
return true;
}
At one point, I had used ASCabEnum to get a list of the ASCab settings (TIFFToPDFHandlerSettings from above) , and I found this data in the default ASCab settings:
ColorCompression=7
ColorManagementPolicyCmyk=1
ColorManagementPolicyGray=1
ColorManagementPolicyOther=2
ColorManagementPolicyRgb=2
GrayCompression=7
MonoCompression=10
ScannedImageOpt=N
I then used these names and searched all the SDK files. I found that AvCmdDefs.h contained entries like this:
#define kExtractTiffCmdKeyMonoCompression "MonoCompression"
as well as enums for things like kTiffCompressionCCITT_G4 and kTiffCompressionJpegHigh.
So I ASSUMED that something like this is the proper way to get and setup the ASCab settings:
AVConversionEnumToPDFConverters(myAVConversionToPDFEnumProc, NULL);
ASCabPutInt(TIFFToPDFHandlerSettings, "MonoCompression", kTiffCompressionCCITT_G4);
ASCabPutInt(TIFFToPDFHandlerSettings, "GrayCompression", kTiffCompressionJpegHigh);
ASCabPutInt(TIFFToPDFHandlerSettings, "ColorCompression", kTiffCompressionJpegHigh);
HOWEVER, I found that
ASCabPutInt(TIFFToPDFHandlerSettings, "GrayCompression", kTiffCompressionJpegHigh);
would result in Gray images that were ZIP compressed. I'm not sure why. So, I tried values from 7 to 9 instead of kTiffCompressionJpegHigh (which is 10), and I got my JPEG compression back.
So, my final results were (honestly not sure I need the last line):
ASCabPutInt(TIFFToPDFHandlerSettings, "ColorCompression", ASInt32(9)); // Drop to 7 for lower quality
ASCabPutInt(TIFFToPDFHandlerSettings, "GrayCompression", ASInt32(9));
ASCabPutInt(TIFFToPDFHandlerSettings, "MonoCompression", ASInt32(10));
ASCabPutInt(TIFFToPDFHandlerSettings, "Compression", kJpegCompressionHigh);