PDF to PDF/A conversion with PDF-XChange Editor SDK

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

I got the code below online, but I am having difficulties implementing it using the PDF-XChange Editor SDK.
It seems I need to use an active X object with a Windows From to get the IPXV_Document and IPXV_Inst.

Is there a way I can achieve this using only the PDF-XChange Editor SDK from a console application.

Code: Select all

Inst.AddPluginFromFile("D:\\PDFAPlugin.pvp");
        
        //C#
        private void SaveDocument(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst)
        {
            //Performing save to the same file
            Doc.Save();
            //Performing save to the specified file without the progress bar
            PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
            PDFXEdit.IAFS_Name destPath = fsInst.DefaultFileSys.StringToName("D:\\TestFile.pdf"); //Converting string to name
            Doc.Save(destPath, (int)PDFXEdit.PXV_DocSaveFlags.PXV_DocSave_NoProgress);

            //Saving document as pdfa (for this the PDFA plugin should be registered)
            PDFXEdit.IPXV_ExportConverter cnv = null;
            for (uint i = 0; i < pdfCtl.Inst.ExportConvertersCount; i++)
            {
                if (pdfCtl.Inst.ExportConverter[i].ID == "conv.exp.pdfa")
                    cnv = pdfCtl.Inst.ExportConverter[i];
            }
            if (cnv != null)
            {
                PDFXEdit.ICab cab = pdfCtl.Inst.GetFormatConverterParams(false, "conv.exp.pdfa");
                pdfCtl.Doc.Save(destPath, 0, null, cnv, cab);
            }
        }

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello dauda.kadiri@aquaforest.com,

If you are not using the IPXV_Control, then you won't have a IPXV_Document available at all. You should use only the IPXV_Inst in the console project. What you have is the IPXC_Document that should be opened by using the IPXC_Inst (that can be obtained from the IPXV_Inst by using the GetExtension() method). Once you have it, you can prepare the ExportConverter and then do:

Code: Select all

//IPXC_Document srcDoc;
PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)pdfCtl.Inst.GetExtension("AFS");
PDFXEdit.IAFS_Name name = fsInst.DefaultFileSys.StringToName(@"D:\pdfaRes.pdf");
int openFileFlags = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_CreateAlways | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Write | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_FullCache);
PDFXEdit.IAFS_File destFile = fsInst.DefaultFileSys.OpenFile(name, openFileFlags);
cnv.Convert(pxvInst, srcDoc, destFile)
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex
Thank you for the reply, I have applied the changes you suggested but no success.
Below is the code i am using
It throws a com exception on the pxvInst.AddPluginFromFile().
Method.

The exceptions are.

"Error HRESULT E_FAIL has been returned from a call to a COM component." for the AddPluginFromFile()
The IAUX_Inst::FormatHRESULT formatted message = "Error [System]: Unspecified error."

Can you please tell me what I am doing wrong.

Code: Select all

  		PXV_Inst pxvInst = new PXV_Inst();
                pxvInst.Init();
                pxvInst.AddPluginFromFile(@"J:\QA Folder\out\pdfa\PDFAPlugin.pvp");
                PDFXEdit.IAFS_Inst fsInst = pxvInst.GetExtension("AFS");
                PDFXEdit.IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(@"J:\QA Folder\out\pdfa\9904pdf_a.pdf");
                int openFileFlags = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_CreateAlways | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Write | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_FullCache);
                PDFXEdit.IAFS_File destFile = fsInst.DefaultFileSys.OpenFile(destPath, openFileFlags);
                PDFXEdit.IPXV_ExportConverter cnv = null;
                IPXC_Inst docInst = (PXC_Inst)pxvInst.GetExtension("PXC");
                IPXC_Document srcDoc = docInst.OpenDocumentFromFile(@"J:\QA Folder\out\pdfa\9904pdf_a.pdf", null);

                for (uint i = 0; i < pxvInst.ExportConvertersCount; i++)
                {
                    if (pxvInst.ExportConverter[i].ID == "conv.exp.pdfa")
                        cnv = pxvInst.ExportConverter[i];
                }
                if (cnv != null)
                {
                    cnv.Convert(pxvInst, srcDoc, destFile);
                }
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello dauda.kadiri@aquaforest.com,

Here's an answer to your problem:
viewtopic.php?f=66&t=25056&p=97884&hili ... ins#p97884

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex
Thanks you for help.
I am almost there now, but I have 1 more questions.
1. I suppress the conversion report pop up box that shows up after each file is converted to PDF/A-1b, this is because we would like to run this operation as a
batch job using a windows service. Is there a way to redirect the error and fixes output in the image below to a string that I can log in my process so that my users
will know why some conversions failed.

Image

Once again thank you for the support.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello dauda.kadiri@aquaforest.com,

Here's the post that shows a perfect sample for you - you will have to set the ShowReport parameter to 0 - then no report will be generated:
viewtopic.php?f=66&t=28839&p=111604&hil ... rt#p111604

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

