Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Skylark app - create pdf and donwload it
Skylark app - create pdf and donwload it [message #55986] Sat, 09 January 2021 13:47 Go to next message
BetoValle is currently offline  BetoValle
Messages: 78
Registered: September 2020
Location: Brasil Valinhos SP
Member
Hi,

I haven't found an example of how to create a pdf and download it using a skylark application.
could someone suggest an example to me?

Thanks!
Re: Skylark app - create pdf and donwload it [message #55987 is a reply to message #55986] Sat, 09 January 2021 16:02 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 310
Registered: August 2018
Location: France
Senior Member
You mean, download file using skylark ?

Re: Skylark app - create pdf and donwload it [message #55990 is a reply to message #55987] Sat, 09 January 2021 18:47 Go to previous messageGo to next message
BetoValle is currently offline  BetoValle
Messages: 78
Registered: September 2020
Location: Brasil Valinhos SP
Member

are two linked situations:
how to create a pdf (like a simple report like a hello world) and download it, in a skylark application.
Re: Skylark app - create pdf and donwload it [message #55991 is a reply to message #55990] Sat, 09 January 2021 20:28 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 310
Registered: August 2018
Location: France
Senior Member
Well, to generate a PDF I can't realy help you. But to download a file via skylark I did this :


SKYLARK(DownloadURL,"/url/**"){
	if( http.GetParamCount() > 0){
		bool find = false;
		for(FileURL& fu : GetApp().AllURL){
			if(fu.URL.IsEqual((String)http[0])){
				find = true;
				if(fu.file){
					if(FileExists(fu.file->FilePath)){
						if(fu.TotalDownloadNumber == -2 || (fu.TotalDownloadNumber > fu.DownloadNumber)){
							fu.DownloadNumber++;
							http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") <<  LoadFile(fu.file->FilePath);
						}else{
							http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") <<  LoadFile(fu.file->FilePath);
							GetApp().RemoveURL(fu.Id);
						}
					}else{
						http("FILEREQUIRED","url/")("ERROR_CODE",204)("ERROR_STRING", "File no longer exist on server.").RenderResult("views/notFound").Response(204,"File no longer exist");
					}
				}else{
					http("FILEREQUIRED","url/")("ERROR_CODE",204)("ERROR_STRING", "File no longer exist on server.").RenderResult("views/notFound").Response(204,"File no longer exist");
				}
				break;
			}
		}
		if(!find){
			http("FILEREQUIRED","url/")("ERROR_CODE",404)("ERROR_STRING", "Bad URL requested.").RenderResult("views/notFound").Response(404,"Bad URL requested");
		}else{
			http("FILEREQUIRED","url/")("ERROR_CODE",400)("ERROR_STRING", "Something went wrong.").RenderResult("views/notFound").Response(400,"Something went wrong");
		}
	}else{
		http("FILEREQUIRED","url" )("ERROR_CODE",400)("ERROR_STRING", "Bad request, no argument passed.").RenderResult("views/notFound").Response(400,"Bad request, no argument passed");
	}
}


The importante line is :

http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") <<  LoadFile(fu.file->FilePath);


[Updated on: Sat, 09 January 2021 20:30]

Report message to a moderator

Previous Topic: Keyboard navigation doesn't work
Next Topic: skylark with server and client
Goto Forum:
  


Current Time: Wed Jan 27 17:11:38 CET 2021

Total time taken to generate the page: 0.01504 seconds