MiServer output pages to PDF for print
9 posts
• Page 1 of 1
MiServer output pages to PDF for print
Hi!
How to convert MiServer output pages to PDF for print, exactly as used in Dyalog documentation? (the same top bar menu).
Example:
https://docs.dyalog.com/latest/APL%20Wo ... 0Guide.pdf
I think it is an app insn´t it? If so, somebody knows its name, and how to use, please?
Thanks
Marco Gantois
How to convert MiServer output pages to PDF for print, exactly as used in Dyalog documentation? (the same top bar menu).
Example:
https://docs.dyalog.com/latest/APL%20Wo ... 0Guide.pdf
I think it is an app insn´t it? If so, somebody knows its name, and how to use, please?
Thanks
Marco Gantois
- Gantois
- Posts: 89
- Joined: Thu Apr 17, 2014 9:44 am
Re: MiServer output pages to PDF for print
Hi Marco,
In Dyalog, using the htmlrenderer, I can generate a pdf from a MiServer site.
Is this what you want to do?
'hr' ⎕wc 'htmlrenderer' ('URL' 'https://miserver.dyalog.com/')
hr.PrintToPDF 'd:\tmp\mypdf.pdf'
1
Regards,
Vince
In Dyalog, using the htmlrenderer, I can generate a pdf from a MiServer site.
Is this what you want to do?
'hr' ⎕wc 'htmlrenderer' ('URL' 'https://miserver.dyalog.com/')
hr.PrintToPDF 'd:\tmp\mypdf.pdf'
1
Regards,
Vince
- Attachments
-
- mypdf.pdf
- (78.91 KiB) Downloaded 561 times
- Vince|Dyalog
- Posts: 432
- Joined: Wed Oct 01, 2008 9:39 am
Re: MiServer output pages to PDF for print
Нi Vince,
At first Thanks for your help.
Explaining my case better (example):
:Class teste: MildPage
∇ Render req;html
:Access Public
html←Example
req.Return html
∇
∇ r←Example
r←'<!DOCTYPE html>'
r,←'<html>'
r,←'<body>'
r,←'<h4>This is a HTML page example</h4>'
r,←'<p>I would like the user to be able to receive this page in pdf for print</p>'
r,←'<img src="\Img\3001.png" alt="logo" >'
r,←'</body>'
r,←'</html>'
∇
:EndClass
I tried without success:
∇ Render req;html
:Access Public
html←Example
'hr' ⎕wc 'htmlrenderer' ('HTML' html)
hr.PrintToPDF'D:\Tmp\mypdf.pdf'
req.Return html
∇
Could you help me please?
Regards,
Marco
At first Thanks for your help.
Explaining my case better (example):
:Class teste: MildPage
∇ Render req;html
:Access Public
html←Example
req.Return html
∇
∇ r←Example
r←'<!DOCTYPE html>'
r,←'<html>'
r,←'<body>'
r,←'<h4>This is a HTML page example</h4>'
r,←'<p>I would like the user to be able to receive this page in pdf for print</p>'
r,←'<img src="\Img\3001.png" alt="logo" >'
r,←'</body>'
r,←'</html>'
∇
:EndClass
I tried without success:
∇ Render req;html
:Access Public
html←Example
'hr' ⎕wc 'htmlrenderer' ('HTML' html)
hr.PrintToPDF'D:\Tmp\mypdf.pdf'
req.Return html
∇
Could you help me please?
Regards,
Marco
- Gantois
- Posts: 89
- Joined: Thu Apr 17, 2014 9:44 am
Re: MiServer output pages to PDF for print
Hi Marco!
I'm a little confused by what you're attempting. First, it looks like you're using MiServer version 2? I wouldn't attempt to call HTMLRenderer from within your MildPage - I think that overcomplicates things. I think the easiest way, assuming I have some understanding of what you're trying to accomplish, is to run your MiSite and then point an external HTMLRenderer at it. For example, the following is a really simple function to print any webpage using HTMLRenderer.
will print the page to the file /tmp/marco.pdf. You need to insert a delay in order to allow the page to finish rendering before we try to print it. There are more complex ways to accomplish waiting for the page to load, but a simple ⎕DL should suffice for this problem.
I hope this helps!
/Brian
I'm a little confused by what you're attempting. First, it looks like you're using MiServer version 2? I wouldn't attempt to call HTMLRenderer from within your MildPage - I think that overcomplicates things. I think the easiest way, assuming I have some understanding of what you're trying to accomplish, is to run your MiSite and then point an external HTMLRenderer at it. For example, the following is a really simple function to print any webpage using HTMLRenderer.
- Code: Select all
∇ url PrintTo file;h
[1] 'h'⎕WC'HTMLRenderer'('URL'url)
[2] 1 ⎕NDELETE file ⍝ remove eny existing file of the same name
[3] ⎕DL 2 ⍝ give page time to load
[4] h.PrintToPDF file
∇
'http://localhost:8088' PrintTo '/tmp/marco.pdf'
will print the page to the file /tmp/marco.pdf. You need to insert a delay in order to allow the page to finish rendering before we try to print it. There are more complex ways to accomplish waiting for the page to load, but a simple ⎕DL should suffice for this problem.
I hope this helps!
/Brian
-
Brian|Dyalog - Posts: 120
- Joined: Thu Nov 26, 2009 4:02 pm
- Location: West Henrietta, NY
Re: MiServer output pages to PDF for print
Hi Brian, How are you?
I believe this is the solution to what I'm trying to do:
print the page to the pdf file and than submit it to printer from within PDF.
Yes. I am using MiServer 2.
I will test giving you a feedback.
Thank you very much
Regards
Marco
I believe this is the solution to what I'm trying to do:
print the page to the pdf file and than submit it to printer from within PDF.
Yes. I am using MiServer 2.
I will test giving you a feedback.
Thank you very much
Regards
Marco
- Gantois
- Posts: 89
- Joined: Thu Apr 17, 2014 9:44 am
Re: MiServer output pages to PDF for print
Hi Brian!
The url PrintTo file function works nice but I still have some problems to complement the solution. This is a brief to see if I am on the right track:
We are developing a website for schools. One feature of the teacher module is to print multiples choice tests created by themselves. When the test is selected in the list an apl function (MiServer Class) build and return the html result (a test/quiz for students). Everything is working so far ...
My question is: How to create the pdf file (from test.htm to test.pdf) and then call it for printing?
The functions for tests are in the namespace abc below.
Problems after tests:
When the content file is changed (abc.HtmlTest) but not the file name, the PrintTo function keeps the last file content even if the last file no longer exists.
TEST 1: OK
abc.Html2Pdf ‘marco’
TEST 2: OK
a) abc.Html2Pdf ‘marco1’
b) change the content of HtmlTest
c) abc.Html2Pdf ‘marco2’
TEST 3: failed → did not recognize the change (b)
a) abc.Html2Pdf ‘marco3’
b) change the content of HtmlTest
c) Html2Pdf ‘marco3’
Another question:
Is it possible the program call the url after PrinTo as if the user had clicked on the url link? (perhaps by httpCommand or CURL)?
:Namespace abc
∇ Html2Pdf uid;content;url;filehtml;filepdf
url←'http://localhost:8088/Tmp/',uid,'.html'
filehtml←'C:/MiServer/etestes/Tmp/',uid,'.html'
filepdf←'C:/MiServer/etestes/Tmp/',uid,'.pdf'
content←HtmlTest
content #.Files.PutText filehtml
url PrintTo filepdf
∇
∇ r←HtmlTest
r←'<!DOCTYPE html>'
r,←'<body>'
r,←'<h4>This is a HTML page example</h4>'
r,←'<p>From html to pdf for printing</p>'
r,←'<img src="professor.png" alt="logo" >'
r,←'</body>'
r,←'</html>'
∇
∇ url PrintTo file;h
'h'⎕WC'HTMLRenderer'('URL'url)
1 ⎕NDELETE file ⍝ remove eny existing file of the same name
⎕DL 2 ⍝ give page time to load
h.PrintToPDF file
∇
:EndNamespace
Could you help me please?
Greetings!
Marco
The url PrintTo file function works nice but I still have some problems to complement the solution. This is a brief to see if I am on the right track:
We are developing a website for schools. One feature of the teacher module is to print multiples choice tests created by themselves. When the test is selected in the list an apl function (MiServer Class) build and return the html result (a test/quiz for students). Everything is working so far ...
My question is: How to create the pdf file (from test.htm to test.pdf) and then call it for printing?
The functions for tests are in the namespace abc below.
Problems after tests:
When the content file is changed (abc.HtmlTest) but not the file name, the PrintTo function keeps the last file content even if the last file no longer exists.
TEST 1: OK
abc.Html2Pdf ‘marco’
TEST 2: OK
a) abc.Html2Pdf ‘marco1’
b) change the content of HtmlTest
c) abc.Html2Pdf ‘marco2’
TEST 3: failed → did not recognize the change (b)
a) abc.Html2Pdf ‘marco3’
b) change the content of HtmlTest
c) Html2Pdf ‘marco3’
Another question:
Is it possible the program call the url after PrinTo as if the user had clicked on the url link? (perhaps by httpCommand or CURL)?
:Namespace abc
∇ Html2Pdf uid;content;url;filehtml;filepdf
url←'http://localhost:8088/Tmp/',uid,'.html'
filehtml←'C:/MiServer/etestes/Tmp/',uid,'.html'
filepdf←'C:/MiServer/etestes/Tmp/',uid,'.pdf'
content←HtmlTest
content #.Files.PutText filehtml
url PrintTo filepdf
∇
∇ r←HtmlTest
r←'<!DOCTYPE html>'
r,←'<body>'
r,←'<h4>This is a HTML page example</h4>'
r,←'<p>From html to pdf for printing</p>'
r,←'<img src="professor.png" alt="logo" >'
r,←'</body>'
r,←'</html>'
∇
∇ url PrintTo file;h
'h'⎕WC'HTMLRenderer'('URL'url)
1 ⎕NDELETE file ⍝ remove eny existing file of the same name
⎕DL 2 ⍝ give page time to load
h.PrintToPDF file
∇
:EndNamespace
Could you help me please?
Greetings!
Marco
- Gantois
- Posts: 89
- Joined: Thu Apr 17, 2014 9:44 am
Re: MiServer output pages to PDF for print
Hi Marco!
I'm currently at Dyalog24 and won't have a chance to look at your question in detail for a few days. I apologize for the delay, but wanted to let you know why I'm not able to reply more quickly.
/Brian
I'm currently at Dyalog24 and won't have a chance to look at your question in detail for a few days. I apologize for the delay, but wanted to let you know why I'm not able to reply more quickly.
/Brian
-
Brian|Dyalog - Posts: 120
- Joined: Thu Nov 26, 2009 4:02 pm
- Location: West Henrietta, NY
Re: MiServer output pages to PDF for print
I'm not sure what you are trying to achieve, but it might be easier to help you by clarifying a couple of things.
Usually it is the client that does the printing. If I use my web browser and want a site saved as pdf or sent to a printer, the web browser offers this (usually both options via a print command in the menu or as a shortcut).
If you are writing an APL program and you want to achieve the same thing programmatically, you can use the HTMLRenderer. This is basically a web browser and offers a built in print command.
If I understand you right, your users access a website you develop and serve with MiServer, so printing is not something you need to add support for, it is a feature of the browser. You could add a button to your website that triggers the print client side, but it isn't strictly necessary (see https://developer.mozilla.org/en-US/docs/Web/API/Window/print).
Webpages can be cached on the way from the server to the client to speed up browsing and reduce traffic. There are several techniques to force new content to be fetched every time, e.g. use the HTTP header directive
Good luck!
Usually it is the client that does the printing. If I use my web browser and want a site saved as pdf or sent to a printer, the web browser offers this (usually both options via a print command in the menu or as a shortcut).
If you are writing an APL program and you want to achieve the same thing programmatically, you can use the HTMLRenderer. This is basically a web browser and offers a built in print command.
If I understand you right, your users access a website you develop and serve with MiServer, so printing is not something you need to add support for, it is a feature of the browser. You could add a button to your website that triggers the print client side, but it isn't strictly necessary (see https://developer.mozilla.org/en-US/docs/Web/API/Window/print).
Webpages can be cached on the way from the server to the client to speed up browsing and reduce traffic. There are several techniques to force new content to be fetched every time, e.g. use the HTTP header directive
- Code: Select all
Cache-Control: no-cache
Good luck!
- gil
- Posts: 72
- Joined: Mon Feb 15, 2010 12:42 am
Re: MiServer output pages to PDF for print
Hi Brian! Thank you for the feedback.
Hi Gil!
Thanks for your clarifications. Like you said, my users access a website we develop and serve with MiServer. The reports to be printed depends on the user's choice from a list of options.
I understood that your last recommendation is appropriate for my case. I will see your link.
I will se the tip about cache too.
Thank you,
Greetings
Marco
Hi Gil!
Thanks for your clarifications. Like you said, my users access a website we develop and serve with MiServer. The reports to be printed depends on the user's choice from a list of options.
I understood that your last recommendation is appropriate for my case. I will see your link.
I will se the tip about cache too.
Thank you,
Greetings
Marco
- Gantois
- Posts: 89
- Joined: Thu Apr 17, 2014 9:44 am
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group