• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

IAC CopyToClipboard worked for years but now fails starting around November 2021 (on Acrobat DC)

New Here ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

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;
}

TOPICS
Acrobat SDK and JavaScript

Views

106

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

Hi

Which operating system and version are you using?

And have you checked that the IDataObject has a bitmap image and not a different image type? (just checking the simple stuff first)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

On Windows 10, Adobe Acrobat DC - fails as stated (even though has worked for a year or more with no code changes.

On Windows 10, Adobe Acrobat XI Pro - works great now and has worked great for a few years.

 

Here are more complex details.

The Visual Studio code builds the app on an Adobe Acrobat XI Pro environment; thus the added reference for Acrobat.dll is from Acrobat XI Pro.  That app is installed on the Acrobat DC system and , somewhat surprisingly, works great until a week ago.  So, I installed Visual Studio on the Acrobat DC system and rebuilt the app which now references the Acrobat.dll from Acrobat DC.  The rebuilt app fails the same way.

Two things broke a week or two ago (with no changes to my code):

1.  if (clipboardData.GetDataPresent(DataFormats.Bitmap)) is always false

2.  pdDocTarget.Save((short)PDSaveFlags.PDSaveFull, targetFilespec)  <--- always returns false now!!!

Note that other function still work no matter which version of Acrobat is used for builds.  For example, 

int ctrPagesInSource = pdDocSource.GetNumPages(); ,<--- still works

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2021 Nov 26, 2021

Copy link to clipboard

Copied

LATEST

A third party product provides the function I need using this code with their product.

Their product is not free so I have not purchased the full product yet since I still hope Adobe can fix the bug.

/// <summary>
/// Gets cropped page image.  
/// Cropping to remove a portion of top page is necessary because a FAX header at the top causes identical pages to seem not identical!
        public Image getCroppedImageFromPdfPage(PdfDocument pdfDoc, int pagenum, float numberTopInchesToCrop)
        {
            // Convert page to Image!
            Image wholeImage = pdfDoc.SaveAsImage(pagenum - 1);
            // Remember Pages[0] is page 1; Pages[n-1] is page n
            PdfPageBase page = pdfDoc.Pages[pagenum - 1];
            float wholeImageHeightPixels = wholeImage.Height;
            // Canvas is drawing surface of pdf document page
            // 1 inch = 72 points
            float canvasHeightInches = page.Canvas.Size.Height / 72f;
            // formula:
            float imagePixelsPerInch = wholeImageHeightPixels / canvasHeightInches;

            float numberTopPixelsToCrop = numberTopInchesToCrop * imagePixelsPerInch;
            Bitmap croppedImage = new Bitmap(wholeImage.Width, wholeImage.Height - (int)numberTopPixelsToCrop);
            Graphics graphics = Graphics.FromImage(croppedImage);
            RectangleF sourceRect = new RectangleF(0, (int)numberTopPixelsToCrop, wholeImage.Width, wholeImage.Height - (int)numberTopPixelsToCrop);
            RectangleF destinationRect = new RectangleF(0, 0, wholeImage.Width, wholeImage.Height - (int)numberTopPixelsToCrop);
            graphics.DrawImage(wholeImage, destinationRect, sourceRect, GraphicsUnit.Pixel);
            return (Image)croppedImage;
        }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines