Handling transparency

Hello :slight_smile:

I’m using the aspose pdf library mostly to convert pdf to xps/png, or the opposite. It works very well, we (my company) have paid a licence (for 1 developer) back in 2016 and thus are limited to the version 17.4.0 that came out around a year after our purchase.

The problem we currently have is when we try to convert xps files that contain images with transparency.
When creating a new Aspose.Pdf.Document by providing it the path to an xps file:

LoadOptions options = new XpsLoadOptions();
using (var document = new Document(xpsFilePath, options)) // exception at this line
{
// do stuff
}

We are having this error (which I got in french but tried to translate in english) :

App_DispatcherUnhandledException
System.MethodAccessException: Failed attempt of accessing the secured transparency method 'Aspose.Pal.PalBitmap.ParseRgb(System.Drawing.Imaging.BitmapData, Boolean)' to the secured critical method 'System.Runtime.InteropServices.Marshal.Copy(IntPtr, Byte[], Int32, Int32)'.
The assembly 'Aspose.Foundation, Version=17.4.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56' is marked with AllowPartiallyTrustedCallersAttribute, and uses the transparency model of security level 2. If transparency of level 2 is used, all the methods of the AllowPartiallyTrustedCallers assemblies makes transparent secured by default, which may be the cause of this exception.
   at Aspose.Pal.PalBitmap.ParseRgb(BitmapData bitmapData, Boolean isAllowTransparencyToColorHack)
   at Aspose.Pal.PalBitmap.GetPixels(Boolean isConvertTo1Bpp, Boolean isAllowTransparencyToColorHack)
   at ♣  .☻(DrBrush ☻, Page ♥, DrMatrix ♣)
   at ♣  .☻(DrBrush ☻, Page ♥, DrMatrix ♣)
   at ♣  .☻(DrBrush ☻, Boolean ♥, Page ♣, DrMatrix)
   at  .VisitPathStart(ApsPath ☻)
   at Aspose.Rendering.ApsPath.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCanvas.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsCompositeNode.Accept(ApsDocumentVisitor visitor)
   at Aspose.Rendering.ApsPage.Accept(ApsDocumentVisitor visitor)
   at ♠  .☻(List`1 ☻, Document ♥, LoadOptions ♣, Boolean)
   at ☼?? .☻(Stream ☻, Document ♥, XpsLoadOptions ♣, Boolean)
   at Aspose.Pdf.Document.☻(Stream ☻, LoadOptions ♥)
   at Aspose.Pdf.Document..ctor(String filename, LoadOptions options)

Currently we are getting around this error by removing the transparency of the image prior to the xps conversion to a pdf file.

My question is, do you know if this issue can be prevented while keeping the transparency of the image ? Is this maybe a known issue that have been fixed in a future version of Aspose.Pdf ?

Thank you for your time,
Gilles

@GillesAvrillier

Would you kindly share the problematic XPS file with us so that we can test the scenario in our environment and share our feedback with you accordingly.

Hello, sorry for the delay

You’ll find an example of an XPS file that I cannot load using the provided bit of code

file with transparent image.zip (282.7 KB)

@GillesAvrillier

We tested the scenario in our environment while using Aspose.PDF for .NET 20.5 and were unable to notice any issue. The PDF file was generated without any issue and has been attached for your reference as well. Would you please try using latest version of the API and in case you still face any issue, please feel free to let us know.

out20.5.pdf (203.3 KB)

I already tried to use the latest version of Aspose.PDF but the licence I’m currently using has expired in 2017. I’m stuck with 17.4.0 until I buy a new licence.
So there are no solutions other than getting the latest version?

@GillesAvrillier

We would like to share with you that support is provided on the basis of latest version and we always recommend our customers to use latest version because it contains more fixes and improvements. If the issue is not persisting with latest version of the API, we request you to upgrade your API version. In case your license is expired, you can get a temporary license to evaluate the API with latest version features and then make the decision accordingly.

Ok thank you for your time, I’ll try the temporary license then