Does exists a framework (classes) to generate a PDF

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Does exists a framework (classes) to generate a PDF

Postby SchubYu » Wed Mar 17, 2010 5:34 am

We need to generate classes and do not want to use a DLL. Do you provide a ConfMap for it?
SchubYu
 
Posts: 1
Joined: Wed Mar 17, 2010 4:52 am

Re: Does exists a framework (classes) to generate a PDF

Postby Bob Whitefield » Wed Mar 17, 2010 5:54 pm

SchubYu wrote:We need to generate classes and do not want to use a DLL. Do you provide a ConfMap for it?

Why not simply print to a PDF driver like Adobe's or CutePDF?

Bob
Bob Whitefield
[|]
 
Posts: 17
Joined: Thu May 01, 2008 7:41 pm

Re: Does exists a framework (classes) to generate a PDF

Postby ricardovp » Fri Sep 10, 2010 12:04 pm

Hi!

I've created a report on my application that must be saved as a PDF file. The problem is that each page of the report must be a different PDF file... With CutePDF I can't do this without prompt the user for a filename in each page, but if I have 100 pages that could become anoying for the user...

Could you help me to find a way to do that without pompting the user for each file?

Thanks guys
ricardovp
 
Posts: 5
Joined: Thu Sep 09, 2010 11:05 am

Re: Does exists a framework (classes) to generate a PDF

Postby benvandijk » Sat Sep 11, 2010 12:16 pm

It is possible to send your prints to files without bothering the user.
You have to tweak the common printing framework in VAST.

I can only give you the changes for Windows, that is the one i tweaked. :)

First you have to define an instance variable for the filename in the CwPrinterShell class and a getter and setter.
I used xmNFile vor the instance variable, fileName and fileName: for the getter en setter.
Next you have to change two methods:

Code: Select all
initializeResources
   "Initialize the receiver's default resource values."

   xmNx := 0.
   xmNy := 0.
   xmNwidth := 0.
   xmNheight := 0.
   xmNx := 0.
   xmNfile := nil.
   xmNtitle := ''.  "$NON-NLS$"
   pageNumber := 0.
   resolution := 0 @ 0.

   self initializeScreen


and more importantly:
Code: Select all
createDocInfoStruct
   "Answer a newly created OSDocinfo structure."

   ^OSDocinfo new
      lpszDocName: xmNtitle asPSZ copyToOSMemory;
      lpszOutput: (xmNfile ifNotNil: [:string | string asPSZ copyToOSMemory]);
      cbSize: OSDocinfo fixedSize;
      yourself


Now you need to get the filename to the printer shell at the right time:

Go to class CoTemplate and add an instance variable fileName, getter fileName and setter fileName:
Next go to class CoPaginatingDevice and change the method:
Code: Select all
initiateOutput
   "Allocate graphical resources and begin output.
   
   Return value
      Not specified."

   "Set the title of the print job."
   self widget
      title: self class printJobTitlePrefix  , self template title;
      fileName: self template fileName;
      startJob.

   super initiateOutput


Now you can assign the filename to your print:
Code: Select all
      myReport coElement fileName:anyFileName.
      myReport printer: printer.
      myReport print.


In this case myReport is an instance of a AbtAppBldrReport

Lastly, if you use a print previewer you have to add the setter fileName: to the EuPrintPreviewerShell class too

Happy printing,

Greetings, Ben
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: Does exists a framework (classes) to generate a PDF

Postby ricardovp » Tue Sep 21, 2010 5:49 am

Hi Ben!

Thanks for your answer! Now I can create my Post Script files without prompting the user for a filename!

To generate a PDF file from a PS (Post Script) file I'm using Ghostscript... I've managed to do so using the AbtProgramStarter class and setting some parameters, but I want to use the Ghostscript DLL... I'm not used to use the PlatformFunction class, so I'm hoping that you guys may helpe me...

In the DLL I have the following functions that I have to call:

Code: Select all
int gsapi_new_instance (void **pinstance, void *caller_handle);
int gsapi_init_with_args (void *instance, int argc, char **argv);
int gsapi_exit (void *instance);
void gsapi_delete_instance (void *instance);


And I've got the following example to use them in C:

Code: Select all
/* Example of using GS DLL as a ps2pdf converter.  */

