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:

    • Offizieller Beitrag

    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.

    Einmal editiert, zuletzt von ehimmer (12. April 2020 um 19:11)

  • 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.

  • I just noticed that the define is no longer fixing transparency. I still have {$DEFINE WPDF4} in WPINC.INC, but transparent PNG images that look fine in print preview are not transparent in the PDF.

    WPTools 9.2.3 and 9.2.4

    Delphi 11.1

    Einmal editiert, zuletzt von ehimmer (6. Juli 2022 um 23:04)

  • Apparently our PNG signature images are not working even though they are transparent PNG images. I tried an older standard transparent PNG image and it worked fine. I'll send you a sample signature PNG image... maybe you can tell me why it doesn't work for those even though it is transparent in the print preview. The signature images are ones we converted from BMP to PNG using the following code, maybe I'm missing something:

  • I found if I force the Bitmap to 8bit, it works fine. Strange because my old sample PNG image is 32bit and works fine, but the only bit depth for the signature file that is still transparent in the PDF is 8bit (I tried all the pf values):

    vBitmap.PixelFormat := pf8bit;

    Is there an issue with the PDF exporter?