Qt and PDFCreator as library

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
Tony21
Posts: 7
Joined: Tue May 09 2017

Qt and PDFCreator as library

Post by Tony21 » Tue May 09 2017

Hi guys,
First of all I want to know you I am beginer with Qt proj and also I never use any of Amyuni product before.
So I need to implement Amyuni PDF library to existing Qt proj.
So in documentation they say I can use Amyuni PDFCreator as library
without using their PDFCreator control which is an activeX control.
So here in documentation they said that:
https://www.amyuni.com/WebHelp/Develope ... mation.htm

(BTW I using C++ and MS Visual Studio 2013)
My questions are:
1. How can I import their dll elegantly without using #import "/pathToTheDLL"
to my Qt project.
2. Why they generate that 2 additional dlls. Do I need them at all?

THANK YOU ALL IN ADVANCE

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Re: Qt and PDFCreator as library

Post by Jose » Wed May 10 2017

Hi Tony,

Sorry but I am not very familiar with the Qt Creator.

The link below points an example that shows how to use the PDFCreator control as a library in an MFC console application. The file Win32ConsoleApp.cpp is the only file (in addition to stdafx.cpp) that is produced by the Visual Studio wizard.


https://www.amyuni.com/WebHelp/Amyuni_P ... cation.htm


Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Re: Qt and PDFCreator as library

Post by Jose » Wed May 10 2017

Hi Tony,

Here some additional information.

#import "PDFCreactiveX.dll" raw_interfaces_only raw_dispinterfaces
rename("GetObject", "PDFCreactiveX_GetObject")
rename("TextOut", "PDFCreactiveX_TextOut")
rename("GetCharWidth", "PDFCreactiveX_GetCharWidth")
rename("DrawText", "PDFCreactiveX_DrawText")

The above call results in the two attached file: pdfcreactivex.tlh and .tli. That can be used in the C++ Qt application. Please send an email to support@amyuni.com and I will forward them to you.

The user can experiment with the various #import attributes and chose the ones they prefer, see documentation here:
https://msdn.microsoft.com/en-us/library/298h7faa.aspx

Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Tony21
Posts: 7
Joined: Tue May 09 2017

Re: Qt and PDFCreator as library

Post by Tony21 » Thu May 11 2017

Thank you all for effort.

I followed these steps in the sample: https://www.amyuni.com/WebHelp/Amyuni_P ... cation.htm

1, I registered PDFCreactiveX.dll via regsvr32
2, I import the file like this

Code: Select all

#import "Amyuni/SDK/Win32/PDFCreactiveX.dll" 
to my stdafx.h
3, But now when I include stdafx.h in my global.h header, which is my header where I include my all third party sdk's and istantiate them.

So this is doesnt work:

Code: Select all

  IPDFCreactiveXPtr gPDFptr;
Compiler does not know what IPDFCreactiveXPtr is and I also need make it a global variable to work with the same instance in other cpp's.

PLEASE help !!!

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Re: Qt and PDFCreator as library

Post by Jose » Thu May 11 2017

Hello,

To debug this situation further I have downloaded the Qt Creator Community edition and believe I am able to add access the PDF Creator COM object. I suspect that there may be more efficient ways to add a COM object to Qt but I will leave that up to you.

Please follow the steps below:

You need to generate a pdfcreactivex.tlh and pdfcreactivex.tli that you will later include in your project. To create this .tlh and .tli files create a Qt console project and add the import statement below to the main.cpp file. When you compile the console app, Qt will automatically generate this two wrappers.

#import "PDFCreactiveX.dll" raw_interfaces_only raw_dispinterfaces rename("GetObject", "PDFCreactiveX_GetObject") rename("TextOut", "PDFCreactiveX_TextOut") rename("GetCharWidth", "PDFCreactiveX_GetCharWidth") rename("DrawText", "PDFCreactiveX_DrawText")

Image


Next step is to copy or add both pdfcreactivex.tlh and pdfcreactivex.tli files to your main project. In this project, you will also need to add the include and using statements below.

Code: Select all

#include "pdfcreactivex.tlh"    //Add this
using namespace ACPDFCREACTIVEX; //Add this
You can assess the PDF Creator object using the code below:

