/*
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved.
// 
// NOTICE:   Adobe permits you to use, modify, and distribute this file in accordance with the 
// terms of the Adobe license agreement accompanying it.   If you have received this file from a 
// source other than Adobe, then your use, modification, or distribution of it requires the prior 
// written permission of Adobe.
//
*/

/*
// Project: XPS2PDFConverter - Convert an XPS file to PDF.
//
// Note: By default, this example program opens a file called xps2pdf.xps in the
//             source directory.   It converts this xps file to a pdf file and saves the 
//                             file in the executable diretory by the name out.pdf
//
// Steps:
// * Initialize HFT
// * Initialize XPS2PDF by invoking Plugin API XPS2PDFInitialize()
// * Convert the XPS2PDF by invoking Plugin API XPS2PDFConvert()
// * Terminate XPS2PDF by invoking Plugin API XPS2PDFTerminate()
*/

#include <stdio.h>

//PDFL Headers
#include "PDFInit.h"
#include "PDCalls.h"
#include "ASExtraCalls.h"

// Plugin Headers
#include "XPS2PDFCalls.h"

// Sample Headers
#include "MyPDFLibUtils.h"


#define XPS_CONVERSION_OPTION_KEY                             "PDFSettings"
#define XPS_CONVERSION_OPTION_KEYLANG     "PDFSettingsLang"
#define PDF_EXTENSION ".pdf"
#define PLATFORM_LANGUAGE "ENU"
#define JOB_OPTIONS_NAME "../../../Resource/joboptions/Standard.joboptions"


#define INPUT_PATH "../sources/xps2pdf.xps"
#define OUTPUT_PATH "out.pdf"

HFT   gXPS2PDFHFT;

int   XPSToPDFMain();
void   MainProc();

void   MainProc()
{
DURING
                gXPS2PDFHFT  = InitXPS2PDFHFT;
                if (XPS2PDFInitialize())
               {
                                XPSToPDFMain();
                               XPS2PDFTerminate();
               }
HANDLER
               printf( "MainProc has thrown an exception...\n" );
                DisplayError(ERRORCODE);
END_HANDLER
}
int   XPSToPDFMain()
{
                ASInt32  ret_val=0;
                PDDoc  outPDDoc=NULL;
DURING    
                ASCab  settingsCab =  ASCabNew();
                ASText  langText =  ASTextFromEncoded(PLATFORM_LANGUAGE,  kASRomanScript);
                ASText  joNameText =  ASTextFromEncoded(JOB_OPTIONS_NAME,  kASRomanScript);
                ASCabPutText(settingsCab,  XPS_CONVERSION_OPTION_KEYLANG, langText);
                ASCabPutText(settingsCab,  XPS_CONVERSION_OPTION_KEY, joNameText);

                ASFileSys  asFileSys =  ASGetDefaultFileSys();
                ASPathName  asInPathName =  ASFileSysCreatePathName(NULLASAtomFromString( "Cstring" ),  INPUT_PATH,0);
                ASPathName  asOutPathName =  ASFileSysCreatePathName(NULLASAtomFromString( "Cstring" ),  OUTPUT_PATH, 0);
               ret_val = XPS2PDFConvert(settingsCab,0,asInPathName,NULL,&outPDDoc,NULL);
                if (ret_val)
               {
                               printf( "file %s success\n" ,  INPUT_PATH);
                                PDDocSave(outPDDoc,  PDSaveFull  , asOutPathName,  ASGetDefaultFileSys(),  NULLNULL);
                                PDDocClose(outPDDoc);
               }
                else
                               printf( "file %s failed\n" ,  INPUT_PATH);

                //clean up args when done
                ASCabDestroy(settingsCab);
                ASFileSysReleasePathNULL, asInPathName);
                ASFileSysReleasePathNULL, asOutPathName);
HANDLER
                DisplayError(ERRORCODE);
               ret_val=0;
END_HANDLER
                return  ret_val;
}


#define INCLUDE_MYPDFLIBAPP_CPP 1
#include "MyPDFLibApp.cpp"
#undef INCLUDE_MYPDFLIBAPP_CPP