How to define a public function in a CXP application

This forum is for conversations about Internet development using CXP, WebSockets, HttpEndPoint, etc.
Message
Author
Diego Euri Almanzar
Posts: 174
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to define a public function in a CXP application

#11 Post by Diego Euri Almanzar »

Dear Slavoljub Damnjanovic,

I have hundreds of reports in my desktop app that I don't plan on losing in my new web app. I don't think there is a need to spend years doing all those reports again, time that can be spent on more productive matters.

For example, how would you do the following in your library, and send it to the browser?

SET DEVICE TO PRINT
ROW := 0
USE CUSTOMERS NEW
GO TOP

DO WHILE .NOT. EOF()
ROW++
@ROW, 1 DCPRINTSAY NAME FONT "10.ARIAL"
SKIP
ENDDO
SET DEVICE TO SCREEN

With the Express library, these reports can be automatically converted to PDF.

Why PDF? because the PDF saves the attributes of the text. If you convert it to a TXT document, attributes like FONTS, etc. would be lost.

And, if it exists, jspdf, and other tools, it's because the PDF document remains an important document type on the Web.

Anyway, that's why I'm looking for your help to display a PDF in the browser, or the help of anyone. If you have a solution in your library, much better.

Thanks.

User avatar
SlavkoDam
Posts: 111
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How to define a public function in a CXP application

#12 Post by SlavkoDam »

Hi,

In PowerWin library, you can do the same task with this:

DbOpen(,{{"Customers"}})
ExpDb(,{"Name"},,,,,"P")

These 2 lines will automatically create a PDF file with all records of a db. You can save a PDF file or display it automatically in Acrobat Reader. With other parameters in ExpDb() you can define a condition to export only selected records, attributes for font, color, width, height, align of rows, but also others export formats: Word, Excel, HTML, XML, SDF, CSV, DBF. As you see, this is more versatile and the code is extremely shorter than in Express library, and text attributes are preserved in all document formats.

I am not familiar how Express converts a report to a PDF file, using some external converter or its own Xbase++ code. In PowerWin library, I have developed my own pure Xbase++ code for converting a report to all export formats. So, I generate Word, Excel, PDF, HTML files in pure Xbase++ code, by programming theirs respective document specifications. I can say that this is quite complicated. You have to learn Word and Excel VBA, PDF native format reference, HTML programming, etc.

I understand what you said about PDF, but as I said its your way and, as you see in PowerWin library, there are other export formats of reports. Clients of my applications use formats as they wish, they are all available to them.

The main reason why PDF format is the most popular, is that its much faster that other formats, both for creating and displaying. But, PDF format is the most complicated to program, by my experience.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Diego Euri Almanzar
Posts: 174
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to define a public function in a CXP application

#13 Post by Diego Euri Almanzar »

Dear Slavoljub Damnjanovic

You have understood me very well, and I thank you very much. Although you are a very hard-working person, and with many work commitments, you give me help, or attention.

Taking advantage of the fact that I have been able to capture your attention, I will tell you that your recommendation is excellent. The problem is that I have hundreds of reports done in my desktop application, and I don't want to lose them. And in order not to lose them, I only need to be able to enter the pdf into a browser. With traditional HTML options, uploading a local PDF is problematic, because the browser blocks the display. There are options with jspdf, and other libraries, but I still don't handle them well.

I know you have understood me correctly, but here I attach something more complete on how I generate the PDF. Although, I repeat, with the generation I have no problem. Also, I reiterate that I do not want to start from scratch, I want to save my reports.

Precisely what you recommend is what I am avoiding, starting from scratch. If I were to decide to start developing all the reports, again, I would use your library options, or the Express options. An example of the Express options for reporting would be the following:


GetList := {}

DCTABLE OBJECT oTable ROWS CUSTOMER->(RecCount()) COLUMNS 4 CLASS 'dctable' WIDTH 800

@ DCHTML_TABLE_HEADER, 1 DCHTML 'Name' PARENT oTable
@ DCHTML_TABLE_HEADER, 2 DCHTML 'Street' PARENT oTable
@ DCHTML_TABLE_HEADER, 3 DCHTML 'City' PARENT oTable
@ DCHTML_TABLE_HEADER, 4 DCHTML 'State' PARENT oTable

CUSTOMER->(dbGoTop())
nRow := 1
DO WHILE !CUSTOMER->(Eof())
@ nRow,1 DCHTML CUSTOMER->bill_name PARENT oTable
@ nRow,2 DCHTML CUSTOMER->bill_strt PARENT oTable
@ nRow,3 DCHTML CUSTOMER->bill_city PARENT oTable
@ nRow,4 DCHTML CUSTOMER->bill_state PARENT oTable
CUSTOMER->(dbSkip())
nRow++
ENDDO

DCREAD HTML TO cHtml

? cHtml

CUSTOMER->(dbCloseArea())


I know that your library is very powerful, versatile, and intelligent, and since I am out of my initial stage of the migration process, I will be using your library through CXP. If I'm using Express through CXP, it will be much easier to use your library, since it's fully web-based. And, excuse my obstinacy, my confinement, but I will not return to zero. I'll try to save the reports I have.

Does your library have a way to upload PDFs that are already done or made?

User avatar
SlavkoDam
Posts: 111
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How to define a public function in a CXP application

#14 Post by SlavkoDam »

Hi Diego,

With PowerWin library you can do the same task with this:

ExpDb("Customer", {"bill_name","bill_strt","bill_city","bill_state"},,,,,"H","Customer.html")

The report will be saved in a specified file. You can read it and display in a dialog window as you did, or send it to an Internet browser to display a customer table.

With PowerWin you can open any existing PDF file and display it in Acrobat Reader. Similar, you can display any doc file in MS Word, any xls file in MS Excel, any HTML file in Internet browser. You can do the same in web app. Its not necessary to display PDFs in Internet browser, you can display them in Acrobat Reader.

I understand you that you have done so much so far and you cannot start from scratch, and its normal.

Express is a great work, but it has an uncomfortable app programming style, with commands. As I said on my site, Power* libraries have programming building blocks, all in one functions for any programming task. Using them, programmers can "do more and write less". App programs are very short and compact.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Diego Euri Almanzar
Posts: 174
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to define a public function in a CXP application

#15 Post by Diego Euri Almanzar »

Dear Slavoljub Damnjanovic,

my problem has always been to look for the easy, because after old, it is difficult to start again. Sure, I know I think wrong, but it's my way. Therefore, I searched for years, a framework for the web, with the same characteristics for the Web, so as not to have to work much.

I was stubborn about not learning HTML, and years went by without me doing anything of importance. Anyway, I'm already involved with HTML, with CXP, EXPRESS, and with your library, and I feel very experienced. I've already started developing my HTML views, and everything is going great. However, I refuse to run all my reports again. Sooner or later, I know I'll find a way to upload a PDF to the browser.

Maybe you have some function in PowerWeb to upload PDF to a browser. I attach two screenshots: One HTML, and one CXP. HTML displays the PDF seamlessly. Whereas, CXP does not show it. I was reading that it is a browser security configuration. This is called FakePath. Maybe I will learn to disable this option in the browser, the problem will be solved.

Thanks.
Attachments
HTML.jpg
HTML.jpg (251.6 KiB) Viewed 10781 times
CXP.jpg
CXP.jpg (82.04 KiB) Viewed 10781 times

skiman
Posts: 1195
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to define a public function in a CXP application

#16 Post by skiman »

Hi,

I saw the error on your screenshot. Have you set the content-type to application/pdf?
Best regards,

Chris.
www.aboservice.be

Diego Euri Almanzar
Posts: 174
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to define a public function in a CXP application

#17 Post by Diego Euri Almanzar »

Hi, Chris (Skiman),

I really appreciate your collaboration. Sometimes, I get obsessed with things, and I waste a lot of time studying the cases that I have not been able to achieve. When you should spend your time on more productive things. And, that has happened with the study of uploading a PDF to the browser.

