How to Make Graphics and Images Transparent
Knowledge Base :: PDF Creator Pilot 4 Knowledge Base

See Also Example
Collapse All

PDF Creator Pilot allows you to use opacity, to work in blend mode, and to load images with a color or image mask.

To use opacity for drawing text and graphics:

1) Draw a background (any text and/or graphics), if needed.

2) Call the SetOpacityFill, SetOpacityStroke, or SetOpacity method.

3) Draw any foreground. All paintings will now reflect the opacity level you have set.

 

To use blend mode you will need:

1) Draw a background (any text and/or graphics), if needed.

2) Call method SetBlendMode.

3) Draw any foreground. All paintings now will consider blend mode you have set.

 

To use transparent images you will need:

1) Draw a background (any text and/or graphics), if needed.

2) Load an image with a color or image mask using the AddImageWithColorMask or AddImageWithMask method.

3) Draw the loaded image. The image will be drawn with the transparent color or mask specified.

Example

Using Opacity

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
PDF.SetColorSpaceType(cstDefaultRGB);
PDF.SetLineWidth(10);

{ 1st square }
PDF.SetColorStroke(0, 0, 0, 0);
PDF.SetColorFill(1, 0, 0, 0);
PDF.DrawRectangle(50, 50, 100, 100, 0);
PDF.FillAndStroke;

{ 2nd square }
PDF.SetColor(0, 0, 1, 0);
PDF.SetOpacityStroke(0.2);
PDF.SetOpacityFill(0.8);
{ or just set the same opacity level for
  both colors, call:
   PDF.SetOpacity(0.5); }
PDF.DrawRectangle(100, 100, 100, 100, 0);
PDF.FillAndStroke;

PDF.SetColorStroke(0, 1, 0, 0);
PDF.SetColorFill(0.2, 0.2, 1, 0);
PDF.DrawRectangle(100, 100, 100, 100, 0);
PDF.FillAndStroke;

PDF.SaveToFile('test.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created
PDF->SetColorSpaceType(cstDefaultRGB);
PDF->SetLineWidth(10);

//1st square
PDF.SetColorStroke(0, 0, 0, 0);
PDF.SetColorFill(1, 0, 0, 0);
PDF.DrawRectangle(50, 50, 100, 100, 0);
PDF.FillAndStroke();

//2nd square
PDF->SetColor(0, 0, 1, 0);
PDF->SetOpacityStroke(0.2f);
PDF->SetOpacityFill(0.8f);
// or just set the same opacity level for
// both colors, call:
//  PDF->SetOpacity(0.5f);
PDF->DrawRectangle(100, 100, 100, 100, 0);
PDF->FillAndStroke();

PDF->SetColorStroke(0, 1, 0, 0);
PDF->SetColorFill(0.2f, 0.2f, 1, 0);
PDF->DrawRectangle(100, 100, 100, 100, 0);
PDF->FillAndStroke();

PDF->SaveToFile("test.pdf", true);
C#
[copy to clipboard]
// PDF object is supposed to be created
PDF.SetColorSpaceType(ColorSpaceType.cstDefaultRGB);
PDF.SetLineWidth(10);

//1st square
PDF.SetColorStroke(0, 0, 0, 0);
PDF.SetColorFill(1, 0, 0, 0);
PDF.DrawRectangle(50, 50, 100, 100, 0);
PDF.FillAndStroke();

//2nd square
PDF.SetColor(0, 0, 1, 0);
PDF.SetOpacityStroke(0.2);
PDF.SetOpacityFill(0.8);
// or just set the same opacity level for
// both colors, call:
//  PDF.SetOpacity(0.5);
PDF.DrawRectangle(100, 100, 100, 100, 0);
PDF.FillAndStroke();

PDF.SetColorStroke(0, 1, 0, 0);
PDF.SetColorFill(0.2, 0.2, 1, 0);
PDF.DrawRectangle(100, 100, 100, 100, 0);
PDF.FillAndStroke();

PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
PDF.SetColorSpaceType 1 'ColorSpaceType.cstDefaultRGB
PDF.SetLineWidth 10

'1st square
PDF.SetColorStroke 0, 0, 0, 0
PDF.SetColorFill 1, 0, 0, 0
PDF.DrawRectangle 50, 50, 100, 100, 0
PDF.FillAndStroke

'2nd square
PDF.SetColor 0, 0, 1, 0
PDF.SetOpacityStroke 0.2
PDF.SetOpacityFill 0.8
'' or just set the same opacity level for
'' both colors, call:
''  PDF.SetOpacity 0.5
PDF.DrawRectangle 100, 100, 100, 100, 0
PDF.FillAndStroke

PDF.SetColorStroke 0, 1, 0, 0
PDF.SetColorFill 0.2, 0.2, 1, 0
PDF.DrawRectangle 100, 100, 100, 100, 0
PDF.FillAndStroke

PDF.SaveToFile "test.pdf", true
Using Blend Mode

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }

{ Declaration:

  const
    blendModeNames: array[0..15] of PChar = (
      'Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten',
      'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference',
      'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity');
  var
    fLeft, fTop, fWidth, fHeight : Single;
    rowShift, columnShift : Single;
    row, column : integer;
}

fLeft := 50.0;
fTop := 50.0;
fWidth := 50.0;
fHeight := 50.0;

for row := 0 to 2 do
begin
    rowShift := row * height * 2;
    for column := 0 to 4 do
    begin
        PDF.SetBlendMode(bmNormal);
        columnShift := column * (fWidth * 1.5);

        PDF.SetColorFill(0, 0, 0, 0);
        PDF.ShowTextAt(fLeft + columnShift, fTop + rowShift - 20, blendModeNames[column + 5 * row]);

        PDF.SetColorFill(0.9, 0.6, 0.1, 0);
        PDF.DrawRectangle(fLeft + columnShift, fTop + rowShift, fWidth, fHeight, 0);
        PDF.Fill;

        PDF.SetBlendMode(column + 5 * row);

        PDF.SetColorFill(0.5, 0.5, 1.0, 0);
        PDF.DrawRectangle(fLeft + columnShift + fWidth / 3, fTop + rowShift + fHeight / 3, fWidth, fHeight, 0);
        PDF.Fill;
    end;
end;

