C#
/* --------------------------------------------------------------------------------
* <copyright file="Program.cs" company="Global Graphics Software Ltd">
* Copyright (c) 2024 Global Graphics Software Ltd. All rights reserved.
* </copyright>
* <summary>
* This example is provided on an "as is" basis and without warranty of any kind.
* Global Graphics Software Ltd. does not warrant or make any representations
* regarding the use or results of use of this example.
* </summary>
* ---------------------------------------------------------------------------------
*/
using JawsMako;
namespace RenderWithAlpha;
internal class Program
{
static int Main()
{
try
{
var testFilepath = @"..\..\..\..\TestFiles\";
var mako = IJawsMako.create();
IJawsMako.enableAllFeatures(mako);
// Input
var pdfInput = IPDFInput.create(mako);
using var assembly = pdfInput.open(testFilepath + "BeerLabels.pdf");
using var inFixedPage = assembly.getDocument().getPage()
.getContent();
double dpi = 144;
var destWidth = (uint)(inFixedPage.getWidth() / 96.0 * dpi);
var destHeight = (uint)(inFixedPage.getHeight() / 96.0 * dpi);
var rgbSpace = IDOMColorSpaceDeviceRGB.create(mako);
var renderer = IJawsRenderer.create(mako);
var separations = renderer.renderSeparations(inFixedPage, 8, rgbSpace, 4,
new FRect(), destWidth, destHeight, new CEDLVectWString(), IOptionalContent.Null(),
eOptionalContentEvent.eOCEPrint, new CEDLVectWString(), true);
// Save the alpha channel
var alpha = separations[3];
// Just the RGB channels
separations.resize(3);
IDOMImage rgbImage = IDOMRecombineImage.create(mako, rgbSpace, separations);
IDOMImage image = IDOMRecombineAlphaImage.create(mako, rgbImage, alpha);
IDOMPNGImage.encode(mako, image, IOutputStream.createToFile(mako, "BeerLabels.png"));
}
catch (MakoException e)
{
Console.WriteLine($"Exception thrown: {e.m_errorCode}: {e.m_msg}");
}
catch (Exception e)
{
Console.WriteLine($"Exception thrown: {e}");
}
return 0;
}
}