Thank you for the reply.
I have successfully suppress the report popup, my question was is there a way to redirect the output the report shows to a string in my code.
I will like to show my Users the Errors and fixes so that they can know which files have issues in them and why the conversion failed.

Kind Regards
Dauda
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello Dauda,

I'm afraid that is not possible - if some error occurs, the Convert method will throw an exception, no other information is available from the SDK.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

Thank you! , we will review the results we have internally and we will come back to you if we make a decision.


Your help was very important
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

Thank you for your help, I have another issue, when I try to validate the PDFA/-1b files produces by your trial version,
I get an error message saying transparent images are not allowed in a PDF/A-1b file.
I wanted to confirm if it was as a result of the trial stamp you put on the files, because I do not get this error with PDF/A-2b.

Below are the error messages I get:
Using Adobe Acrobat
Image

Using Vera PDF
A Group object with an S key with a value of Transparency shall not be included in a form XObject.
A Group object with an S key with a value of Transparency shall not be included in a page dictionary
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello Dauda,

This is what you should do (if you have bought a copy of End User Editor of course). Save you document as PDF\A with needed settings with and without the license key and compare the Acrobat validation behavior. Then we will know whether it's our watermark or not.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex
We are looking into getting the license.
I have one more issue though.

The conversions go through successfully, but my process does not exit with exit code 0, instead I get the message below.
Aquaforest.Pdfa.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
The weird issue is that this crash happens when i am exiting the process.
Maybe i am not cleaning up the objects and resources.

See event log entry below
Faulting application name: Aquaforest.Pdfa.exe, version: 1.0.0.0, time stamp: 0x5b9fbd88
Faulting module name: PDFXEditCore.x86.dll, version: 7.0.326.1, time stamp: 0x5b58f463
Exception code: 0xc0000005
Fault offset: 0x00031033
Faulting process ID: 0x19d0
Faulting application start time: 0x01d44e94ccf89599
Faulting application path: J:\dev\Source Control\Aquaforest.Pdfa\bin\Aquaforest.Pdfa.exe
Faulting module path: C:\Program Files (x86)\Tracker Software\Editor SDK\Bin\PDFXEditCore.x86.dll
Report ID: f6b5a2c6-9ef9-4971-a974-c8dde14425cc
Faulting package full name:
Faulting package-relative application ID:

See my code below
private static void Convert(string input, string output, int part, string conformance)
{
PXV_Inst pxvInst = new PXV_Inst();
try
{
Console.WriteLine("Converting {0} to a PDF/A-{1}{2}", input, part, conformance);
int conformanceInt = 1;
switch (conformance)
{
case "a":
{
conformanceInt = 0;
}
break;

case "b":
{
conformanceInt = 1;
}
break;

case "u":
{
conformanceInt = 2;
}
break;
}
pxvInst.Init();
pxvInst.StartLoadingPlugins();
var pluginPath = Path.Combine(currentDirectory, "PDFAPlugin.pvp");
pxvInst.AddPluginFromFile(pluginPath);
pxvInst.FinishLoadingPlugins();
PDFXEdit.IAFS_Inst fsInst = pxvInst.GetExtension("AFS");
PDFXEdit.IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(output);
int openFileFlags = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_CreateAlways | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Write | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_FullCache);
PDFXEdit.IAFS_File destFile = fsInst.DefaultFileSys.OpenFile(destPath, openFileFlags);
PDFXEdit.IPXV_ExportConverter cnv = null;
IPXC_Inst docInst = (PXC_Inst)pxvInst.GetExtension("PXC");
IPXC_Document srcDoc = docInst.OpenDocumentFromFile(input, null);
ICab cab = pxvInst.GetFormatConverterParams(false, "conv.exp.pdfa");
ICabNode convParamsRoot = cab.Root;

//<!-- 1 - PDF/A-1; 2 - PDF/A-2; 3 - PDF/A-3 -->
//<Item id="Part" type="Int" defVal="2" />
//<!-- 0 - -a; 1 - -b; 2 - -u; -->
//<Item id="Conformance" type="Int" defVal="1" />
//This will do PDF/A-2b
convParamsRoot.SetInt("Part", part);
convParamsRoot.SetInt("Conformance", conformanceInt);
convParamsRoot.SetInt("ShowReport", 0);
convParamsRoot.SetString("ErrorMessage", "true");
for (uint i = 0; i < pxvInst.ExportConvertersCount; i++)
{
if (pxvInst.ExportConverter.ID == "conv.exp.pdfa")
cnv = pxvInst.ExportConverter;
}
if (cnv != null)
{
cnv.Convert(pxvInst, srcDoc, destFile, 0, cab);
pxvInst.ClearHistory(true);
pxvInst = null;
destFile.Close();
srcDoc.Close();
}
}
catch (Exception ex)
{
IAUX_Inst auxInst = (IAUX_Inst)pxvInst.GetExtension("AUX");
var error = auxInst.FormatHRESULT(System.Runtime.InteropServices.Marshal.GetHRForException(ex), 0);
throw new Exception(error);
}
}
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Never mind Alex, I was using the 32 bit on a 64 bit system Thank you.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello Dauda,