PDF.SaveToFile('TestBlendModes.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created

string blendModeNames[] = { "Normal", "Multiply", "Screen", "Overlay",
    "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight",
    "Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity" };

float fLeft = 50.0f;
float fTop = 50.0f;
float fWidth = 50.0f;
float fHeight = 50.0f;

for (int row = 0; row < 3; row++)
{
    float rowShift = row * height * 2;
    for (int column = 0; column < 5; column++)
    {
        PDF->SetBlendMode(bmNormal);

        float columnShift = column * (fWidth * 1.5f);

        PDF->SetColorFill(0, 0, 0, 0);
        PDF->ShowTextAt(fLeft + columnShift, fTop + rowShift - 20, blendModeNames[column + 5 * row]);

        PDF->SetColorFill(0.9f, 0.6f, 0.1f, 0);
        PDF->DrawRectangle(fLeft + columnShift, fTop + rowShift, fWidth, fHeight, 0);
        PDF->Fill();

        PDF->SetBlendMode((BlendMode)(column + 5 * row));

        PDF->SetColorFill(0.5f, 0.5f, 1.0f, 0);
        PDF->DrawRectangle(fLeft + columnShift + fWidth / 3, fTop + rowShift + fHeight / 3, fWidth, fHeight, 0);
        PDF->Fill();
    }
}

PDF->SaveToFile("TestBlendModes.pdf", true);
C#
[copy to clipboard]
// PDF object is supposed to be created

string[] blendModeNames = new string[] { "Normal", "Multiply", "Screen", "Overlay",
    "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight",
    "Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity" };

BlendMode[] blendModes = new BlendMode[] { BlendMode.bmNormal, BlendMode.bmMultiply, BlendMode.bmScreen,
    BlendMode.bmOverlay, BlendMode.bmDarken, BlendMode.bmLighten, BlendMode.bmColorDodge,
    BlendMode.bmColorBurn, BlendMode.bmHardLight, BlendMode.bmSoftLight, BlendMode.bmDifference,
    BlendMode.bmExclusion, BlendMode.bmHue, BlendMode.bmSaturation, BlendMode.bmColor, BlendMode.bmLuminosity };

float fLeft = 50.0f;
float fTop = 50.0f;
float fWidth = 50.0f;
float fHeight = 50.0f;

for (int row = 0; row < 3; row++)
{
    float rowShift = row * fHeight * 2;
    for (int column = 0; column < 5; column++)
    {
        PDF.SetBlendMode(BlendMode.bmNormal);
        float columnShift = column * (fWidth * 1.5f);

        PDF.SetColorFill(0, 0, 0, 0);
        PDF.ShowTextAt(fLeft + columnShift, fTop + rowShift - 20, blendModeNames[column + 5 * row]);

        PDF.SetColorFill(0.9f, 0.6f, 0.1f, 0);
        PDF.DrawRectangle(fLeft + columnShift, fTop + rowShift, fWidth, fHeight, 0);
        PDF.Fill();

        PDF.SetBlendMode(blendModes[column + 5 * row]);

        PDF.SetColorFill(0.5f, 0.5f, 1.0f, 0);
        PDF.DrawRectangle(fLeft + columnShift + fWidth / 3, fTop + rowShift + fHeight / 3, fWidth, fHeight, 0);
        PDF.Fill();
    }
}

PDF.SaveToFile("TestBlendModes.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created

Dim blendModeNames(16)
blendModeNames(1) = "Normal"
blendModeNames(2) = "Multiply"
blendModeNames(3) = "Screen"
blendModeNames(4) = "Overlay"
blendModeNames(5) = "Darken"
blendModeNames(6) = "Lighten"
blendModeNames(7) = "ColorDodge"
blendModeNames(8) = "ColorBurn"
blendModeNames(9) = "HardLight"
blendModeNames(10) = "SoftLight"
blendModeNames(11) = "Difference"
blendModeNames(12) = "Exclusion"
blendModeNames(13) = "Hue"
blendModeNames(14) = "Saturation"
blendModeNames(15) = "Color"
blendModeNames(16) = "Luminosity"

fLeft = 50
fTop = 50
fWidth = 50
fHeight = 50

for row = 0 To 2
    rowShift = row * fHeight * 2
    for column = 0 To 4
        PDF.SetBlendMode 0' bmNormal
        columnShift = column * (fWidth * 1.5)

        PDF.SetColorFill 0, 0, 0, 0
        PDF.ShowTextAt fLeft + columnShift, fTop + rowShift - 20, blendModeNames(column + 5 * row + 1)

        PDF.SetColorFill 0.9, 0.6, 0.1, 0
        PDF.DrawRectangle fLeft + columnShift, fTop + rowShift, fWidth, fHeight, 0
        PDF.Fill

        PDF.SetBlendMode column + 5 * row

        PDF.SetColorFill 0.5, 0.5, 1.0, 0
        PDF.DrawRectangle fLeft + columnShift + fWidth / 3, fTop + rowShift + fHeight / 3, fWidth, fHeight, 0
        PDF.Fill
    next
next

PDF.SaveToFile "TestBlendModes.pdf", true
Loading an Image with a Color Mask

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
clr := 255; { 255=x0000FF - red color }
ind := PDF.AddImageWithColorMask('picture.gif', clr);
PDF.ShowImage(ind, 0, 0);
PDF.SaveToFile('test.pdf', true);Loading an Image with a Color Mask
C/C++
[copy to clipboard]
// PDF object is supposed to be created
long clr = 255; //255=0x0000FF - red color
long ind = PDF->AddImageWithColorMask("picture.gif", clr);
PDF->ShowImage(ind, 0, 0);
PDF->SaveToFile("test.pdf", true);
C#
[copy to clipboard]
// PDF object is supposed to be created
long clr = 255; //255=0x0000FF - red color
long ind = PDF.AddImageWithColorMask("picture.gif", clr);
PDF.ShowImage(ind, 0, 0);
PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
clr = 255 '255=0x0000FF - red color
ind = PDF.AddImageWithColorMask("picture.gif", clr)
PDF.ShowImage ind, 0, 0
PDF.SaveToFile "test.pdf", true
Loading an Image with a Mask

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
ind := PDF.AddImageWithMask('picture.tiff', 'mask.tiff');
PDF.ShowImage(ind, 0, 0);
PDF.SaveToFile('test.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created
long ind = PDF->AddImageWithMask("picture.tiff", "mask.tiff");
PDF->ShowImage(ind, 0, 0);
PDF->SaveToFile("test.pdf", true);
C#
[copy to clipboard]
// PDF object is supposed to be created
long ind = PDF.AddImageWithMask("picture.tiff", "mask.tiff");
PDF.ShowImage(ind, 0, 0);
PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
ind = PDF.AddImageWithMask("picture.tiff", "mask.tiff")
PDF.ShowImage ind, 0, 0
PDF.SaveToFile "test.pdf", true

See Also

Reference