IAC CopyToClipboard worked for years but now fails starting around November 2021 (on Acrobat DC)
I have used IAC to copy pdf page image to the clipboard. Here is the code that no longer works (it was working for a long time until a week ago). The code still works on our old Acrobat XI Pro systems; it fails on Acrobat DC systems. The exception is always thrown. Does anyone know what happened or how I can solve the problem?
private Image getImageFromDocPage(CAcroPDPage pdfPage)
{
Image img = null;
CAcroRect pdfRect = new Acrobat.AcroRect(); // the pdf region
CAcroPoint pdfPoint = new Acrobat.AcroPoint(); // the pdf point
pdfPoint = (CAcroPoint)pdfPage.GetSize();
pdfRect.Left = 0;
// Tricky! Faxed documents have a fax 'header' at the top of each page which makes the pages different even though the contents are actually identical!
// A point = 1/72 inch.
short topPortionToIgnoreUnitsPoints = 8;
/*
if (radioButtonIgnoreTop8Points.Checked) { topPortionToIgnoreUnitsPoints = 8; }
if (radioButtonIgnoreTop12Points.Checked) { topPortionToIgnoreUnitsPoints = 12; }
if (radioButtonIgnoreTop18Points.Checked) { topPortionToIgnoreUnitsPoints = 18; }
if (radioButtonIgnoreTop24Points.Checked) { topPortionToIgnoreUnitsPoints = 24; }
if (radioButtonIgnoreTop36Points.Checked) { topPortionToIgnoreUnitsPoints = 36; }
*/
pdfRect.Top = topPortionToIgnoreUnitsPoints;
pdfRect.right = pdfPoint.x;
pdfRect.bottom = pdfPoint.y;
pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);
//Constants.displayInformationMessage("Copied 1st page to clipboard!");
//
IDataObject clipboardData = Clipboard.GetDataObject();
if (clipboardData.GetDataPresent(DataFormats.Bitmap))
{
Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
img = (Image)pdfBitmap;
}
else
{
throw new Exception("Error. Unable to process image data in the pdf documents.");
}
return img;
}