Not a problem at all :)
If you want, I can convert that file for you (so no watermark will be there).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

That would be great, here is a url to the PDF file below.
https://aquaforestdownloads.blob.core.w ... _image.pdf

Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello Dauda,

Here's the converted file to the PDF/A-1B standard without our watermarks:
sample_image.pdf
(454.01 KiB) Downloaded 124 times
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

Thank you for this, it validated properly.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex
I am having the same issue I had in new enviroments.

The conversions go through successfully, but my process does not exit with exit code 0, instead I get the message below.
Aquaforest.Pdfa.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
The weird issue is that this crash happens when i am exiting the process.
Maybe i am not cleaning up the objects and resources.

See event log entry below
Faulting application name: Aquaforest.Pdfa.exe, version: 1.0.0.0, time stamp: 0x5ba50269
Faulting module name: PDFXEditCore.x64.dll, version: 7.0.326.1, time stamp: 0x5b58f728
Exception code: 0xc0000005
Fault offset: 0x0000000000031eb5
Faulting process id: 0x32a8
Faulting application start time: 0x01d451b91a2b3fbf
Faulting application path: C:\Aquaforest\Autobahn DX\pj\bin\Aquaforest.Pdfa.exe
Faulting module path: C:\Aquaforest\Autobahn DX\pj\bin\PDFXEditCore.x64.dll
Report Id: 5b635b3b-bdac-11e8-810d-1418773b7f12
Faulting package full name:
Faulting package-relative application ID:


See my code below
private static void Convert(string input, string output, int part, string conformance)
{
PXV_Inst pxvInst = new PXV_Inst();
try
{
Console.WriteLine("Converting {0} to a PDF/A-{1}{2}", input, part, conformance);
int conformanceInt = 1;
switch (conformance)
{
case "a":
{
conformanceInt = 0;
}
break;

case "b":
{
conformanceInt = 1;
}
break;

case "u":
{
conformanceInt = 2;
}
break;
}
pxvInst.Init();
pxvInst.StartLoadingPlugins();
var pluginPath = Path.Combine(currentDirectory, "PDFAPlugin.pvp");
pxvInst.AddPluginFromFile(pluginPath);
pxvInst.FinishLoadingPlugins();
PDFXEdit.IAFS_Inst fsInst = pxvInst.GetExtension("AFS");
PDFXEdit.IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(output);
int openFileFlags = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_CreateAlways | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Write | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_FullCache);
PDFXEdit.IAFS_File destFile = fsInst.DefaultFileSys.OpenFile(destPath, openFileFlags);
PDFXEdit.IPXV_ExportConverter cnv = null;
IPXC_Inst docInst = (PXC_Inst)pxvInst.GetExtension("PXC");
IPXC_Document srcDoc = docInst.OpenDocumentFromFile(input, null);
ICab cab = pxvInst.GetFormatConverterParams(false, "conv.exp.pdfa");
ICabNode convParamsRoot = cab.Root;

//<!-- 1 - PDF/A-1; 2 - PDF/A-2; 3 - PDF/A-3 -->
//<Item id="Part" type="Int" defVal="2" />
//<!-- 0 - -a; 1 - -b; 2 - -u; -->
//<Item id="Conformance" type="Int" defVal="1" />
//This will do PDF/A-2b
convParamsRoot.SetInt("Part", part);
convParamsRoot.SetInt("Conformance", conformanceInt);
convParamsRoot.SetInt("ShowReport", 0);
convParamsRoot.SetString("ErrorMessage", "true");
for (uint i = 0; i < pxvInst.ExportConvertersCount; i++)
{
if (pxvInst.ExportConverter.ID == "conv.exp.pdfa")
cnv = pxvInst.ExportConverter;
}
if (cnv != null)
{
cnv.Convert(pxvInst, srcDoc, destFile, 0, cab);
pxvInst.ClearHistory(true);
pxvInst = null;
destFile.Close();
srcDoc.Close();
}
}
catch (Exception ex)
{
IAUX_Inst auxInst = (IAUX_Inst)pxvInst.GetExtension("AUX");
var error = auxInst.FormatHRESULT(System.Runtime.InteropServices.Marshal.GetHRForException(ex), 0);
throw new Exception(error);
}
}
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

Hello Dauda,

You have forgot to call pxvInst.Shutdown() at the end before nullifying it. Again, I strongly recommend reading this:
https://sdkhelp.pdf-xchange.com/view/PXV:CoClasses

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
dauda.kadiri@aquaforest.com
User
Posts: 15
Joined: Thu Aug 23, 2018 5:17 pm

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by dauda.kadiri@aquaforest.com »

Hi Alex

Thanks I will read it
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PDF to PDF/A conversion with PDF-XChange Editor SDK

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply