Skip to main content
Participating Frequently
July 19, 2025
Question

Icon load issue

  • July 19, 2025
  • 1 reply
  • 110 views

In my Adobe plugin I am trying oad the toolbar icon like this ASPathName pn = ASFileSysCreatePathFromCString( ASGetDefaultFileSys(), settings.logoFilename );

PDDoc doc = PDDocOpen( pn, ASGetDefaultFileSys(), NULL, false );

AVIcon icon1 = AVIconCreateFromPDF( doc, 0, 24, 24 );

AVIcon icon2 = AVIconCreateFromPDF( doc, 1, 24, 24 );

AVToolBarSetIcon( mainToolbar, icon1, icon2 ); but the problem is since the icons are taken from a pdf, the white background of the pdf also appears in the icon. I don't have a perfectly square icon. It has irregular shape. So how to make only the image part of the pdf come in as a icon

1 reply

Participant
August 4, 2025
quote

In my Adobe plugin I am trying oad the toolbar icon like this ASPathName pn = ASFileSysCreatePathFromCString( ASGetDefaultFileSys(), settings.logoFilename );

PDDoc doc = PDDocOpen( pn, ASGetDefaultFileSys(), NULL, false );

AVIcon icon1 = AVIconCreateFromPDF( doc, 0, 24, 24 );

AVIcon icon2 = AVIconCreateFromPDF( doc, 1, 24, 24 );

AVToolBarSetIcon( mainToolbar, icon1, icon2 ); but the problem is since the icons are taken from a pdf, the white background of the pdf also appears in the icon. I don't have a perfectly square icon. It has irregular shape. So how to make only the image part of the pdf come in as a icon


By CredibleBH @brilliant_care1058

Based on your description, the issue is that the white background of the PDF is being included in the `AVIcon` you create, because `AVIconCreateFromPDF` essentially takes a snapshot of the entire page content. To achieve the desired effect of having only the image part of the PDF with an irregular shape as the icon, you need to provide an alpha channel (transparency) mask.

Here's a breakdown of the problem and the general solution approach:

**The Problem:**

* `AVIconCreateFromPDF` is designed to render a PDF page into an icon. A PDF page is a rectangular canvas. If the content on that page doesn't fill the entire rectangle, the default background color (usually white) will be included in the resulting image.
* The `AVIcon` structure in the Acrobat SDK uses a `AVIconCreateWithMask` function to support icons with transparency. This function requires an icon and a mask. The mask is a bitmap that defines the transparent and opaque parts of the icon.

**The Solution:**

Instead of directly using `AVIconCreateFromPDF`, you need to:

1. **Extract the Image from the PDF:** This is the core task. You can't just "cut out" the image. You'll need to parse the PDF content stream to find the image objects.
2. **Create an Icon from the Extracted Image:** Once you have the image data (and its transparency information), you can use it to create an `AVIcon`.
3. **Create a Mask:** If the image itself doesn't have an alpha channel, you'll have to create a separate mask bitmap. This mask will be a 1-bit or 8-bit image where one color (e.g., black) represents the opaque parts of your icon and another color (e.g., white) represents the transparent parts.

**A More Concrete Approach (and a likely path for your plugin):**

A common and often easier way to handle this is to use a more modern image format that supports transparency, like PNG, and bundle that with your plugin.

1. **Convert Your Icon PDF to PNG:** Use an external tool (like Photoshop, GIMP, or an open-source library like ImageMagick) to convert your icon PDFs to PNG files with a transparent background. Make sure the background is truly transparent, not just white.
2. **Load the PNG as a Bitmap:** In your plugin, instead of opening the PDF, load the PNG file as a bitmap. The Acrobat SDK provides functions to work with bitmaps.
3. **Create an AVIcon from the Bitmap with a Mask:** You'll use functions like `AVIconCreateWithMask` or similar functions that can handle a bitmap with an alpha channel. This function would take your PNG's color data and alpha channel data to create the transparent icon.

**Example Code Snippet (Conceptual - not a copy-paste solution):**

```c++
// Assuming you have a PNG file with transparency
// This is a conceptual example, the actual functions might be different
// You'll need to find the correct SDK functions for loading PNGs and
// handling alpha channels.

// 1. Create an ASPathName to your PNG file
ASPathName pngPath = ASFileSysCreatePathFromCString( ASGetDefaultFileSys(), "my_icon.png" );

// 2. Load the PNG data into memory or a bitmap structure
// Let's assume you have a function that does this.
MyBitmapData* iconBitmap = loadPNGFile( pngPath );

// 3. Create the AVIcon using a function that supports transparency.
// The SDK has functions like `AVIconCreateWithMask` or `AVIconCreateWithAlpha`.
// You'll need to get the bitmap data and the mask data (alpha channel).
AVIcon icon1 = AVIconCreateWithAlpha( iconBitmap->data, iconBitmap->alphaMask, 24, 24 );

// 4. Set the icon to the toolbar
AVToolBarSetIcon( mainToolbar, icon1, NULL ); // Or set icon2 as well
```

**Where to Look in the Adobe Acrobat SDK:**

* **`AVIcon` Functions:** Look for functions like `AVIconCreateFromBitmap`, `AVIconCreateWithMask`, and `AVIconCreateWithAlpha`. These are the key to creating icons with transparency.
* **Bitmap Handling:** Explore the `ASFixedBitmap` and related structures. The SDK provides functions for creating and manipulating bitmaps. You might need to write your own code to read the PNG file format and populate these structures.
* **PDF Parsing (Advanced):** If you absolutely must get the icon from a PDF, you'll need to delve into the PDF content stream to find the image objects (`/XObject` of type `/Image`). This is significantly more complex and requires a deep understanding of the PDF specification.

**Recommendation:**

The easiest and most robust solution is to use a PNG file with transparency. It simplifies the development process and is a standard way to handle icons with irregular shapes. Use a tool to convert your PDFs to transparent PNGs and then use the appropriate Adobe Acrobat SDK functions to load the PNG data and create the `AVIcon` with an alpha channel.