i have a problem with placing images on an existing page. Referencing to your post in another topic https://forum.pdf-xchange.com/ ... 003#p95003, i build a small c# class to place an image on the first page.
The Problem is, after placing the image, the visible context of the page will not redraw and so i can't see the image. If i zoom in or zoom out i can see the image. If i return to the initial zoomlevel the image is invisible again. If i place the image outside the visible context and (e.g.) scroll down to the image location, the image will drawn. (On the other hand, if the image is placed half inside the visible context, the part outside the visible context will be drawn.) After using the "EditingContent-Tool" and moving the image in any direction, the image will drawn permanently.
I made a small Video for better understanding, but for some reasons i am not able to upload it (5.6MB)
How can i force redrawing the page?
And just two more "simple" Questions
1. What do i have to do if i want to select the image programatically after placing on the page?
2. For now i can't "undo" the operation, is it possible to do this in any way?
PS: I know, the easiest way ist to execute the command 3524 ("cmd.document.addImage") but that's to simple
This is the PlaceImage-Class:
Code: Select all
using System.Drawing;
using AxPDFXEdit;
using PDFXEdit;
namespace vv5.PdfXchangeServices {
public class PlaceImageService {
private readonly AxPXV_Control _pdfEditControl;
public PlaceImageService(AxPXV_Control pdfEditControl) {
_pdfEditControl = pdfEditControl;
}
public void PlaceImage(string fileFullname, Point position) {
var pages = _pdfEditControl.Inst.ActiveDoc.CoreDoc.Pages;
var page = pages[0];
var image = _pdfEditControl.Inst.ActiveDoc.CoreDoc.AddImageFromFile(fileFullname, 0, (uint)PXC_ImageToXObjectFlags.ITX_DonotModifySrc);
PXC_Rect rect;
rect.left = position.Y;
rect.right = image.Width + rect.left;
rect.bottom = position.X;
rect.top = image.Height + rect.bottom;
PlaceImage(page, image, rect);
}
private void PlaceImage(IPXC_Page page, IPXC_Image image, PXC_Rect rect) {
var doc = page.Document;
var content = page.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone);
var contentCreator = doc.CreateContentCreator();
contentCreator.Attach(content);
PlaceImage(contentCreator, image, rect);
page.PlaceContent(content, (uint)PXC_PlaceContentFlags.PlaceContent_Replace);
}
private void PlaceImage(IPXC_ContentCreator contentCreator, IPXC_Image image, PXC_Rect rect) {
var im = new PXC_Matrix();
im.a = rect.right - rect.left;
im.d = rect.top - rect.bottom;
im.e = rect.left;
im.f = rect.bottom;
contentCreator.SaveState();
contentCreator.ConcatCS(ref im);
contentCreator.PlaceImage(image);
contentCreator.RestoreState();
}
}
}