Using wPDF to create Legal size documents from RTF

  • I'm currently creating a PDF from RTF using this:

    var

    RichText : TWPCustomRtfEdit;

    Enviroment : TWPToolsEnviroment;

    PDF : TWPPDFExport;

    begin

    Result := 0;

    if not ForceDirectories(ExtractFilePath(AFQFilename_PDF)) then begin

    Result := 3;

    Exit;

    end;

    Enviroment := nil;

    RichText := nil;

    PDF := nil;

    try

    try

    {$IFNDEF NOENVIROMENT}

    Enviroment := TWPToolsEnviroment.Create(nil);

    Enviroment.Assign(GlobalWPToolsCustomEnviroment);

    {$ENDIF}

    RichText := TWPCustomRtfEdit.CreateDynamic;

    if Assigned(Enviroment) then

    RichText.Memo.RTFData.RTFProps.Enviroment := Enviroment;

    RichText.AsString := AString_RTF;

    RichText.ReformatAll; // First time to calculate pages

    RichText.ReformatAll; // Second time to do the job

    RichText.ReformatAll; // Third time to REALLY do the job

    PDF := TWPPDFExport.Create(nil);

    PDF.Source := RichText;

    PDF.FileName := AFQFilename_PDF;

    PDF.FontMode := wpEmbedSubsetTrueType_UsedChar;

    PDF.Print;

    except

    Result := 4;

    end;

    finally

    if Assigned(Enviroment) then FreeAndNil(Enviroment);

    if Assigned(RichText) then FreeAndNil(RichText);

    if Assigned(PDF) then FreeAndNil(PDF);

    end;


    Unfortunately, I cannot figure out how to tell the TWPPDFExport I'd like it to generate PDFs for legal size paper.

    I imaging it must be a property set somewhere, but I can't find it.

    Does anyone know how to do this?

    Thanks!

    • Offizieller Beitrag

    After

    RichText.AsString := AString_RTF;

    Set the required pages size in the WPTools TWPRichText object.

    RichText.Header.PageSize := wp_Legal; // defined in unit WPRTEDefsConsts

    Other values can be set with

    RichText.Header.SetPageWH(....)

    Values are set as "twips" - one twip is 1/1440 of an inch

    2 times call to ReformatAll should be enough. 2 times because some objects, such as page number, need to "know" the page count for correct width calculation.

    Regards,

    Julian