I’ve come across some weird behavior when converting a PDF to PDF/A which contains a image with a transparent background.
Things I’ve notice.
- Removing the stamps, shows a scaled up image that has a cropped box at the bottom.
- Removing the Pdf.License converts the document perfectly.
- If you save the non converted PDF the image will display.
Here an example which produces the problem, with an attached exmaple png which has a transparent background.
var image = Image.Load(“exmaple.png”, new LoadOptions { DataRecoveryMode = DataRecoveryMode.ConsistentRecover });
var imageStream = new MemoryStream();
image.Save(imageStream);
var pdfDocument = new Document
{
HideMenubar = true,
HideToolBar = true,
DisplayDocTitle = true,
IsLinearized = true,
OptimizeSize = true,
EmbedStandardFonts = true
};
pdfDocument.OptimizeResources(new Document.OptimizationOptions
{
CompressImages = true,
RemoveUnusedStreams = true,
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
ImageQuality = 80
});
pdfDocument.PageInfo.Margin.Top = pdfDocument.PageInfo.Margin.Bottom = pdfDocument.PageInfo.Margin.Left = pdfDocument.PageInfo.Margin.Right = 200;
pdfDocument.PageInfo.Width = (float)Math.Ceiling(ConvertUtil.PixelToPoint(image.Width, 96.0) + pdfDocument.PageInfo.Margin.Top + pdfDocument.PageInfo.Margin.Bottom);
pdfDocument.PageInfo.Height = (float)Math.Ceiling(ConvertUtil.PixelToPoint(image.Height, 96.0) + pdfDocument.PageInfo.Margin.Left + pdfDocument.PageInfo.Margin.Right);
var pdfImage = new Aspose.Pdf.Image();
var page = pdfDocument.Pages.Add();
page.Paragraphs.Add(pdfImage);
pdfImage.ImageStream = imageStream;
var stamp = new TextStamp(“TEST STAMP”);
stamp.TextState.Font = FontRepository.FindFont(“Helvetica”);
stamp.TextState.FontStyle = FontStyles.Regular;
stamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
stamp.TextState.FontSize = 8.0F;
stamp.TopMargin = 5;
stamp.LeftMargin = 10;
stamp.VerticalAlignment = VerticalAlignment.Bottom;
stamp.HorizontalAlignment = HorizontalAlignment.Left;
page.AddStamp(stamp);
pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
pdfDocument.Save(“output.pdf”, SaveFormat.Pdf);