#1 2011-06-09 07:05:44

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Convert EMF-Files to PDF/A-Files in Delphi 6

Hi to all,

I'm new to the PDF Engine and it looks like a really great
component!
One of the best components you can get for free, I think.

(Is it correct, that you can use it for free even in
commercial projects?)

I'm now looking for code-examples to convert EMF-Files to PDF/A-Files in Delphi 6

Maybe somebody has an example for this?

Thanks in advance!

Don

Offline

#2 2011-06-09 14:03:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

You can use it for free even in commercial projects, thanks to the MPL license.
See http://synopse.info/forum/viewtopic.php?id=27

Here is some code, adapted from the  procedure TTestSynopsePDF._TPdfDocumentGDI regression test included in SynSelfTests:

  with TPdfDocument.Create do
  try
    // force PDFA/1 file format
    PDFA1 := true;
    // add a page with a metafile on it
    AddPage;
    MF := TMetaFile.Create;
    try
      MF.LoadFromFile(aMetaFileName);
      Canvas.RenderMetaFile(MF); // use Scale, XOff, YOff parameters for layout on page
    finally
      MF.Free;
    end;
    // save resulting PDF
    SaveToFile('destination.pdf');
  finally
    Free;
  end;

You can add a loop in order to add one emf file per page, if you want.

This code sounds not so difficult to follow, doesn't it?
smile

Offline

#3 2011-06-10 14:20:11

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Thanks a lot for the code!

I'm trying it with an example emf-file, but I get an EZeroDivide-Exception
in procedure "ScaleMatrix" in SynPdf.pas

I just replaced the var "aMetaFileName" with a full path to my example-emf-file.

I didn't change anything else from your code.

Don't know what I'm doing wrong?
Maybe this is the same problem: http://synopse.info/forum/viewtopic.php?id=257   ?



PS: God save the MPL license!  :-)

Offline

#4 2011-06-10 16:12:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

How is your emf file produced?

What does it contain?

Did you open it with EmfExplorer tool?
See http://frazmitic.free.fr/emfexplorer

Could you post it in some place, so that I could see it?

Offline

#5 2011-06-14 08:10:13

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

I create EMF-Files mit Parts of the "Virtual Printer" from mabuse.de (http://www.mabuse.de/tech-vprinter.mhtml)

I use this since 2004 in a Delphi 4 - Projekt. I use only parts of Virtual Printer and as I downloaded
it in 2004 some of the parts were buggy. I fixed all parts I needed and all works great.

You have to set the print-processor of any printer-driver to emf-output and so with the parts of Virtual Printer
you can "filter" the emf-files out of the spool-files.

We use this to archive documents in our software.

The new request is to save those documents also in other formats like, JPG, TIFF and PDF/A.
So I found your PDF-Engine.
(Maybe I should use your GDI+ to create TIFF or JPG? Is it better than the "normal" components from Graphics.pas or jpeg.pas?)

In my example-emf-file is a little picture and some formatted text. I can open it with EmfExplorer without problems.
You can download the emf-file here: http://www.divshare.com/download/15093007-80e

Thanks!

Offline

#6 2011-06-14 08:42:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

I'll take a look at the emf file soon. Thanks for the link.
mabuse web site still states that their driver is buggy under XP. It could be even worse under Seven. And it won't work on 64 bit OS, I suspect.

About our GDI+ library, it is able to render the EMF with anti-aliasing, so the quality will be much better for JPG or TIFF. But it won't handle any kind of EMF content directly (it's not a 100% covering) - but it does a very good job, even with complex meta files.
And you can use SynGdiPlus to save any bitmap into Jpeg of Tiff, sometimes faster than with the jpeg unit.

Offline

#7 2011-06-14 13:20:26

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

I think I could fix the bugs from Virtual Printer. I had some conversation with mabuse.de in 2004 telling
them about the bugs and they wanted to fix the code if they get time...
So obviously they hadn't the time till today...

EMF to PDF/A - Error:
If this helps: I get the same error starting your example-project "TestSynGdiPlusMain". I think the problem
is "FormCreate" in line "Gdip := TGDIPlusFull.Create('gdiplus.dll');"
There are several versions of this file on my xp-machine. Maybe this is a problem?

Another question(s) to creating BMP/JPG/TIFF:
I'm trying to convert my TEST.EMF - File to BMP with the functions of SynGdiPlus.pas.
My Code:

   MF := TMetaFile.Create;
   MF.LoadFromFile('TEST.EMF');
   Bmp := Gdip.DrawAntiAliased(MF, 100, 100);
   Bmp.SaveToFile('TEST.BMP');

A correct BMP-File is created but it's size is more than 30 MB. This is of course to big.
(Converting with "normal" Delphi-Units I get a 5 MB - BMP-File.) Probably I did someting wrong again? :-)

How do I convert to JPG and TIFF with SynGdiPlus?  Do you have any examples?

Sorry for asking so much...

Offline

#8 2011-06-14 14:40:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

DonMartin wrote:

If this helps: I get the same error starting your example-project "TestSynGdiPlusMain". I think the problem
is "FormCreate" in line "Gdip := TGDIPlusFull.Create('gdiplus.dll');"
There are several versions of this file on my xp-machine. Maybe this is a problem?

I don't think so. The most advanced one should be located and used by the unit.
But you should call TGDIPlusFull.Create only once per project. Please check it.

DonMartin wrote:

A correct BMP-File is created but it's size is more than 30 MB. This is of course to big.
(Converting with "normal" Delphi-Units I get a 5 MB - BMP-File.) Probably I did someting wrong again? :-)

The BMP size (its width/height) is just bigger than you expected.
Use the ScaleX,ScaleY: integer parameters of TGDIPlus.DrawAntiAliased() to some percent (e.g. 30,30).

DonMartin wrote:

How do I convert to JPG and TIFF with SynGdiPlus?  Do you have any examples?

The easiest way is to use the global SaveAs() procedure in the unit.

Offline

