/* * (c) Copyright Ascensio System SIA 2010-2023 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish * street, Riga, Latvia, EU, LV-1050. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ #include "../../DesktopEditor/common/File.h" #include "../../DesktopEditor/common/Directory.h" #include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h" #include "../../DesktopEditor/xmlsec/src/include/CertificateCommon.h" #include "../PdfFile.h" void TEST(IRenderer* pRenderer) { // ТЕСТОВЫЕ КОММАНДЫ pRenderer->PathCommandStart(); pRenderer->PathCommandMoveTo(10, 10); pRenderer->PathCommandLineTo(20, 20); pRenderer->PathCommandCurveTo(70, 30, 30, 20, 50, 50); pRenderer->PathCommandClose(); pRenderer->put_BrushColor1(0xFF0000); pRenderer->put_PenColor(0x0000FF); pRenderer->put_PenSize(1); pRenderer->DrawPath(c_nStroke | c_nWindingFillMode); pRenderer->PathCommandEnd(); } void TEST2(IRenderer* pRenderer) { ((CPdfFile*)pRenderer)->OnlineWordToPdf(NSFile::GetProcessDirectory() + L"/../example/pdf.bin", L""); } void TEST3(IRenderer* pRenderer) { ((CPdfFile*)pRenderer)->OnlineWordToPdfFromBinary(NSFile::GetProcessDirectory() + L"/../example1/1/pdf.bin", L""); } int main() { CApplicationFontsWorker oWorker; oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache"; oWorker.m_bIsNeedThumbnails = false; if (!NSDirectory::Exists(oWorker.m_sDirectory)) NSDirectory::CreateDirectory(oWorker.m_sDirectory); NSFonts::IApplicationFonts* pApplicationFonts = oWorker.Check(); std::wstring wsSrcFile = NSFile::GetProcessDirectory() + L"/test.pdf"; std::wstring wsDstFile = NSFile::GetProcessDirectory() + L"/test2.pdf"; std::wstring wsTempDir = NSFile::GetProcessDirectory() + L"/pdftemp"; if (!NSDirectory::Exists(wsTempDir)) NSDirectory::CreateDirectory(wsTempDir); CPdfFile pdfFile(pApplicationFonts); pdfFile.SetTempDirectory(wsTempDir); std::wstring wsPassword; bool bResult = pdfFile.LoadFromFile(wsSrcFile); if (!bResult) { wsPassword = L"123456"; bResult = pdfFile.LoadFromFile(wsSrcFile, wsPassword); } ICertificate* pCertificate = NULL; if (false) { std::wstring wsCertificateFile = NSFile::GetProcessDirectory() + L"/test.pfx"; std::wstring wsPrivateKeyFile = L""; std::string sCertificateFilePassword = "123456"; std::string sPrivateFilePassword = ""; pCertificate = NSCertificate::FromFiles(wsPrivateKeyFile, sPrivateFilePassword, wsCertificateFile, sCertificateFilePassword); } if (false) { double dPageDpiX, dPageDpiY, dWidth, dHeight; pdfFile.GetPageInfo(0, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY); pdfFile.ConvertToRaster(0, NSFile::GetProcessDirectory() + L"/res.png", 4, dWidth * dPageDpiX / 25.4, dHeight * dPageDpiY / 25.4, true, pdfFile.GetFontManager()); RELEASEINTERFACE(pApplicationFonts); RELEASEOBJECT(pCertificate); return 0; } if (false) { pdfFile.CreatePdf(); double dPageDpiX, dPageDpiY, dWidth, dHeight; pdfFile.GetPageInfo(0, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY); dWidth *= 25.4 / dPageDpiX; dHeight *= 25.4 / dPageDpiY; for (int i = 0; i < pdfFile.GetPagesCount(); i++) { pdfFile.NewPage(); pdfFile.BeginCommand(c_nPageType); pdfFile.put_Width(dWidth); pdfFile.put_Height(dHeight); pdfFile.DrawPageOnRenderer(&pdfFile, i, NULL); pdfFile.EndCommand(c_nPageType); } if (pCertificate) pdfFile.Sign(10, 70, 50, 50, NSFile::GetProcessDirectory() + L"/test.png", pCertificate); pdfFile.SaveToFile(wsDstFile); RELEASEINTERFACE(pApplicationFonts); RELEASEOBJECT(pCertificate); return 0; } if (bResult && pdfFile.EditPdf(wsDstFile)) { if (pCertificate) { if (pdfFile.EditPage(0)) { pdfFile.Sign(10, 70, 50, 50, NSFile::GetProcessDirectory() + L"/test.png", pCertificate); } } else { if (pdfFile.EditPage(0)) { TEST(&pdfFile); pdfFile.RotatePage(90); } pdfFile.DeletePage(1); if (pdfFile.EditPage(1)) { TEST2(&pdfFile); } if (pdfFile.AddPage(3)) { TEST3(&pdfFile); } } pdfFile.Close(); } RELEASEINTERFACE(pApplicationFonts); RELEASEOBJECT(pCertificate); return 0; }