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);
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,
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
@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.
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
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.