WPCubed Product Support

Problem mit Landscape reports

Es funktioniert, wenn ich folgenden code benutze:

w := MulDiv(richText.Memo._PaintPages[counter].WidthTw,WPScreenPixelsPerInch,1440);
                   h := MulDiv(richText.Memo._PaintPages[counter].HeightTw,WPScreenPixelsPerInch,1440);
                   if richText.Header.Landscape then
                   begin
                        w := MulDiv(richText.Memo._PaintPages[counter].HeightTw,WPScreenPixelsPerInch,1440);
                        h := MulDiv(richText.Memo._PaintPages[counter].WidthTw,WPScreenPixelsPerInch,1440);
                   end;
                   xres := richText.Memo.RTFData.RTFProps.FFontXPixelsPerInch;
                   yres := richText.Memo.RTFData.RTFProps.FFontYPixelsPerInch;
                   StartPage(MulDiv(w, xres, WPScreenPixelsPerInch), MulDiv(h, yres, WPScreenPixelsPerInch), xres, yres, 0);
                   try
                      // render the rtf page to the pdf printer
                      // note that without wppNoPageBackground the watermark would be
                      // overpainted!
                      richText.Memo.PaintRTFPage(counter, 0, 0, 0, 0, Canvas, [wppNoPageBackground, wppInPaintForwPDF], xRes, yRes,
                                                 -1, -1, [wpNoViewPortAPI]);

                   finally
                          EndPage;
                   end;

Diesen Code habe ich quasi aus der Datei WPPDFWP.pas (ab zeile 269) kopiert. Dabei ist fSource.Memo._Paintpages[i].WidthTw immer gesetzt aber eben auch falsch herum, falls Landscape = True ist.

Mit dem obigen Code funktionierts mal - allerdings ist noch ein kleines Problem mit einem Bild, das falsch skaliert gezeichnet wird.

Im Originaldokument ist füllt das Bild ca 1/4 der Landscape Seite aus (2x2 Tabelle - eine Zelle wird vom Bild ausgefüllt) . Im PDF Ausdruck ist es aber viel kleiner skaliert.
Allerdings liegt das soweit ich gesehen habe nicht am pdf drucken selber sondern am Zwischenschritt - bei dem ich das RTF bearbeit und als WPT File speichere.

#4 ♥ 0
7.5k Views 2 users read 5 min
support

PageWidth/Height ändert sich nicht mir Landscape.

