2025.6.1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/***********************************************************************************************************************
|
||||
*
|
||||
* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc.
|
||||
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
|
||||
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
|
||||
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
|
||||
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
|
||||
@@ -17,6 +17,7 @@
|
||||
#define INITIALIZE_A3D_API
|
||||
#define HOOPS_PRODUCT_PUBLISH_ADVANCED
|
||||
#include <A3DSDKIncludes.h>
|
||||
#include <hoops_license.h>
|
||||
#include "../common.hpp"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
@@ -24,28 +25,33 @@
|
||||
#include <iostream>
|
||||
|
||||
// Typical commandline parameters which can be used with VisualCpp IDE :
|
||||
// "..\..\..\..\samples\publish\publishgallery\Coding_Samples\sample_DemoDataModel.pdf" "html" "..\..\..\..\samples\publish\publishhtml\htmlforserver\exportpdftohtml\root\PdfContent" "LayerDataModelDemo.xml"
|
||||
// "..\..\..\..\samples\publish\publishgallery\Coding_Samples\sample_DemoDataModel.pdf" "html" "online" "..\..\..\..\samples\publish\publishhtml\htmlforserver\exportpdftohtml\root\PdfContent" "LayerDataModelDemo.xml"
|
||||
// Following are default parameters used when the exe is called with no arguments:
|
||||
// Console exe is supposed to be launched from exe directory
|
||||
#ifdef _MSC_VER
|
||||
# define IN_FILE _T(SAMPLES_PUBLISH_GALLERY_DIRECTORY"\\Coding_Samples\\sample_DemoDataModel.pdf")
|
||||
# define IN_FILE_HTMLTEMPLATE _T(SAMPLES_DATA_DIRECTORY"\\html\\exportpdftohtml_template.html")
|
||||
# define IN_EXPORTFORMAT _T("html") // values are "html" or "scs"
|
||||
# define IN_FILE_HTMLTEMPLATE _T(SAMPLES_DATA_HTML_DIRECTORY"\\exportpdftohtml_template.html")
|
||||
# define IN_VIEWER_TEMPLATE _T(SAMPLES_PUBLISH_HTML_DIRECTORY"\\htmlforserver\\exportpdftohtml\\root\\viewer.html")
|
||||
# define EXPORT_FORMAT _T("html") // values are "html" or "scs"
|
||||
# define EXPORT_TYPE _T("online")
|
||||
# define OUT_ROOT_DIR _T(SAMPLES_PUBLISH_HTML_DIRECTORY"\\htmlforserver\\exportpdftohtml\\root\\PdfContent")
|
||||
# define OUT_NAME _T("sample_DemoDataModel")
|
||||
# define OUT_NAME _T("sample_DemoDataModel")
|
||||
#else
|
||||
# define IN_FILE SAMPLES_PUBLISH_GALLERY_DIRECTORY"/Coding_Samples/sample_DemoDataModel.pdf"
|
||||
# define IN_FILE_HTMLTEMPLATE SAMPLES_DATA_DIRECTORY"/html/exportpdftohtml_template.html"
|
||||
# define IN_EXPORTFORMAT "html" // values are "html" or "scs"
|
||||
# define IN_FILE_HTMLTEMPLATE SAMPLES_DATA_HTML_DIRECTORY"/exportpdftohtml_template.html"
|
||||
# define IN_VIEWER_TEMPLATE SAMPLES_PUBLISH_HTML_DIRECTORY"/htmlforserver/exportpdftohtml/root/viewer.html"
|
||||
# define EXPORT_FORMAT "html" // values are "html" or "scs"
|
||||
# define EXPORT_TYPE "online"
|
||||
# define OUT_ROOT_DIR SAMPLES_PUBLISH_HTML_DIRECTORY"/htmlforserver/exportpdftohtml/root/PdfContent"
|
||||
# define OUT_NAME "sample_DemoDataModel"
|
||||
#endif
|
||||
|
||||
//#define MONOLITHIC
|
||||
// Uncomment this to have a monolithic export (only available if IN_EXPORTFORMAT is html)
|
||||
// The result is that you will have only one file but it will take more time to load inside a browser.
|
||||
enum class ExportType {
|
||||
WRONG_TYPE, // Only when wrong parameters is passed in the command line arguments
|
||||
ONLINE, // The solution for client/server integration and request for best performances (cf. kA3DWebOnline).
|
||||
OFFLINE_SINGLE_FILE, // The easy way to give a PDF exported to someone (cf. kA3DWebOfflineSingleFile).
|
||||
};
|
||||
|
||||
|
||||
//######################################################################################################################
|
||||
// Tools
|
||||
@@ -54,11 +60,11 @@ A3DBool hasEnding(const A3DUTF8Char* pcStr, const A3DUTF8Char* pcExt)
|
||||
if (pcExt == nullptr || pcStr == nullptr)
|
||||
return A3D_FALSE;
|
||||
|
||||
std::string strExt(pcExt);
|
||||
std::string str(pcStr);
|
||||
const std::string strExt(pcExt);
|
||||
const std::string str(pcStr);
|
||||
if (str.length() >= strExt.length())
|
||||
{
|
||||
std::string const strFileNameExt = str.substr(str.length() - strExt.length());
|
||||
const std::string strFileNameExt = str.substr(str.length() - strExt.length());
|
||||
return std::equal(strFileNameExt.begin(), strFileNameExt.end(), strExt.begin(), [](char const& c1, char const& c2)
|
||||
{
|
||||
return c1 == c2 || std::toupper(c1) == std::toupper(c2);
|
||||
@@ -88,18 +94,20 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
GetLogFile(SAMPLES_PUBLISH_HTML_DIRECTORY"/htmlforserver/exportpdftohtml/root/ExportPDFToHtml.log.txt");
|
||||
#endif
|
||||
|
||||
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY));
|
||||
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY), HOOPS_LICENSE);
|
||||
CHECK_RET(sHoopsExchangeLoader.m_eSDKStatus);
|
||||
CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree));
|
||||
CHECK_RET(A3DDllSetCallbacksReport(PrintLogMessage, PrintLogWarning, PrintLogError));
|
||||
|
||||
// First of all we parse optional command line options
|
||||
A3DUTF8Char* pc3DTemplateFile = NULL;
|
||||
A3DUTF8Char* pcFileName = NULL;
|
||||
A3DUTF8Char* pcFormat = NULL;
|
||||
A3DUTF8Char* pcOutputDirectory = NULL;
|
||||
A3DUTF8Char* pcOutputName = NULL;
|
||||
int iOutputFormats = 0;
|
||||
A3DUTF8Char* pc3DTemplateFile = nullptr;
|
||||
A3DUTF8Char* pcFileName = nullptr;
|
||||
A3DUTF8Char* pcFormat = nullptr;
|
||||
A3DUTF8Char* pcOutputDirectory = nullptr;
|
||||
A3DUTF8Char* pcOutputName = nullptr;
|
||||
A3DUTF8Char* pcExportType = nullptr;
|
||||
A3DUns8 iOutputFormats = 0;
|
||||
ExportType eExportType = ExportType::WRONG_TYPE;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
A3DUTF8Char fileName[_MAX_PATH];
|
||||
@@ -108,7 +116,7 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
|
||||
A3DUTF8Char format[_MAX_PATH];
|
||||
pcFormat = format;
|
||||
A3DMiscUTF16ToUTF8(IN_EXPORTFORMAT, pcFormat);
|
||||
A3DMiscUTF16ToUTF8(EXPORT_FORMAT, pcFormat);
|
||||
|
||||
A3DUTF8Char outputDirectory[_MAX_PATH];
|
||||
pcOutputDirectory = outputDirectory;
|
||||
@@ -121,12 +129,17 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
A3DUTF8Char templateFile[_MAX_PATH];
|
||||
pc3DTemplateFile = templateFile;
|
||||
A3DMiscUTF16ToUTF8(IN_FILE_HTMLTEMPLATE, pc3DTemplateFile);
|
||||
|
||||
A3DUTF8Char exportType[_MAX_PATH];
|
||||
pcExportType = exportType;
|
||||
A3DMiscUTF16ToUTF8(EXPORT_TYPE, exportType);
|
||||
#else
|
||||
pcFileName = (A3DUTF8Char*)IN_FILE;
|
||||
pcOutputDirectory = (A3DUTF8Char*)OUT_ROOT_DIR;
|
||||
pcOutputName = (A3DUTF8Char*)OUT_NAME;
|
||||
pc3DTemplateFile = (A3DUTF8Char*)IN_FILE_HTMLTEMPLATE;
|
||||
pcFormat = (A3DUTF8Char*)IN_EXPORTFORMAT;
|
||||
pcFormat = (A3DUTF8Char*)EXPORT_FORMAT;
|
||||
pcExportType = (A3DUTF8Char*)EXPORT_TYPE;
|
||||
#endif
|
||||
|
||||
if (iArgc >= 2)
|
||||
@@ -150,23 +163,32 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
if (iArgc >= 4)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
A3DMiscUTF16ToUTF8(ppcArgv[3], pcOutputDirectory);
|
||||
A3DMiscUTF16ToUTF8(ppcArgv[3], pcExportType);
|
||||
#else
|
||||
pcOutputDirectory = ppcArgv[3];
|
||||
pcExportType = ppcArgv[3];
|
||||
#endif
|
||||
}
|
||||
|
||||
if (iArgc >= 5)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
A3DMiscUTF16ToUTF8(ppcArgv[4], pcOutputName);
|
||||
A3DMiscUTF16ToUTF8(ppcArgv[4], pcOutputDirectory);
|
||||
#else
|
||||
pcOutputName = ppcArgv[4];
|
||||
pcOutputDirectory = ppcArgv[4];
|
||||
#endif
|
||||
}
|
||||
|
||||
if (iArgc >= 6)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
A3DMiscUTF16ToUTF8(ppcArgv[5], pcOutputName);
|
||||
#else
|
||||
pcOutputName = ppcArgv[5];
|
||||
#endif
|
||||
}
|
||||
|
||||
// Treat format parameter
|
||||
if (pcFormat != NULL)
|
||||
if (pcFormat != nullptr)
|
||||
{
|
||||
std::string strFormat(pcFormat);
|
||||
std::transform(strFormat.begin(), strFormat.end(), strFormat.begin(), [](unsigned char c)
|
||||
@@ -174,7 +196,8 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
return static_cast<char>(::tolower(c));
|
||||
}
|
||||
);
|
||||
size_t flagSize = strFormat.length();
|
||||
|
||||
const size_t flagSize = strFormat.length();
|
||||
size_t previousCharIndex = 0;
|
||||
for (size_t charIndex = 0; charIndex <= flagSize; ++charIndex)
|
||||
{
|
||||
@@ -194,42 +217,62 @@ int main(int iArgc, A3DUTF8Char** ppcArgv)
|
||||
}
|
||||
}
|
||||
|
||||
if (pcExportType != nullptr)
|
||||
{
|
||||
const std::string strExportType(pcExportType);
|
||||
|
||||
if (strExportType == "offline_single_file")
|
||||
eExportType = ExportType::OFFLINE_SINGLE_FILE;
|
||||
else if (strExportType == "online")
|
||||
eExportType = ExportType::ONLINE;
|
||||
else
|
||||
{
|
||||
MY_PRINTF("Unsupported export type\n");
|
||||
}
|
||||
}
|
||||
|
||||
// check parameter validity
|
||||
if (hasEnding(pcFileName, ".pdf") && pcOutputDirectory != NULL && pc3DTemplateFile!=NULL && iOutputFormats != 0)
|
||||
if (hasEnding(pcFileName, ".pdf") && pcOutputDirectory != nullptr && pc3DTemplateFile != nullptr && iOutputFormats != 0 && eExportType != ExportType::WRONG_TYPE)
|
||||
{
|
||||
A3DRWParamsExportHtmlData paramsExportData;
|
||||
A3D_INITIALIZE_DATA(A3DRWParamsExportHtmlData, paramsExportData);
|
||||
paramsExportData.m_bIncludeMeasurementInformation = A3D_TRUE;
|
||||
paramsExportData.m_pcHtmlTemplateName = pc3DTemplateFile;
|
||||
paramsExportData.m_ePdfOutputFormat = kA3DWebOutPdfFormatXml;
|
||||
paramsExportData.m_i3dOutputFormat = iOutputFormats;
|
||||
|
||||
#ifdef MONOLITHIC
|
||||
// set the output as monolithic
|
||||
paramsExportData.m_eHtmlOutputMode = kA3DWebOfflineSingleFile;
|
||||
if (eExportType == ExportType::ONLINE) {
|
||||
CHECK_RET(A3DConvertPDFToWebFormat(pcFileName, ¶msExportData, pcOutputDirectory, pcOutputName));
|
||||
}
|
||||
else if (eExportType == ExportType::OFFLINE_SINGLE_FILE) {
|
||||
// set the output as monolithic
|
||||
paramsExportData.m_eHtmlOutputMode = kA3DWebOfflineSingleFile;
|
||||
|
||||
// fill and set mandatory parameters
|
||||
A3DRWHtmlOfflineData offlineData;
|
||||
A3D_INITIALIZE_DATA(A3DRWHtmlOfflineData, offlineData);
|
||||
// fill and set mandatory parameters
|
||||
A3DRWHtmlOfflineData offlineData;
|
||||
A3D_INITIALIZE_DATA(A3DRWHtmlOfflineData, offlineData);
|
||||
#ifdef _MSC_VER
|
||||
A3DUTF8Char viewerFilePath[_MAX_PATH];
|
||||
A3DMiscUTF16ToUTF8(IN_VIEWER_TEMPLATE, viewerFilePath);
|
||||
offlineData.m_pcPathToHtmlViewerFile = viewerFilePath;
|
||||
A3DUTF8Char viewerFilePath[_MAX_PATH];
|
||||
A3DMiscUTF16ToUTF8(IN_VIEWER_TEMPLATE, viewerFilePath);
|
||||
offlineData.m_pcPathToHtmlViewerFile = viewerFilePath;
|
||||
#else
|
||||
offlineData.m_pcPathToHtmlViewerFile = (A3DUTF8Char*)IN_VIEWER_TEMPLATE;
|
||||
offlineData.m_pcPathToHtmlViewerFile = (A3DUTF8Char*)IN_VIEWER_TEMPLATE;
|
||||
#endif
|
||||
|
||||
paramsExportData.m_pHtmlOfflineData = &offlineData;
|
||||
#endif // MONOLITHIC
|
||||
CHECK_RET(A3DConvertPDFToWebFormat(pcFileName, ¶msExportData, pcOutputDirectory, pcOutputName, iOutputFormats));
|
||||
|
||||
paramsExportData.m_pHtmlOfflineData = &offlineData;
|
||||
CHECK_RET(A3DConvertPDFToWebFormat(pcFileName, ¶msExportData, pcOutputDirectory, pcOutputName));
|
||||
}
|
||||
|
||||
return A3D_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
MY_PRINTF("\nUsage: ExportPDFToHTML [source] [format] [outputDirectory] [outputXmlFile]\n");
|
||||
MY_PRINTF("\nUsage: ExportPDFToHTML [source] [format] [exportType] [outputDirectory] [outputXmlFile]\n");
|
||||
MY_PRINTF(" source: the pdf file to convert in HTML\n");
|
||||
MY_PRINTF(" format: output format(s) for cad models amongst html, scs.\n");
|
||||
MY_PRINTF(" You can have more than one output format. If so, separate each by using '|'.\n");
|
||||
MY_PRINTF(" Example: \"html|scs\"\n");
|
||||
MY_PRINTF(" Example: \"html|scs\".\n");
|
||||
MY_PRINTF(" exportType: (optional) type of the export we would like (\"online\" or \"offline_single_file\").\n");
|
||||
MY_PRINTF(" outputDirectory: (optional) the directory where the files will be put. The directory must exists.\n");
|
||||
MY_PRINTF(" outputXmlFilename: (optional) name of the output xml file.\n");
|
||||
return A3D_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user