I've been at it for almost two months, and I haven't made it. A week ago, I discovered an example that Alaska Software has, regarding CXPs, and file uploads to the WEB. They, like many authors, indicate that a local file cannot be uploaded, if not through <input type="file"> I wanted to avoid using
<input type="file"> because I need to upload a file directly without user intervention.

Alaska Software explains in the upload.cxp example that they can read a local file, even place its content in a DBF field, but as always, they make use of <input type="file">

Also, I don't understand how they would upload the content of an image to a database field, or the content of a PDF, etc.

They explain, more or less the following:

This sample shows how to upload files from the web browser to a
/// CXP page. After a file was uploaded, it can be processed within
/// the page using the member variable :Files of the HttpRequest
/// object.
///
/// The sample first loads the HTML file upload.html that provides
/// the user interface for selecting files that shall be uploaded.
/// To make a file selectable in the HTML browser, an input element
/// of type "file" must be specified in the HTML markup. In addition,
/// the attributes of the HTML form which contains the input element
/// must be set up as follows: the method attribute must be set to
/// "post", and "multipart/form-data" must be specified for the
/// enctype attribute.

<form action="upload.cxp" method="post" enctype="multipart/form-data">
<input type="file" name="filedata" />
<input type="submit" name="SubmitButton" />
</form>




UPLOAD.CXP
The following code fragment illustrates processing of the uploaded file in the <CXP/>
page upload.cxp. In the example, the file content is stored in a database:

<%
IF 0 != ::HttpRequest:Files:NumItems
oHttpUploadedFile := ::HttpRequest:Files:filedata
cData := oHttpUploadedFile:Data
IF oHttpUploadedFile:LastError == 0
FILESTORE->CONTENT := cData
? "<h1>File was stored to database</h1>"
ELSE
? "<h1>Error oHttpUploadedFile:LastError</h1>"
? "<b>ErrorMessage:</b>"
? "<p>"
? DosErrorMessage(oHttpUploadedFile:LastError)
? "</p>"
ENDIF
ENDIF
%>

User avatar
SlavkoDam
Posts: 111
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How to define a public function in a CXP application

#18 Post by SlavkoDam »

In CXP is not possible to upload files larger than 100.000 Kb, with INPUT type="file". CXP reports an error, no matter do you use upload folder or not. You can test this in that Alaska demo.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Diego Euri Almanzar
Posts: 174
Joined: Thu Nov 05, 2020 10:51 am
Location: DOMINICAN REPUBLIC

Re: How to define a public function in a CXP application

#19 Post by Diego Euri Almanzar »

Dear Friend,
Slavoljub

I know you are a very busy person, and I really appreciate your help. Although I must explain myself better so that you can help me. The thing is that I found an example, in the Alaska web examples, which indicates that it talks about an alternative to upload files to the browser, and that you have to upload them through input files.

But, I don't want to upload them via input - files. I want to upload them through an iframe, or an Html object, as is normally done with a pdf. I have continued investigating and everything indicates that I will not be able to upload it, unless I convert my normal path (C:\tmpfiles\myfile.pdf) to a URL "http://www.example.com/myfile.pdf">

This requires a program that turns my computer into a web server, which can be identified with a URL. I've started thinking of alternatives. Perhaps Apache software can help, although I have no knowledge of it.

Thanks.

User avatar
SlavkoDam
Posts: 111
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

Re: How to define a public function in a CXP application

#20 Post by SlavkoDam »

Hi,

I understood very well your intention to not use file upload, but I wanted to pass my experience with that in CXP and its failure.
If you want to send a file without uploading it, you can do that with HTTP POST request. Read the file content, specify the content type and send it with HTTP POST.
As of your comment from previous post, "Also, I don't understand how they would upload the content of an image to a database field, or the content of a PDF, etc.", that could be done with database binary field type. In a binary field you can put content of any type, including EXE and COM.
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Post Reply