TOPIC: Print Preview (User's Manual)
Print Preview (User's Manual) 3 Years, 6 Months ago
Under XP, when logged in as a plain user, I cannot print preview the User Manual Pages. The error message is: "Unable to create temp file for printing. Check Permissions." Suneido then goes into la la land and pegs the CPU out at 90+%www. When logged in as Admin, the print preview works and I notice that the temp file is created at c: (the root of c:).

The PreviewPageControl uses GetTempPath() to determine the temp file name. This "function" returns the proper temp path of my system -> "C:\DOCUME~1\OliverA\LOCALS~1\Temp\". So why is the print preview for the User's Manual creating a temp file at c: instead of the temp path?
Re:Print Preview (User's Manual) 3 Years, 6 Months ago
Preview and Print from the Help do not use PreviewPageControl because they are not part of the report framework. Instead, the code is in BookControl print which uses the browser control's print. It was hard coded to "c:/temp" - not good.

I changed the code to:


   filename = GetTempFileName(GetTempPath(), "su")
    BookPrint(.book, start, filename, cmd: cmd,
        title: .Title, back: .browser.Current())
    .browser.Goto("file:///" $ filename)

This seems to work. But I also noticed that it was not deleting the temporary file, so I added (right after the above code:


   Delayed(0, Curry(.delete_temp, filename))

You need the delay to give the browser a chance to open the file. (It is ok to delete a file when it is open, the actual delete will occur when it is closed.) A delay of zero means the function will get executed as soon as the message loop runs again.

Post edited by: andrew, at: 2007/02/23 00:23
Re:Print Preview (User's Manual) 3 Years, 6 Months ago
Copied the BookControl over to "mylib" and modified the code (for temp file location) as show and it works great!

More problems:

The tabs Contents, Tools, and User Interfaces seem to lock up when I choose Preview Section or Print Section. I've let the computers (here at home and at work) sit there for about 30 minutes w/o any results. The temp files for both Suneido and IE (yup, Suneido createas a temp file (su[1...].tmp) and IE creates a temp 1to8RandomCharacters.htm) are created, but the preview/printing never happens. Both Suneido's and IE's files pull up fine when used w/IE and/or Firefox outside of Suneido.


I exported the BookControl record from stdlib and imported it into mylib. Nothing showed up under mylib until I closed out the Library view and opened it back up. May already be covered in another forum thread...

Thanks for the prompt response!

Re:Print Preview (User's Manual) 3 Years, 6 Months ago
We have had the same problem previewing or printing large sections (or entire manuals). It seemed to "break" after one of the Internet Explorer updates. Suneido is simply calling the IE COM control so I am not sure what to do to fix this.

The alternative is to export to a single html file and then print from that.

Import not updating the tree is a known problem - just haven't got around to fixing it.
Re:Print Preview (User's Manual) 3 Years, 6 Months ago
Size might be a factor. I don't know why Tools does not print, but Language does (language is larger). After trying to preview Getting Started (seemed to work before), an error message (see attached image file) popped up. Please note, this is the first time for such an error message. I've received another one at one time (along the lines of hwx... or something), but I do not have a screen capture for it (will provide if it happens again). The annoying part of this is that it hangs Suneido. Would be nice if the crashing of IE's com would not affect the continuation of Suneido.

Of course, since the temp files are left after Suneido crashes, I've used them and opened and print previewed them just fine in IE by itself (even the Contents tab, which becomes a 1MB+ file).


Re:Print Preview (User's Manual) 3 Years, 6 Months ago
I have wondered it it is something to do with the IE browser component using threads so it calls the SuneidoAPP function "asynchronously" at a "bad" time. This might explain the inconsistency and the strange errors.

Unfortunately, I still do not know how to fix it.

One "solution" would be to run an HttpServer and access the help via an external browser. This would also be more portable e.g. to Linux where there is no IE browser component (but there are external browsers).
Re:Print Preview (User's Manual) 3 Years, 6 Months ago
It's the images. Take the images out and it works fine. Tools and User Interfaces have the most images. The individual "chapters" within those two tabs print fine, but together - IE hangs. After taking all the images out of Tools, the preview worked. BTW, the temp files that were created did not have the images and thus IE could preview them (even the full Contents).

All the other tabs use images sparingly and thus seem to not hang IE.

External may be the way to go, kills some of the "integration" though. Wxwidgets has a html widget. Gecko?
Re:Print Preview (User's Manual) 3 Years, 6 Months ago
Interesting. Could still be threads since IE probably downloads images "in the background".

I have thought about Gecko and looked at it a little, I think I even saw somewhere that there is a COM wrapper that is compatible with the IE one. One drawback is that it would mean another big component to deploy along with Suneido. The nice thing about IE on Windows is that everyone already has it.

If we ever decide to use wxWidgets with Suneido (e.g. for Linux) then their html control would be an obvious alternative.
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
I've modified BookPrint in such a way that it dumps the images to a temp directory. IE will then actually preview the whole book w/o bombing out. Please note that the modification assumes the temp file change to BookControl that you provided. One todo item up front: The deletion of the temp pictures.

Please note when dumping the Tools tab, that the Library view png and the BookEdit png files do not show up in the print preview. If you open the temp file up in IE, the images show up when viewing the page, but the print preview does not show these two images (there may be more, those are the two that jumped right out).

File Attachment:
File Name: BookPrint.txt
File Size: 2662
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Good idea! Now the browser will not be calling Suneido (SuneidoAPP) to get the images, which eliminates the possibility of getting called at a "bad" time (i.e. in the middle of something)

Our users will be happy :-) since we have been telling them they could not print the help.

The only problem will be knowing when to clean up the temp files, since we do not easily know when the previewing/printing is finished.
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
I added your changes to stdlib and it seems to work well.

I am not sure why those two screenshots do not work. I will try re-doing them.

BTW You can copy records from one library to another with right-click copy and paste (in the Library View tree) instead of export/import. You can also drag but that moves rather than copies. (todo: support Shift+drag for copy)
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Figured out a bug in the process code:

Instead of

if x.path isnt '/res' and text.Prefix?('<') .f.Writeline(Asup(x.text.Replace("suneido:/" $ .book $ "/res", .images)))

it needs to be

if name isnt '/res' and text.Prefix?('<'>
.f.Writeline(text.Replace("suneido:/" $ .boook $ "/res", .images))

1) I've noticed that x.path will never be /res...
2) I needed to process text, not x.text...

I've got a couple of ideas about the temp files... Will post some more later (dinner calls...)
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Ugh...! the forum ate my text!!!

if x.path isnt '/res' and text.Prefix?('<')
.f.Writeline(Asup(x.text.Replace("suneido:/" $ .book $ "/res", .images)))

if name isnt '/res' and text.Prefix?('<')
.f.Writeline(text.Replace("suneido:/" $ .book $ "/res", .images))
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Temp file handling. If Suneido provided its own temp directory in %temp%, programmers could dump any temp files they produced there. Then on exiting Suneido, a cleanup routine could be called to mop up the mess.

The previous BookControl code could be

filename = GetSUTempFileName("suneidoc", "su")
BookPrint(.book, start, filename, cmd: cmd,
title: .Title, back: .browser.Current())
.browser.Goto("file:///" $ filename)

GetSUTempFileName could be

function (path = "", prefix = "su", unique = 0)
dir = GetSUTempPath()
if path isnt "" {
dir = dir $ '\' $ path
CreateDirectory(dir, 0)
if 0 is GetTempFileNameApi(dir, prefix, unique, buf = Buffer(512))
throw "GetSUTempFileName failed"
return buf

and GetSUTempPath could be

function ()
dir = GetTempPath() $ 'Suneido'
CreateDirectory(dir, 0)
return dir

Then some magical function would be needed that would clean up the mess upon Suneido's startup/shutdown.

Got some more ideas on temps, but they may be way overboard...
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Cleaning up on exit seems reasonable. I am not sure where the best place to put the "on exit" code is. Maybe connect it to Window exitOnClose.

I changed your code slightly to:


if name isnt '/res' and text.Prefix?('<')
    // Rewrite image path
    x.text = x.text.Replace("suneido:/" $ .book $ "/res", .images)

I am not sure if we need the "text.Eval()" any more. It is not really needed when we have Asup. Actually, Asup should probably be replaced by InvertHtml since it allows things like conditionals and loops which are not supported by Asup. However, InvertHtml requires properly formed XML (i.e. XHTML) so some pages might have to be cleaned up. (An interface to TidyHTML would be nice.)

Also, Asup is not run by default - HtmlWrap applies it selectively. I think this was originally done for speed reasons, but now we could probably just always apply it. (Like BookPrint does.)

Thanks again for your contributions.
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Eval() seems to be needed for the things like Cookbooks content of:

BookMenuPage("/suneidoc/Cookbook", 1)

Asup() does not "expand" this statement. That was my whole reason for my fix. Instead of inserting the html that the BookMenuPage returns, BookPrint (that I provided, not Suneido's) actually inserted the following:

BookMenuPage("/suneidoc/Cookbook", 1)

Thus, Eval() may have to run before Asup...

sorta like


text = x.text
// First handle BookMenuPage()
if (not text.Prefix?('<'))
    text = text.Eval()
// Handle any other substitution
text = Asup(text)


x.text = x.text.Replace("suneido:/" $ .book $ "/res", .images)

probably needs to be


text = text.Replace("suneido:/" $ .book $ "/res", .images)

otherwise you'll have the same problem that I had -> BookMenuPage(...) appearing in the html output instead of the intended html that BookMenuPage produces.

P.S.: How did you get all the color in your code snippet? By hand?
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
Oh! The preview did not show the colors!
Re:Print Preview (User's Manual) 3 Years, 5 Months ago
We would need to change that kind of thing to:


<$ BookMenuPage("/suneidoc/Cookbook", 1) $>

Thanks for catching my mistake.