EMF to PDF\A

Hi,

I am working with Aspose 9.3 ver. In my application I’m trying to convert an EMF file to PDF with compliance (PDF\A), but the output doesn’t seem to recognize the appropriate font/encoding and Also,the generated PDF\A output file has black back ground.

I have gone through Issues: 22077 (Unresolved) in this forum and got that you did some work around for PDF and it’s working fine. Could you please do the same for PDF\A ?

Here is the my code:

Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
docBuilder.PageSetup.LeftMargin = ConvertUtil.MillimeterToPoint(8);
docBuilder.PageSetup.RightMargin = ConvertUtil.MillimeterToPoint(8);

using (System.Drawing.Image image = System.Drawing.Image.FromFile(emfFilePath))
{
    int framesCount = image.GetFrameCount(FrameDimension.Page);
    for (int indx = 0; indx < framesCount; indx++)
    {
        if (indx != 0)
            docBuilder.InsertBreak(BreakType.SectionBreakNewPage);

        image.SelectActiveFrame(FrameDimension.Page, indx);

        PageSetup pgsetup = docBuilder.PageSetup;
        pgsetup.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
        pgsetup.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);

        docBuilder.InsertImage(image,
            RelativeHorizontalPosition.Page,
            0,
            RelativeVerticalPosition.Page,
            0,
            pgsetup.PageWidth,
            pgsetup.PageHeight,
            WrapType.None);
    }
}

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

foreach (Shape shape in shapes)
{
    if (shape.HasImage && (shape.ImageData.ImageType == ImageType.Emf))
    {
        using (MemoryStream vectorImageStream = new MemoryStream(shape.ImageData.ImageBytes))
        using (Image image = Image.FromStream(vectorImageStream))
        using (MemoryStream resterImageStream = new MemoryStream())
        {
            image.Save(resterImageStream, ImageFormat.Png);
            shape.ImageData.SetImage(resterImageStream);
        }
    }
}

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.SaveFormat = SaveFormat.Pdf;
pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
pdfSaveOptions.JpegQuality = 100;
string outPDFFilePath = Path.ChangeExtension(emfFilePath, ".pdf");
doc.Save(outPDFFilePath, pdfSaveOptions);

Thanks
Gourav

Hi
Thanks for your request. Could you please attach your EMF image here for testing. We will check it and provide you more information.
Most probably there is a transparent background, and since PDF/A compliance does not allow using transparency, it becomes black. You can try to convert your EMF image to image format that does nto support transparency, JPEG for example. This might help you to resolve the problem.
Best regards,

Thanks ALEXEY ,

Please find sample EMF file as attachment. I tried with JPEG image also but no luck. it’s still giving black back ground.

thanks
Gourav

Hi
Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Regarding black background – it is not a bug in Aspose.Words. You are using System.Drawing to convert metafile to raster image. During converting transparent background becomes black. So, you should wait for the fix of the original issue.
Best regards,

Hi,
FYI: I have very complex EMF images (including layered transparent WMF in the EMF) and I generate PDF/A and in fact all document types without any problems. These end up on the wall so need to scale very accurately. They work fine!
Regards, Bruce

Thanks all,

@Bruce: could you please send me sample code of your’s … I would be vary thankful to you. Or you can looked into my code and suggest me any thing to be replaced, to get the work around.

thanks,
Gourav

Thanks Alexey…

I really like your quick response service. Must appreciated.

thanks
Gourav

Hi,
I see what you are doing. I do not insert each frame of an EMF … I only insert an EMF as one image (I believe internally there are many layers).
The biggest surprise / disappointment I had with .NET was that EMF files are saved as PNGs using the normal .NET file save (at least the last time I checked). I have not been able to save an EMF as an EMF file using .NET.
So, I go directly from drawing and grid controls to EMF images then directly to Aspose.words … they do not get saved.
Regards, Bruce

Hi
Here is code that you can use as a temporary workaround of the problem:

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape shape in shapes)
{
    if (shape.HasImage && (shape.ImageData.ImageType == ImageType.Emf))
    {
        using(MemoryStream vectorImageStream = new MemoryStream(shape.ImageData.ImageBytes))
        using(Image vectorImage = Image.FromStream(vectorImageStream))
        using(Bitmap rasterImage = new Bitmap(vectorImage.Width, vectorImage.Height))
        using(Graphics g = Graphics.FromImage(rasterImage))
        {
            g.FillRectangle(Brushes.White, 0, 0, vectorImage.Width, vectorImage.Height);
            g.DrawImage(vectorImage, new Rectangle(0, 0, vectorImage.Width, vectorImage.Height),
                new Rectangle(0, 0, vectorImage.Width, vectorImage.Height), GraphicsUnit.Pixel);
            using(MemoryStream resterImageStream = new MemoryStream())
            {
                rasterImage.Save(resterImageStream, ImageFormat.Png);
                shape.ImageData.SetImage(resterImageStream);
            }
        }
    }
}

Hope this helps. But note that after converting vector image to raster, quality of the image will be worse.
Best regards,

thanks a lot …

it’s a good enough work around.

thanks
Gourav

Hello,

I face a similar “problem”. When converting to PDF/A images with a transparent background, especially PNGs, the background also becomes black. I understand this is “by design” since this format doesn’t support transparency. But maybe you could render the background to white instead of black. Most of the documents we have have white backgrounds.

Best regards,

Hi David,
Thanks for your request. I logged your request in our defect database. We will let you know once the issue is resolved.
Best regards,

The issues you have found earlier (filed as 24630) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as 24621) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.