Code: Select all

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    //initialize com object
     CoInitialize(0);

     IPDFCreactiveXPtr pdf;
     pdf.CreateInstance (__uuidof(PDFCreactiveX));

     pdf->SetLicenseKey (_bstr_t("Amyuni Tech Eval"),_bstr_t("07EFCDAB01000100FB0841E772A5FDC96C023E0C9C2E53F235719C2E3A4F4653C93F512EC24A1F3B864FE74002ECF3BC499975DD2A92"));

     long ret = 0;
     pdf->OpenEx(_bstr_t("C:\\temp\\AMYUNI.pdf"), _bstr_t(""), &ret);

     CoUninitialize();

    return app.exec();
}

Image
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Tony21
Posts: 7
Joined: Tue May 09 2017

Re: Qt and PDFCreator as library

Post by Tony21 » Thu May 11 2017

Jose, I do what you suggest me! look :
1, Import dll
Image

2, Rebuild project and copy the two generated files (pdfcreactivex.tlh and pdfcreactivex.tli) from Debug folder to my Include dll folder.
Including in code as well + using namespace.
Image

3. Trying to reach lPDFCreactivXPtr
Image

So still can make it work. I missing something ?
Please sent me skype name hrvth.tony@gmail.com maybe we can solve it there together. I really need to make it work.

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Re: Qt and PDFCreator as library

Post by Jose » Fri May 12 2017

Hello,

Can you also add the CoInitialize(0) function? You need to initializes the COM library

Code: Select all

    //initialize com object
     CoInitialize(0);

     IPDFCreactiveXPtr pdf;
     pdf.CreateInstance (__uuidof(PDFCreactiveX));
     pdf->SetLicenseKey (_bstr_t("A....uni"),_bstr_t("07EFCDA.....0874F198"));
     long ret = 0;
     pdf->OpenEx(_bstr_t("C:\\temp\\AMYUNI.pdf"), _bstr_t(""), &ret);

     CoUninitialize();
Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Tony21
Posts: 7
Joined: Tue May 09 2017

Re: Qt and PDFCreator as library

Post by Tony21 » Mon May 15 2017

Big thanks to Jose for your patience, you help me a lot.

I have to ask you again for your help with this.

I typed this to my code just to open the a simple pdf.

Code: Select all

//Constants for Activation codes
	bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";
	bstr_t strActivationCode = "07EFCDAB010001004282943FD8F19A88F332D9E7816403607A6D79A42847A1BDE06DB61C1BE94E2D90424BF8762389335F9D3084E9FC";
	
	CoInitialize(0);

	ui.setupUi(this);

         // Get pointer to ActiveX control in  Qt according to this Qt documentation http://doc.qt.io/qt-4.8/qaxbase.html#queryInterface
        // I am not sure if it do what I expect
	long lo = ui.axWidget->queryInterface(QUuid(ui.axWidget->control()), (LPVOID*)&pdf);

	//Create the PDFCreactiveX instance
	pdf.CreateInstance(__uuidof(PDFCreactiveX));

	//set license key
	pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));

	//Open an existent PDF file
	_bstr_t fileName = "c:\\users\\tony\\downloads\\dd.pdf";
	_bstr_t password = "";
	pdf->Open(fileName, password);

	long lPages = pdf->GetPageCount();
Everything goes ok I get 217 pages which is ok. But I cant see the pdf in that ActiveX control, I put on my Qt form.
Just this always the same Amyuni template page not my document. Why it is ??
Image

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Re: Qt and PDFCreator as library

Post by Jose » Wed May 24 2017

Hello,

In the examples above we have been creating a PDF Creator object in memory and accessing this object’s properties and methods.
Example:

Code: Select all

pdf.CreateInstance (__uuidof(PDFCreactiveX));
To be able to view and interact with a PDF document in a PDF Creator object hosted in your Qt form, you need to access that object (PDF Creator object on your Qt form).

To illustrate this, I will refer to a MFC Example:

On a dialog add the PDF control. Add the PDF control as a variable to the dialog named it PDF.
You can access the PDF control through the PDF object

Code: Select all

PDF.Open("test.pdf", "");
Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Post Reply