#9 2011-06-16 08:38:15

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Converting to JPG and TIFF works fine now with the global SaveAs() procedure (Sometimes I'm a little too blind...)

I have also no problems now with BMP-Size-Handling...

But I do still get the EZeroDivide-Exception when trying to convert to PDF/A    :-(
TGDIPlusFull.Create is only once called in your example-project "TestSynGdiPlusMain" (I didn't change the code)

Did you have time to look at my example-emf-file?

Thanks again!

Offline

#10 2011-06-17 11:32:25

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

@ab:

I'm trying to use your example creating pdf/a with "ExportPDF" of SQLite3Pages.pas
see: http://synopse.info/forum/viewtopic.php?pid=1304#p1304

I activated the last two lines and deactivated "ShowPreviewForm"
For testing I activated also the pdf-export-options above.

A PDF-File is created but if testing it online on http://www.pdf-tools.com/pdf/pdfa-online-pruefen.aspx
it says that it's no PDF/A - Format!

What's wrong here?  ("ExportPDFA1" is set to "True")

I'm a little confused now...

Offline

#11 2011-06-17 14:25:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

The generated file was perhaps not 100% conformant with the PDF/A1-a format.
There were indeed some missing features, for instance if you embed pictures in your document.

But the main features did exist:
- correct PDF-1.4 header and identifier;
- OutputIntent entry with enhanced <x:xmpmeta ...> xml metadata;
- Unique hexadecimal ID;
- Always include font widths;
- Always embed used true type fonts glyphs;
- Open as PDF/A in Adobe Acrobat Reader (so that it will be handled in a more secure manner).

These features will fulfill most of the PDF/A standard, especially for the long-term archive needs.

I've made some enhancements to the library, thanks to the report from this online test:
- Now include the ICC profile for RGB pictures;
- Corrected /Link flag and XML metadata;
- New header with 8 bit characters;
- Other fixes of expected markers.
See http://synopse.info/fossil/info/af555880bc

It now passes the test successfully.
When you see the price of their PDF/A generator on this web site, I'm a bit proud of our Open Source solution.
smile

Offline

#12 2011-06-19 17:31:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

DonMartin wrote:

I'm trying it with an example emf-file, but I get an EZeroDivide-Exception

The emf file is strange: there is a SetWindowExtEx(szlExtent(0,0))...
Then these settings are never used, and overriden by other values, i.e. (1,1) then (521,508)...

R0257: [010] EMR_SETWINDOWORGEX    (s=16)    {ptlOrigin(0,0)}
R0258: [009] EMR_SETWINDOWEXTEX    (s=16)    {szlExtent(0,0)}
R0259: [012] EMR_SETVIEWPORTORGEX    (s=16)    {ptlOrigin(1667,46)}
R0260: [011] EMR_SETVIEWPORTEXTEX    (s=16)    {szlExtent(303,296)}
R0261: [010] EMR_SETWINDOWORGEX    (s=16)    {ptlOrigin(0,0)}
R0262: [009] EMR_SETWINDOWEXTEX    (s=16)    {szlExtent(1,1)}
R0263: [010] EMR_SETWINDOWORGEX    (s=16)    {ptlOrigin(0,0)}
R0264: [009] EMR_SETWINDOWEXTEX    (s=16)    {szlExtent(1,1)}
R0265: [009] EMR_SETWINDOWEXTEX    (s=16)    {szlExtent(521,508)}
R0266: [010] EMR_SETWINDOWORGEX    (s=16)    {ptlOrigin(0,0)}
R0267: [019] EMR_SETPOLYFILLMODE    (s=12)    {iMode(1=ALTERNATE)}

This is perfectly possible from the API point of view, but didn't make any sense from the drawing point of view.
The emf content as generated by the pdf printer driver seems strange.

I change our code so that such abusive content will just be ignored.
See http://synopse.info/fossil/info/598d76d574

But I don't understand why the logo is not displayed on the page right side.

Is it not possible for you to create the metafile directly from the application, without any external printer driver?

Offline

#13 2011-06-20 16:33:16

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Many thanks to your changes to SynPdf.pas!!

And yes, I think you could be very proud of this open source project and all the other synopse-projects!! :-)

So the online-validation of pdf/a-files created with "ExportPDF" of SQLite3Pages.pas works fine!
And I don't get any more EZeroDivide-Exception with "RenderMetaFile". But, as you say, the logo of my example-file
is not displayed.

I'm testing also the tool "PDFCreator" to create PDF/A - Files but the online-validation of those files also failed.
And I don't want to use another external software, I really would like to use your PDF Engine!

To get sure that the online-validation works correct, I looked for another possibility to check this and I found a
tool named "PDF/A Live!" here: http://www.intarsys.de/produkte/pdfa-live
(Download-File: http://www.intarsys.de/misc/downloads/s … 5.1.2.exe)

This Tool says that the PDF/A - Files created by "PDFCreator" and created by your PDF-Engine are both not PDF/A-Conform.

Maybe I shouldn't believe all this validation-stuff....

If this is ok for you I want to explain the whole problem:

I'm working on a Delphi4-Project in which you can do 3 several print-outputs:
1. Printing with an ActiveX-Component "THighEditPro". It's from Heiler-Software (http://www.heiler.de)
    This component is no longer supported from Heiler-Software since 1999 (!!) but I still have to handle it.
     (and still have to do this in a Delphi4-Project...)
2. Printing with Word over OLE-Automation (--> Word_TLB.pas)
3. Printing with QuickReport

So in 2004 I had to find a solution to archive all printed documents. I found the vprinter-component of mabuse.de
and I thought it's the easiest and best way to "grab" the emf-files out of the spool-files after being send to the printer.

All this works fine all the years. (the fact that I used the emf-format is just because those format is saved within the spool-files)

Now the archived documents should also be saved in other formats like TIF and PDF/A. So that's the reason I'm "ending" here...   :-)

If there is another way (without vprinter) to directly save all print-output above in MetaFiles, I would do so.
But I don't know how to do this. QuickReport uses MetaFiles internal (as you also wrote here in the forum),
but HighEditPro doesn't. And I don't know if I could save Word-Dokuments over OLE directly in EMF or PDF/A...

So this is the problem. Maybe there's another solution with "RenderMetaFile" so that the logo in my emf-example-file
is displayed. Then I could use vprinter in combination with PDF-Engine to solve all problems.

If all would be ok, I want to create a Delphi6-DLL to call from the Delphi4-Projekt. (cause PDF-Engine doesn't work with delphi4, as
mentioned here in the forum)

So if you have any ideas, let me know...   :-)

Offline

#14 2011-06-20 17:48:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Did you test the latest version of the unit with the intarsys.de web site?
Could you send here the errors it reveals?

It passed the tests for the previous validation site, aka http://www.pdf-tools.com/pdf/pdfa-online-pruefen.aspx.

About your solution, I understand the issue. Not easy to maintain code without the source!

Offline

#15 2011-06-21 09:36:42

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

I tested all with your newest SynPdf.pas (which works with online-validation)

You can download the results of the tests with the Intarsys-Software (CABAReT Stage 5.1)
here: http://www.divshare.com/download/15145237-53c

I zipped two Screen-Shots of the validation-results:

1.  Converting my Test-EMF-File with your example-code you first send me (where I got the EZeroDivide-Exception first
     and where now the logo isn't displayed)
     This Screen-Shot named "intarsys_validation_RenderMetaFile.bmp" (cause of the usage of "RenderMetaFile")

2.  Testing your example with "ExportPDF" of SQLite3Pages.pas (http://synopse.info/forum/viewtopic.php?pid=1304#p1304) as I wrote.
     This Screen-Shot named "intarsys_validation_ExportPDF.bmp"


I now read that the "preflight" - Function of Adobe Acrobat Prof. (Adobe-Validation of PDF/A) was originally from
Callas-Software (http://www.callassoftware.com) and so I downloaded a DEMO-Version of "callas pdfToolbox 5!"
to validate the files again.

But this is the last "validation-thing" I will do. If I just get this logo visible I really want to use the PDF Engine
whatever validation-results are coming...   I think the PDF/A - Format will anyway change from time to time and
all must be constantly adapted.

Offline

#16 2011-06-22 14:23:45

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

ok, I finally tested the PDF-Files with "pdfToolbox" from Callas-Software:

The PDF-Format is detected as "PDF/A-1a" and the validation shows 4 errors in both tested files.
(same files as I described in my last post)

You can download the results here: http://www.divshare.com/download/15153187-774
(sorry, it's all in german)

I think the validation with "pdfToolbox" from Callas-Software must be the only one, which we have to believe,
cause they made the Preflight-Functions for Adobe Acrobat.
So the online-validation and the validation with Intarsys-Software seem to be not working correct.

I checked also PDFCreator with "pdfToolbox": The detected Format here is "PDF/A-1b" and validation runs without any problems.
(and no problems with the logo here)

I still would rather use your PDF Engine before having to use the external PDFCreator. The PDF/A-Format is
also better than in PDFCreator.
Maybe the results of my test with "pdfToolbox" give you some hints for not noticed bugs in the PDF Engine?

If you make some changes in PDF Engine: My Demo-Version of "pdfToolbox" ends in 14 days from today.
After that I can't validate any more except I would buy the full version.

Offline

#17 2011-06-22 14:32:26

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Something I forgot:
If there are too many problems with "PDF/A-1a"-Format, maybe it's possible to just create "PDF/A-1b"-Files with PDF Engine?
Maybe this is easier to do and the validation will succeed...

Offline

#18 2011-06-28 12:37:23

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Did you have time to look at the validations and
are you planning any changes for the pdf/a-problem?

Sorry for asking again...   :-)

Offline

#19 2011-06-28 12:43:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

As far as I understood the error messages, the data in XMP meta data is not the one expected.

I made modifications according to the previous validator... and now it fails with this another validator!!!!

I'm not sure both validators will validate the same...

Sounds confusing to me.

Offline

#20 2011-06-29 08:54:31

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

you're right, it's all very confusing, even to me. but I didn't know this at the beginning
of my posts. so, sorry for that.

I was just looking for a way to create PDF/A.
And cause it's for a commercial product of my company I am responsible for the
new changes and so I decided to check and test all changes before they could
be released in the new version.

I didn't know much about PDF/A before this and I really didn't know that
different validation-tools for PDF/A seem to validate not in the same way.

So unfortunately you made some modifications on account of my former questions,
that now seem to be made in vain. That was not my intention. So sorry, again.

As I realized that those validation-tools didn't work the same way, I decided to
consider only one of them. So I choosed the "pdfToolbox" from Callas-Software,
cause they made the Preflight-Functions for Adobe Acrobat and I think they really
must have the knowledge to validate PDF/A.

So the last validation-results from "pdfToolbox" are the only ones we have to
look at. And I think if the PDF/A-Files from PDF Engine passes the validation
of "pdfToolbox" without errors everything really must be ok.
And you can be sure, that I will not test any other tool...  :-)

Additional to the validation-problem there is still the problem with the Logo,
which is not visible after conversion... Hope there will be also a solution for this.

So I hope you understand that I didn't want you to make needless changes.  :-)
I also just needed some time to understand all this pdf/a-stuff.

I really still prefer to use the PDF Engine for the changes in our product.

Offline

#21 2011-07-14 08:29:53

DonMartin
Member
Registered: 2011-06-09
Posts: 16

Re: Convert EMF-Files to PDF/A-Files in Delphi 6

Thanks again for your support so far!

I'll go on looking at the changes and there are a lot of features,
except this pdf/a-stuff, that are very usefull.
It's still a great project!

Offline

Board footer

Powered by FluxBB