Images not transparent in PDF export

  • Hi


    I have a WP tools document (v7.33.1) with pictures (embedded or through Insertpoints). These pictures are transparent (PNG). In the WPTools editor, this seems fine (I have a background image that sees through the image). But when I export my document to PDF using wPDF the images are not transparent anymore and get a white background covering my background, creating ugly white blocks.


    Because I need further processing of the canvas after each page is drawn, I cannot use the TWPPdfExport component. So I use this code to draw the pages on the wPDF canvas:

    The PDFCreator is a wrapper around the wPDF component. The code inside the PDFCreator component looks like this:

  • In WPObj_Image there should be code inside of the IFDEF EMBEDD_PNGJPG


    It makes sure that a PNG is embedded instead of painted to the Canvas which will always destroy the transparency. This requires wPDF V4.


    Please place a breakpoint there to find out why the code is not executed when you are inside BodyText.PaintPageOnCanvas. I assume this has to do with $DEFINES.

  • When I active {$DEFINE WPDF4} the PNG is printed correctly (with transparency) but when I load JPG files the images don't show, to fix I needed to change the line 1553 in WPOBJ_Image, I'm using Wptools 8 with Delphi 7


    {$IFDEF EMBEDD_PNGJPG} //WPDF4

    to

    {$IFNDEF EMBEDD_PNGJPG} //WPDF4


    is correct ? tks

  • Yes, I'm using the code below, running LoadFromFile I dont need set fileextension


    Fn := 'picture.jpg';

    try

    wpobj := TWPOImage.Create(WPRichText1.Memo.RTFData);

    wpobj.LoadFromFile(Fn);

    finally

    DeleteFile(Fn);

    end;

  • with this line I can print jpeg image, can you check ?


    {$IFDEF EMBEDD_PNGJPG} //WPDF4

    // wPDF4 allows transparent PNG embedding

    // WPDFCOMM_ADDIMAGEDATA = 3020; // Add image data Param = TWPDFImageCommand

    // WPDFCOMM_DRAWPNGDATA = 3021; // Add PNG Data

    // WPDFCOMM_DRAWJPEGDATA = 3022; // Add JPEG Data

    if (wpPaintObjDestIsPDF in PaintMode) and (DataIs('jpg')or DataIs('jpeg')) then

    begin

    WPWriteComment( toCanvas.Handle, 3022, BoundsRect, DataPtr, DataLen);

    if not bDisablePaint then inherited Paint(toCanvas, BoundsRect, ParentTxtObj, PaintMode);

    end else

  • Sorry, I do not see a GDIPP switch in WPObj_Image. Could it be "USEGPP"? I tried disabling USEGPP and it made no difference.


    Also, how did you test it in your demo? I downloaded WPCubedWordprocessorDemo and could not find a way to insert a PNG image to test.


    To test, I created a one row two column table. I then shade the table cells and insert a linked PNG image into one of the cells. Print preview shows it correct, but then creating the PDF is where it is not transparent, i.e. the cell color does not come through the transparent parts of the image.

  • OK, Instead of using the Insert Image option in your demo which did not give me the option for PNG images, I tried dragging the image into the table cell which accepted it. Creating the PDF worked fine as you said.


    Maybe it has something to do with linked images? Or perhaps I have some PDF creation setting set wrong. I'll dig into it more and let you know what I find.

  • I created a new project, so nothing but defaults except for the AcceptFiles option is now true in the WPRichText. I pre-loaded a shaded table with a transparent PNG in one cell. Created the PDF and it is not transparent. I then dragged that same PNG image I used in your demo, and dropped it into the other cell. PDF again created without transparency.


    I will send you the sample. I am at a loss as to what might be different between your demo and my basic sample app.