#1 PDF Engine » Need some basic "Hello World" examples » 2011-02-06 05:22:44

HNRSoftware
Replies: 1

I appear to be the only person on this forum that needs more documentation.  I took some example code on another thread and attempted to get it to run.  (Sorry that I don't use standard indent - I was taught this way on my mother's knee and I can't shake it.)  I'm using Delphi 6 and have been coding in Turbo Pascal/Delphi since the early 1990s.

I do get the "Hello World" text (at the lower right corner of the page??), but I can't find the right combination to get either the line or the rectangle - no crash, but no lines either.

I would also like a meaningful example of placing a TBitmap on a page.  I can imagine passing it through a TMetaFile object but the exact process is not obvious to me.

Function SynHelloWorldTest(ShowAfter : boolean = true; PDFFN : string = 'HelloWorld.pdf') : String;
var xPdf   : TPdfDocument;
    xPage  : TPdfPage;
     begin
     xPdf := TPdfDocument.Create;
     try
        xPdf.Info.Author        := 'Tester';
        xPdf.Info.CreationDate  := Now;
        xPdf.Info.Creator       := 'Tester';
        xPdf.DefaultPaperSize   := psA4;
        xPage := xPDF.AddPage;                    // forum implies that this is unnecessary, but gives access violation if omitted

        xPDF.Canvas.SetRGBFillColor(clRed);            // affects text color
        xPDF.Canvas.SetRGBStrokeColor(clGreen);    // why isn't this one the text color? -- still no lines or rects

        xPDF.Canvas.SetLineWidth(0.25);               // thought maybe the line was just too thin to see
        xPDF.Canvas.MoveTo(100,100); xPDF.Canvas.LineTo(500,500); // nothing shows!!??
        xPdf.Canvas.Rectangle(10,10,600,600);       // nothing shows!!??

        xPDF.Canvas.SetFont('Arial',12.0,[fsBold]);  // comment this out and we get and access violation
        //xPdf.Canvas.BeginText;                         // these don't appear to do anything
        xPdf.Canvas.TextOut(1,1,'Hello World.');     // (0,0) appears at bottom left of the page
        //xPdf.Canvas.EndText;                           // these don't appear to do anything

        xPdf.SaveToFile(PDFFN);
     finally
        xPdf.Free;
        end; // of try
     //result := 'SynHelloWorldTest ['+PDFFN+']  '+fileinfostr(PDFFN);           // verification
     //if fileexists(PDFFN) and (ShowAfter) then WINSHELLOpenFile(PDFFN);  // verification - invokes the default pdf viewer
     end;

Board footer

Powered by FluxBB