Um die akteulle Abmessungen einer Seite auszulesen bitte auf Memo.PaintPageWidth(Height zugreifen. Die WP interface unit die wPDF beiligt zeigt wie es geht.

w := Round( FSource.Memo.PaintPageWidth[i] / FSource.Memo.CurrentZooming );
h := Round( FSource.Memo.PaintPageHeight[i] / FSource.Memo.CurrentZooming );

#3 ♥ 0

Um noch ein bischen klarer zu machen - hier noch ein bischen code:

report laden und speichern:

richEdit := TWPRichText.CreateDynamic;     try        richEdit.Memo._CodePage := 65001;  //utf-8        if Assigned(fParams) then           fParams.Values[cRepRepeats] := '0';        richText.LoadFromStream(inStream);        // Fill report with items        richEdit.WorkOnText := wpBody;        richEdit.ReformatAll;        richEdit.SaveToStream(outStream, 'WPT');     finally            richEdit.Free;     end;

Report mit items befüllen:

repeat            // find a tag            // select whole item              richText.SetSelPosLen(StartTagPos, richText.Finder.Position - StartTagPos + Length(cItemEndTag));            // delete selected text            richText.SelText := '';             // convert the items name to the replace text store in "text"            // insert the text at the current cursor position            richtext.InputStringW(text);   until no tag found any more

after that the report is stored in the "wpt" format on disk

from this "meta" report the pdf is generated using the wpdf component:

richText := TWPRichText.CreateDynamic;     try        richText.Memo._CodePage := 65001;  //utf-8        // fill in report (second pass - but actually does nothing)        FillReportWp(inStream, richText, nil, cMaxNumPass);        // this is the time where the localized images have to be created        for counter := 0 to richText.TextObjects.Count - 1 do        begin             obj := richText.TextObjects.List[counter];             if obj is TLocWPImage then             begin                  TLocWPImage(obj).DataObj := fDataObj;                  obj.Transparent := True;             end;        end;         // todo: remove this line - debugging only        richText.SaveToFile('D:\voucher.wpt');        // #################################################        // #### choose pdf printer        try           Result := PrintPdf(richText);        except              on E : Exception do              begin                   AddGlobalLog(llError, E, fDataObj);                   AddLog('Pdf printing failed: ' + E.Message);                   Result := nil;              end;        end;     finally            richText.Free;            fOnRepProgress := fOnRepProgressPDF;     end;

print pdf looks like:

numPages := richText.CountPages;
  tmpFileName := TTempFileStream.CreateTempFile;
     try
        with TWPPDFPrinter.Create(nil) do
        try
           Modes := [wpClipRectSupport, wpAlwaysHighResPDF, wpNoTextScaling, wpExactTextPositioning];
           CidFontMode := wpCIDUnicode;
           //CidFontMode := wpCIDOff;
           PDFReadMode := wpdfStandard;
           ScreenDpi := DefaultPrinterRes;
           if isPrinterAvail
           then
               CanvasReference := wprefPrinter
           else
               CanvasReference := wprefScreen;
           AutoLaunch := False;
           EncodeStreamMethod := wpEncodeNone;
           CompressStreamMethod := wpCompressFlate;
           PageMode := pwUseNone;
           ZoomMode := pwZoomDefault;
           FontMode := wpEmbedTrueTypeFonts;
           InMemoryMode := True;
           Filename := tmpFileName;
           JPEGQuality := wpNoJPEG;

           // begin printing
           BeginDoc;
           try
              for counter := 0 to numPages - 1 do
              begin

                   // in this version of wpTools the PageHeight/Width seems to be OK
                   // the Header property (should be called PageProperty...) holds
                   // the physical width and height in TWIPS of the page
                   // one twip is a 1/1440 of an inch!
                   pw := richText.Header.PageWidth;
                   ph := richText.Header.PageHeight;

                   StartPage(MulDiv(pw, ScreenDpi.cx, cTwipsPerInch),
                                    MulDiv(ph, ScreenDpi.cy, cTwipsPerInch),
                                    ScreenDpi.cx, ScreenDpi.cy, 0);
                   OutRect := Rect(0, 0, MulDiv(pw, ScreenDpi.cx, cTwipsPerInch), MulDiv(ph, ScreenDpi.cy, cTwipsPerInch));

                   h := outRect.Bottom - outRect.Top;
                   w := outRect.Right - outRect.Left;

                   try
                      // render the rtf page to the pdf printer
                      richText.PaintPageOnCanvas(counter, 0, 0, w, h, Canvas, [wppNoPageBackground]);

                   finally
                          EndPage;
                   end;

                   DoPDFProgress(((counter + 1)*100) div numPages); 
              end;
           finally
                  EndDoc;
           end;
        finally
               Free;
        end;

        // #################################################
        // #### Ensure that the file is deleted right after it has been uploaded
        Result := TTempFileStream.Create(tmpFileName, fmOpenRead);

Note that the code above generates a portrait pdf from an originaly landscape rtf file.

The rtf was created using Word2000 and stored as a rtf file. The file itself contains a table (2x2 fields) including some text and some images and I'm using WPTools6.

I can provide the resulting wpt and the rtf file if necessary.

#2 ♥ 0

Ich bin über ein kleineres Landscape Problem gestolpert:

-) ich lade einen RTF Report in Landscape
-) speichere einen geänderten Report im wpt Format ab (nachdem ich
nache einigen Keywörtern gesucht habe und diese geändert habe)
-) lade das File wieder -> richtext.header.landscape ist auf true gesetzt (stimmt ja auch) allerdings ist die Seitenbreite und Höhe immer noch so als ob das Dokument im Portrait Modus gespeichert ist.

-) das hat dann natürlich auch starken Einfluss auf das darau generierte PDF...

hat jemand eine Idee?

#1 ♥ 0