#if defined(_WIN32) && !defined(_Windows)
# define _Windows
#endif
#ifdef _Windows
/* add this source to a project with gsdll32.dll, or compile it directly with:
*   cl -D_Windows -Isrc -Febin\ps2pdf.exe ps2pdf.c bin\gsdll32.lib
*/
# include <windows.h>
# define GSDLLEXPORT __declspec(dllimport)
#endif

#include "ierrors.h"
#include "iapi.h"

void *minst;

int main(int argc, char *argv[])
{
    int code, code1;
    const char * gsargv[10];
    int gsargc;
    gsargv[0] = "ps2pdf";    /* actual value doesn't matter */
    gsargv[1] = "-dNOPAUSE";
    gsargv[2] = "-dBATCH";
    gsargv[3] = "-dSAFER";
    gsargv[4] = "-sDEVICE=pdfwrite";
    gsargv[5] = "-sOutputFile=out.pdf";
    gsargv[6] = "-c";
    gsargv[7] = ".setpdfwrite";
    gsargv[8] = "-f";
    gsargv[9] = "input.ps";
    gsargc=10;

    code = gsapi_new_instance(&minst, NULL);
    if (code < 0)
    return 1;
    code = gsapi_init_with_args(minst, gsargc, gsargv);
    code1 = gsapi_exit(minst);
    if ((code == 0) || (code == e_Quit))
    code = code1;

    gsapi_delete_instance(minst);

    if ((code == 0) || (code == e_Quit))
    return 0;
    return 1;
}


I've tried to translate that example to Smalltalk, but I couldn't make it work... The creation of the GS instance is working fine, but when I try to call other functions, I'm receiving the message: "General protection fault - read from invalid memory location". Other thing, I don't now how to represent the gsargv array in Smalltalk, so I've tried to create a String from it, is that right?

Here is my code:

Code: Select all
| wfun wrc winst wptr whnd wgsargc wgsargv wptrgsargv |

" Create GS Instance "

whnd := '    ' asPointer.
wptr := whnd asInteger asBytes asPointer.

wfun := PlatformFunction
                    language: 'c'
                    function: 'gsapi_new_instance'
                    library: 'gsdll32.dll'
                    parameterTypes: #(pointer)
                    returnType: #int32.

wrc := (wfun callWith: wptr).
(wrc = 0)
ifFalse:[
        ^false
].

" Initialize GS interpreter "

wgsargc := 10.
wgsargv := 'ps2pdf -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=out.pdf -c .setpdfwrite -f input.ps'.

wptrgsargv := wgsarggv asPointer.

wfun := PlatformFunction
                    language: 'c'
                    function: 'gsapi_init_with_args'
                    library: 'gsdll32.dll'
                    parameterTypes: #(handle int32 pointer)
                    returnType: #int32.

wrc := (wfun callWith: whnd with: wgsargc with: wptrgsargv).
(wrc = 0)
ifFalse:[
        ^false
].

" Exit GS interpreter "

wfun := PlatformFunction
                    language: 'c'
                    function: 'gsapi_exit'
                    library: 'gsdll32.dll'
                    parameterTypes: #(handle)
                    returnType: #int32.

wrc := (wfun callWith: whnd).
(wrc = 0)
ifFalse:[
        ^false
].

" Delete GS Instance "

wfun := PlatformFunction
                    language: 'c'
                    function: 'gsapi_delete_instance'
                    library: 'gsdll32.dll'
                    parameterTypes: #(handle)
                    returnType: #int32.

wrc := (wfun callWith: whnd).
(wrc = 0)
ifFalse:[
        ^false
].

^true


Thanks for your patience! :)
ricardovp
 
Posts: 5
Joined: Thu Sep 09, 2010 11:05 am

Re: Does exists a framework (classes) to generate a PDF

Postby marten » Tue Sep 21, 2010 10:26 am

ricardovp wrote:Hi Ben!

Thanks for your answer! Now I can create my Post Script files without prompting the user for a filename!

To generate a PDF file from a PS (Post Script) file I'm using Ghostscript... I've managed to do so using the AbtProgramStarter class and setting some parameters, but I want to use the Ghostscript DLL... I'm not used to use the PlatformFunction class, so I'm hoping that you guys may helpe me...


Here is the answer: http://schrievkrom.wordpress.com/2010/09/21/vasmalltalk-ghostscript/
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Does exists a framework (classes) to generate a PDF

Postby ricardovp » Tue Sep 21, 2010 11:16 am

Hi Marten!

Thank you very much!!! It worked just fine!!!
ricardovp
 
Posts: 5
Joined: Thu Sep 09, 2010 11:05 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest