Beiträge von MarkElder

    Hello,

    I am loading images in a mail merge. Everything looks great on screen. However, I can't get the images to print in color. They will print in black and white - except when the first printed page contains an image.

    When the mail merge is generated I have a number of optional pages. I have loaded the merge templates into memory streams. The templates are saved in the wpt format.

    Here is how I am appending the templates together.

    Once all the pages are added then I call MergeText and perform the mail merge. Normally my first document (usually two pages long) will not contain any images. The following pages will typically have images.

    If I print out the entire report I get black and white image. If I just print a specific page that has an image it will then be in color.

    I'm at a complete loss for even what to look at next. I did try printing to the XPS and Snagit printers. Those both always had color images.

    It's almost like WPTools is looking at the first page and if it does not contain an image or any color it tells the printer to print in B&W?

    Any suggestions on what to look at are appreciated.

    Thanks,

    Mark

    I just realized I was only searching the WPTool6 forum. I went back and searched the FAQ WPTools 5 and 6 General forum and found this post:


    The example there is assigning a WPOImage object directly to Obj like I am doing, so I guess that is OK. I'm still not sure why the LoadImageFromFile is working like it is, but I guess that really does not matter.

    I am loading an image during a mail merge. I have registered a custom image format that I want loaded. So instead of using the Contents.LoadImageFromFile I am loading my own TPicture object and then assigning the graphic.

    I am a little confused when assigning the object. I have three questions:
    1) Can I just assign my WPImage to Obj as in the code below or should I create a text object and then assign Obj := NewWPImage.ObjRef?
    2) Do I need to free the current contents of Obj?
    3) Do I need to set the height and width after setting the Obj?

    The code I have below is working right now but I have started out but looking at how Contents.LoadImageFromFile was working. That code is confusing to me and has prompted these questions.

    My Code:

    Code
    MyPicture := TPicture.Create();    try      MyPicture.LoadFromFile(AttachmentDir + DataValue);      NewWPImg := TWPOImage.CreateImage(Contents.DataCollection, MyPicture.Graphic);      PictureWidth := MyPicture.Width;      PictureHeight := MyPicture.Height;    finally      FreeAndNil(MyPicture);    end;    // MaxWidth and MaxHeight are in Twips - I just need to scale them    // to keep the picture in the right proportions     WPScaleWH(PictureWidth, PictureHeight, MaxWidth, MaxHeight);    NewWPImg.WidthTW := PictureWidth;    NewWPImg.HeightTW := PictureHeight;    Contents.Obj := NewWPImg;


    From Contents.LoadImageFromFile. When I look at this code I wonder?
    - Why was a TWPTextObj created instead of an WPOImage?
    - Why was o.ObjRef assigned to Obj instead of o directly?
    - When o is freed why is ObjRef still valid?
    - What good does it do to set o.Width and o.Height and then immediately free o? Should that be setting
    obj.Width and obj.Height? Is that needed at all since the ObjRef width and height is set?

    I'm still not working but here is my latest attempt.

    I realized that I didn't have GraphicEx turned on even though I am using it in my project. I added the compiler define and got it enabled. I also registered my customer image class with the GraphicEx system.

    However it is still not working. I am still just getting blanks.

    I made a change and added a call to the NoViewer command. A Handle is still needed, but it seems reasonable to do this anyway.

    Code
    PDF.CommandEx(COMPDF_NoViewer, 1);

    I found this in one of the demos. I could not fine any documentation for this other than the comments in the source

    Zitat

    COMPDF_NoViewer = 140; // Pass 1 to use the viewer as PDF tool (invisible)

    I did look some more at the DirectDLL demo and it looks like I could probably copy out the LoadFromStream and WriteBitmap functions and add them directly to my class. There is the direct method wpview_pdfMakeJPEG, but I really want this in a stream not on disk in a file. The function TWPViewPDF.WriteBitmap handles that nicely for me.

    Hello,

    I am using WPViewPDF in a generic class - not on a form.

    If I create the class like this: TWPViewPDF.Create(nil);
    I get the following exception when I try to execute LoadFromStream.

    Exception class EInvalidOperation with message 'Control '' has no parent window'.

    My use of the viewer is simple. I am just loading the PDF, calling WriteBitmap and then freeing the PDF Viewer.

    Right now I am getting around this by creating the viewer like this:
    TWPViewPDF.CreateParented(Application.MainForm.Handle);

    I hate to reference MainForm if I don't need to. Is there a way to use WPViewPDF without needing a window handle?

    Thanks,

    Mark

    Hello,

    I am trying to add a custom image format and have WPTools support loading those images.

    In this specific case I am trying to make PDF files look like images. I only care about getting the first page of the PDF file as an image.

    I created a new class (TPDFImage) derived from TJPEG and overrode the LoadFromStream method to use WPViewPDF to convert the first page of the PDF into a Jpeg and set the internal TJPEG representation. That class is then registered:
    TPicture.RegisterFileFormat('pdf', 'Load PDF File as an Image', TPDFImage);

    So far everything is working great. I can work with PDF file just like images and show them in TImage controls.

    Now I am trying to get PDF's loaded (as a image) during a mail merge with WPTools. To load my images I am doing the following:
    Contents.LoadImageFromFile(AttachmentDir + DataValue);

    I have traced this through and it eventually calls GetWPObjectForExtension. That returns Nil instead of my TPDFImage class. Is there something extra I need to do in order to get WPTools to recognize my new picture type?

    Thanks,

    Mark

    I am working with the Mail Merge and trying to get a handle on how to specify formatting for numeric fields. I'm getting a little confused by the difference in names between the objects and the documentation. I'm posting this here to try and get confirmation that I am using these objects correctly and if so maybe it can be helpful to others.

    InputMergeField takes the following paramaters: (The following is from the WPTools help file)

    Zitat

    FieldName: string the name of the field
    DisplayText: string the default text for the field. It is stored in txtobj.Params
    Command: string the optional commands for the field - they will be stored in txtobj.Source.
    Format: Integer an optional value to specify the format. It will be stored in txtobj.IParam.
    DisplayChar: Integer an optional which will be attached to the field. It will be stored in txtobj.CParam. It should not be used.

    What I really want is to store a format string. There is a field called Format and I guess I could define a set of integers for some fixed formats but "Command" looks like a better option to me.

    DisplayText is confusing to me. I found that it does Initially set the default value. However, if the text shown in the field is edited in the document then Params is not updated. And if Params is updated on the Merge object the text in the document is not changed. I'm not sure when Params would ever be used after the initial call to InputMergeField.

    So in my Template Editor I have two boxes. One to enter a field name and one to enter a format.

    I have two events to deal with field. When the cursor position changes if I am on a field copy the field information to my input boxes:

    Code
    procedure TAgToolsEditor.WPRichTextChangeCursorPos(Sender: TObject);var  CurrentField: TWPTextObj;begin  CurrentField := WPRichText.FieldAtCP;  if CurrentField <> nil then  begin    cboCustomField.Text := CurrentField.Name;    cboFormat.Text := CurrentField.Source;  endend;

    Then I have an "Add Field" button will either update or insert a new field. When updating a field I am re-setting the Params field. However that does not seem to matter. The text I see in the document will not change.

    Code
    procedure TAgToolsEditor.cmdAddCustomClick(Sender: TObject);var  CurrentField: TWPTextObj;  DefaultText: string;  i: integer;begin  CurrentField := WPRichText.FieldAtCP;  if CurrentField <> nil then  begin    CurrentField.Name := cboCustomField.Text;    CurrentField.Params := cboCustomField.Text;    CurrentField.Source := cboFormat.Text;    WPRichText.ReformatAll(false, true);  end  else  begin    i := LastDelimiter('.',  cboCustomField.Text);    if (i > 0) then      DefaultText := RightStr(cboCustomField.Text, Length(cboCustomField.Text) - i)    else      DefaultText := cboCustomField.Text;    WPRichText.InputMergeField(cboCustomField.Text, DefaultText, cboFormat.Text);  end;end;


    Then in my merge code I pull out the Format string. Now stored in a "Command" field instead of the source property we used above.


    Hello,

    I am starting a new project that will be using WPTools mail merge field. I need an editor for my internal use for creating our merge documents.

    I was thinking there was a fairly complete editor in the Demos folder that I could use. However I can't seem to find it. Am I imagining this or is there something out there that I am just missing?

    Thanks,

    Mark

    Hello,

    I am converting a page from PDF file to a JPEG with the following code.

    TempImageFileName := CreateTempFilePath('PDFImport.jpg');
    WPViewPdf.WriteJPEG(TempImageFileName, Pg, 300, 0);
    TGraphicEditor(FDoc.docEditor).LoadImageFile(TempImageFileName);
    DeleteFile(TempImageFileName);

    On some computers - some of the time I don't get a file created. At this time it seems to be random. I can see the page in the viewer just fine, but the jpeg file is never created.

    I have two customers that this happens to consistently. I have used process monitor from the sysinternals suite to try and see where things are failing. I can see the temp file name opened but nothing is ever written to the file.

    I also checked and the correct dll seems to be loaded (we install the dll in the same directory as our exe).

    And the preview in the component does correctly draw the thumbnail of the page.

    Any ideas on what could be happening or other steps I can take on the computers where this is not working?

    Thanks,

    Mark

    Hello,

    I am using wPDF and Drawing images to the canvas.

    I am seeing the following exception in the debugger

    Project ClickForms.exe raised exception class EJPEG with message 'JPEG error #36'.

    and the following message in the output window

    Debug Output: wPDF: Problem when compressing JPEG Data Process ClickForms.exe (1396)

    My PDF seems to be generated OK, but I am assuming that my images are not compressed? I have a number of images I am output. This only happens on one or two of them.

    Any ideas on what could be causing this and if there is anything I can change?

    Hello,

    I need to draw pages to my own canvas. I already have a document interface with my own scrollbar and headers/footers. If I have a three page document I will have three separate text areas, each the size of one page body where the page needs to be drawn.

    I'm have plenty of options with WPTools to make this happen. I'm just trying to figure out which objects I should really be using. If I have the Rich text in a stream and I want to load it and then call print on specific pages when they are in view what objects would you suggest. I already have an internal "cell" object that is my text area on the canvas. It knows when it is in view and scrolling etc. I just need someway to say Draw Page 2 on this canvas in this rect.

    Thanks,

    Mark

    Hello,

    I have a customer who needs to import the PDF files we are creating into a document management system. They have asked us to product PDF version 1.7 files. We had put off updating our wPDF component. I just updated and tested some files and they appear to be version 1.4. This is better as we were at 1.2.

    Does the current version of wPDF (3.58.5) support a PDF file spec newer than 1.4? If so how do I change the version that is being output?

    Thanks,

    Mark