SetViewportOrgEx( )

  • Hi,

    We have made our own components for displaying and filling forms and reports on the screen. Forms are displayed and stored page by page, but in reports the next page comes after the other. All elements have coordinates relative to the top left corner of the first page.

    When printing a report, view use SetViewportOrgEx( ) with y parameter set to PAGE_HEIGHT * (CurrentPage - 1) * -1 to shift everything in to place.

    This works ok for physical printing, but when printing to the wPDF-canvas, it doesn't shift it enough. On my default printer, it starts drawing page 2 at the bottom of page 2, and page 3 and so on comes blank.

    I found that multiplying the PAGE_HEIGHT by the magic number 6 shifts everything into place, but selecting a different printer as default need for a different magic number....

    Why do I need this magic number when printing to wPDF?
    How can I find the right magic number?

    regards,
    -Vegar

    • Offizieller Beitrag

    Hi,

    Is it possible that your coordinates exceed the value 32000. PDF internally does not support that, wPDF offers a "highres" mode as work around. (See property Modes).

    Please plcae your coordinate manipulations inside SaveDC/RestoreDC since PDF always stacks multiplications. Not having SaveDC/RestoreDC makes the DF output unnecessary complex and could be the reason for the problems you see.

    Julian

    • Offizieller Beitrag

    Hi,

    I just checked it out. I noted that you seem to also print the invisible text outside of the page rectangle.

    If I understood correctly you print the complete report (10 pages) on one canvas and only move the window.

    That technique is highly problematic with something like wPDF. It will export the invisible stuff as well, only that it is not visible due to clipping.

    I am not sure how to solve this - is it really not possible to get individual pages from the reporter?

    Julian

  • On screen, it draws all components to the same canvas. When printing, it only draws the components for the current page to the canvas that it is given (the wPDF canvas).

    So there is no problem drawing only one pageful of components. The problem is to shift their coordinates right, since this seems to be printer dependent for wPDF.

    I can draw it to a real printer canvas without problem, even the printers causing trouble with wPDF.

    There are a lot of things I do not understand. I can see why controls come outside the page and get clipped, but I cant understand why components drawn outside of page five can show up on page three and so on.

    regards,
    -Vegar

  • So I think I have found a couple of issues with our code.

    First, the filtering of what components get drawn for each page is wrong. It filters away components from previous pages, but not for following pages. So for a three page report, the first page will include all three pages, the second and third outside the page bounds, the second page will include page two and three, and the last one only page three.

    Second, there seems to be an error related to the resolution of the printer vs the pdf. The PDFPrinter-component has its canvas reference set to printer, and in the call to StartPage( ), a resolution of 100 was passed in. The magic number 6 used in SetViewPort( ), worked in most sercomstances because most printer has an dpi of 600.
    So by using the actual dpi from the printer in the call to StartPage( ), we no longer needed the magic number. What we then needed, though, was to scale everything else, but the code for that was already in place for drawing to a printer, so that was ok.

    There seems to be a lot of other issues in this code, but for now everything seems to work - regarding size and positioning at least.

    I got myself a new problem though. We draw a small bitmap on every page, and now this bitmap is drawn with a black background in the pdf. On screen and on printer it is ok, but not in the pdf output. I will send you a new debug-output together with the bitmap, and hope you have a solution for me.