Files
core/PdfWriter/test/test.cpp
Kulikova Svetlana eeb757f5a4 simple interface
2022-02-11 15:13:48 +03:00

48 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "../PdfRenderer.h"
#include "../../PdfReader/PdfReader.h"
#include "../../DesktopEditor/common/File.h"
int main()
{
NSFonts::IApplicationFonts* pApplicationFonts = NSFonts::NSApplication::Create();
CPdfRenderer pdfWriter(pApplicationFonts, true);
pdfWriter.SetTempFolder(NSFile::GetProcessDirectory() + L"/wtemp");
PdfReader::CPdfReader* pReader = new PdfReader::CPdfReader(pApplicationFonts);
pReader->SetTempDirectory(NSFile::GetProcessDirectory() + L"/rtemp");
// PDFDoc монополизирует доступ к файлу для чтения и не отпускает пока не деструкнится.
// Для дозаписи файл нужно прочитать в память для ридера, а доступ к файлу отдать вритеру.
BYTE* pData;
DWORD nBytes;
NSFile::CFileBinary::ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.pdf", &pData, nBytes);
if (!pData)
{
RELEASEOBJECT(pReader);
RELEASEOBJECT(pApplicationFonts);
return 1;
}
bool bResult = pReader->LoadFromMemory(pData, nBytes);
if (bResult && pReader->EditPdf(&pdfWriter))
{
if (pReader->EditPage(0))
{
pdfWriter.TEST();
}
if (pReader->EditPage(1))
{
pdfWriter.TEST();
}
pReader->AddToFile(NSFile::GetProcessDirectory() + L"/test.pdf");
}
RELEASEOBJECT(pReader);
RELEASEOBJECT(pApplicationFonts);
RELEASEARRAYOBJECTS(pData);
return 0;
}