Watermark

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Watermark

Post by Yury » Tue Jun 06, 2017 9:41 am

Hello, I found some operations which are placing the watermark on to the document. But how can I setup watermark in such a way that it'd be visible for the end user in process of his work over document, and user could not remove it?
Same way as I can see Tracker-Soft's Watermark image. ( See attach )

Regards,
Yury
Attachments
2017-06-06_124022.png

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Tue Jun 06, 2017 11:54 am

Hello Yury,

Basically what you have to do is draw on the Pages View directly. For that, check out this post:
http://www.tracker-software.com/forum3/ ... ck#p103111

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Wed Jun 07, 2017 1:42 pm

Thanks, Sasha. I did the following:
1. I took the code from the sample, you've pointed me to.
2. I changed the m_aInst.MathHelper.Matrix_TransformRect(ref p2v, ref rc); to m_aInst.MathHelper.Rect_Transform(ref p2v, ref rc); as compiler failed to find method.
3. I tried to register/unregister call back at event monitor... ( not sure I did this correctly )

Code: Select all

        public partial class UIEventMon : PDFXEdit.IUIX_EventMonitor
        {
            MainEditorForm _form;
            bool _registered = false;
            public  UIEventMon(MainEditorForm form)
            {
                _form = form;
            }
            public void OnEventMonitor(PDFXEdit.IUIX_Obj pTarget, PDFXEdit.IUIX_Event pEvent)
            {
                
                {
                    if (_form.pdfCtl.Doc != null && !_registered)
                    {
                        _form.pdfCtl.Doc.ActiveView.PagesView.RegisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _form._dPClbk);
                        _registered = true;
                    }
                }
                
                if( pEvent.Code == (int)PDFXEdit.UIX_EventCodes.e_BeforeDestroy )
                {
                    if(_form.pdfCtl.Doc != null && _registered )
                    {
                        _form.pdfCtl.Doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _form._dPClbk);
                        _registered = false;
                    }
                }
                
            }
        }
I'm able to break debugger at painting code ( DrawRectangle ), however I see nothing in editor view.
Sometimes, ( in case I have document with 1 page, I see the blue rectangle at the left bottom of the page. If open doc with several pages, I don't see it.

So,
1. How can I properly register/unregister callback?
2. How to draw on each page?

Best regards, and thanks for your help!

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Wed Jun 07, 2017 2:06 pm

Hello Yury,

In this case you should use the pdfCtl_OnEvent method to monitor the events. As for the registering\unregistering of the callback, you can use the e.activeDocChanged event to unregister the callback first and then register it to another document. Also the unregistering should be done in the e.document.beforeClose event. The callback itself should probably hold a reference to the IPXV_Document that should be cleared when unregistering.
To draw on all of the pages do this:

Code: Select all

//Drawing rectangle on the foreground
if (nStage == PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground)
{
	for (uint i = 0; i < pPageRegions.Count; i++)
	{
		DrawRectangle(pView, pRC, pPageRegions[i].nPage);
	}
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Wed Jun 07, 2017 3:36 pm

Thanks, sorry, can't find where these e.activeDocChanged , e.document.beforeClose are defined?

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13591
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Watermark

Post by Tracker Supp-Stefan » Wed Jun 07, 2017 4:20 pm

Hello Yuri,

This is a list of the events in the Editor:
http://sdkhelp.tracker-software.com/view/PXV:PXV_Events

And you can handle them with the OnEvent method:
http://sdkhelp.tracker-software.com/vie ... er_OnEvent

Regards,
Stefan

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Wed Jun 07, 2017 5:10 pm

Could you please give some code example? Not sure I understand.....
I have this in my code

Code: Select all

private void pdfCtl_OnEvent(object sender, AxPDFXEdit._IPXV_ControlEvents_OnEventEvent e)
        {
            
            
        }
And this:

Code: Select all

 this.pdfCtl.OnEvent += new AxPDFXEdit._IPXV_ControlEvents_OnEventEventHandler(this.pdfCtl_OnEvent);
Until now everything is clear for me.
But inside the pdfCtl_OnEvent, how I can detect that e is "e.document.beforeClose"
Sorry, looks I missing something

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Wed Jun 07, 2017 8:19 pm

Please check the FullDemo application - there is a sample on that matter.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Thu Jun 08, 2017 9:40 am

int id = pdfCtl.Inst.Str2ID("e.document.beforeClose");

Correct?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Thu Jun 08, 2017 10:03 am

Correct, and then compare it to the e.nEventID.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Thu Jun 08, 2017 3:31 pm

Does not work....

Code: Select all

 private void pdfCtl_OnEvent(object sender, AxPDFXEdit._IPXV_ControlEvents_OnEventEvent e)
        {
            try
            {
                if (e.nEventID == _editorIDS.nIDS[(int)IDS.e_activeDocChanged])
                {

                    if (_doc != null)
                        _doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
                   
                    if(this.pdfCtl.Doc!=null )
                         this.pdfCtl.Doc.ActiveView.PagesView.RegisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
                    
                    _doc = this.pdfCtl.Doc;
                }
                int id = pdfCtl.Inst.Str2ID("e.document.beforeClose");

                if (e.nEventID == id)
                {
                    this.pdfCtl.Doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
                }
            }
            catch (Exception ex)
            {
                return;
            }
1. I can break at

Code: Select all

public void DrawRectangle(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage)
        {
            PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout;
            if (plm == null)
                return;

            PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true);
            PDFXEdit.PXC_Rect rc = m_rcDraw;
            m_aInst.MathHelper.Rect_Transform(ref p2v, ref rc);

            //Flipping rectangle top and bottom coordinates and converting it's type
            PDFXEdit.tagRECT rcDR;
            rcDR.left = (int)rc.left;
            rcDR.right = (int)rc.right;
            rcDR.top = (int)rc.bottom;
            rcDR.bottom = (int)rc.top;

            pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDR, 1);
        }
So, call back is set. But I don't see any rectangles on pages. See attachment.
Next, this code produces exception when I'm closing window..

Code: Select all

if (_doc != null)
                        _doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
May be I should not save doc?
And finally, I never come to inside the if:

Code: Select all

if (e.nEventID == id)
                {
                    this.pdfCtl.Doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
                }
Any thoughts? I'm using x64 version of the control.
Attachments
Editor.png

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Thu Jun 08, 2017 3:54 pm

Seems I got rid of exceptions and callback registrations issues. (

Code: Select all

int id = pdfCtl.Inst.Str2ID("e.document.beforeClose");
             pdfCtl.EnableEventListening2(id, bRegister);
But I still do not see the rectangles... Ideas?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 9:07 am

Hello Yury,

For starters just make a button with this code:

Code: Select all

DrawPagesCallback m_DPClbk = null;

private void drawRectangleOnPageToolStripMenuItem_Click(object sender, EventArgs e)
{
	if (m_DPClbk == null)
	{
		m_DPClbk = new DrawPagesCallback(auxInst, uiInst);
		//Registering callback at the needed document's pages view
		pdfCtl.Doc.ActiveView.PagesView.RegisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, m_DPClbk);
	}
}
Then use this code here for a callback class:

Code: Select all

public class DrawPagesCallback : PDFXEdit.IPXV_PagesViewDrawCallback
{
	public PDFXEdit.IAUX_Inst m_aInst;
	public PDFXEdit.IUIX_Inst m_uiInst;
	private PDFXEdit.IColor m_clrFill;
	private PDFXEdit.IColor m_clrBorder;
	private PDFXEdit.PXC_Rect m_rcDraw;
	PDFXEdit.IUIX_Brush m_Brush;
	PDFXEdit.IUIX_Pen m_Pen;
	public DrawPagesCallback(PDFXEdit.IAUX_Inst aInst, PDFXEdit.IUIX_Inst uiInst)
	{
		m_aInst = aInst;
		m_uiInst = uiInst;
		m_clrFill = m_aInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
		m_clrFill.SetRGB(0.0f, 1.0f, 1.0f);
		m_clrBorder = m_aInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
		m_clrBorder.SetRGB(0.0f, 1.0f, 0.0f);
		m_rcDraw.left = -100;
		m_rcDraw.right = 100;
		m_rcDraw.top = 100;
		m_rcDraw.bottom = 0;
		m_Brush = m_uiInst.CreateNewBrush();
		m_Pen = m_uiInst.CreateNewPen();
		m_Brush.Color0 = m_clrFill.RGB;
		m_Brush.Color1 = m_clrFill.RGB;
		m_Pen.Brush.Color0 = m_clrBorder.RGB;
		m_Pen.Brush.Color1 = m_clrBorder.RGB;
		m_Pen.Width = 10;
		m_Pen.Inside = true;

	}
	public void OnDrawPagesView(PDFXEdit.IPXV_PagesView pView, PDFXEdit.PXV_PagesViewDrawStage nStage, PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IPXV_PagesLayoutRegions pPageRegions)
	{
		if (pView == null)
			return;
		//Drawing rectangle on the foreground
		if (nStage == PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground)
		{
			for (uint i = 0; i < pPageRegions.Count; i++)
			{
				DrawRectangle(pView, pRC, pPageRegions[i].nPage);
			}
		}
	}

	public void DrawRectangle(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage)
	{
		PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout;
		if (plm == null)
			return;

		PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true);
		PDFXEdit.PXC_Rect rc = m_rcDraw;
		m_aInst.MathHelper.Rect_Transform(ref p2v, ref rc);

		//Flipping rectangle top and bottom coordinates and converting it's type
		PDFXEdit.tagRECT rcDR;
		rcDR.left = (int)rc.left;
		rcDR.right = (int)rc.right;
		rcDR.top = (int)rc.bottom;
		rcDR.bottom = (int)rc.top;

		pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDR, 1);
	}
}
Do not forget about unregistering the callback:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_document_beforeClose])
{
	if (m_DPClbk != null)
		pdfCtl.Doc.ActiveView.PagesView.UnregisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, m_DPClbk);
}
All of this code should draw a rectangle on the visual left bottom side of the page.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 10:43 am

Not working.... project attached

Thank you.
Attachments
PDFXEditor.7z
(574.18 KiB) Downloaded 37 times

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 11:13 am

Hello Yury,

As I see you haven't tried resizing the page or scrolling it. You will have to invalidate the page(s) for the first time manually:

Code: Select all

pdfCtl.Doc.ActiveView.PagesView.RegisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, _dPClbk);
pdfCtl.Doc.ActiveView.PagesView.InvalidatePage(pdfCtl.CurrentPage);
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 11:34 am

No, this didn't help . Have you tried to build/run my project?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 11:43 am

Works for me:
WS.gif
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 12:00 pm

Just checked again.... If I start under VS2013 - it works. If I start under VS2010 - it does not.... any thoughts?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 12:12 pm

Hello Yury,

What came to mind is a .Net platform that the different VS are using - check that out.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 12:43 pm

No, this is in project settings. Both use .Net Framework 4 Client Profile

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 12:48 pm

Well then it's not a SDK problem then.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 2:36 pm

Alex, I think that issue is in some object marshaling....look at the code below:

Code: Select all

public void OnDrawPagesView(PDFXEdit.IPXV_PagesView pView, PDFXEdit.PXV_PagesViewDrawStage nStage, PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IPXV_PagesLayoutRegions pPageRegions)
   {
      if (pView == null)
         return;
      //Drawing rectangle on the foreground
      if (nStage == PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground)
      {
         for (uint i = 0; i < pPageRegions.Count; i++)
         {
            DrawRectangle(pView, pRC, pPageRegions[i].nPage, pPageRegions[i].rcPageRect);
         }
      }
   }
public void DrawRectangle(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage, PDFXEdit.tagRECT rcPage)
   {
      PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout;
      if (plm == null)
         return;

      PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true);
      PDFXEdit.PXC_Rect rc = m_rcDraw;
      PDFXEdit.PXC_Rect rcPageRect; rcPageRect.bottom = rcPage.bottom; rcPageRect.left = rcPage.left; rcPageRect.top = rcPage.top; rcPageRect.right = rcPage.right;        
      m_aInst.MathHelper.Rect_Transform(ref p2v, ref rc);
      m_aInst.MathHelper.Rect_Transform(ref p2v, ref rcPageRect);  

      //Flipping rectangle top and bottom coordinates and converting it's type
      PDFXEdit.tagRECT rcDR;
      rcDR.left = (int)rc.left;
      rcDR.right = (int)rc.right;
      rcDR.top = (int)rc.bottom;
      rcDR.bottom = (int)rc.top;

      PDFXEdit.tagRECT rcDRPage;
      rcDRPage.left = (int)rcPageRect.left;
      rcDRPage.right = (int)rcPageRect.right;
      rcDRPage.top = (int)rcPageRect.bottom;
      rcDRPage.bottom = (int)rcPageRect.top;

      pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDRPage, 1.0);   

      pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDR, 1.0);
   }
Having this, I got a small rectangle at the bottom left of the page.
Note that 1.0 is used instead of 1
I checked the interop wrapers and both are the same.
[DispId(1610743821)]

Code: Select all

void DrawRect(ref tagRECT stRect, IUIX_Brush pBrush, IUIX_Pen pPen, ref tagRECT stClipRect, double nOpacity = 1);
I think you'd know about this. default parameters in DevStudio 10 will not work. they will be transferred as 0 instead of 1

But please, tell me how to draw rect over the Page bound? My code above not working to draw rec on entire page.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Fri Jun 09, 2017 2:55 pm

That's because you have not taken the needed page's rectangle:

Code: Select all

public void DrawRectangle(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage)
{
	PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout;
	if (plm == null)
		return;

	PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true);
	PDFXEdit.IPXC_Page page = pView.DocView.Doc.CoreDoc.Pages[nPage];
	PDFXEdit.PXC_Rect rc = page.get_Box(PXC_BoxType.PBox_PageBox); ;// = m_rcDraw;
	m_aInst.MathHelper.Rect_Transform(ref p2v, ref rc);

	//Flipping rectangle top and bottom coordinates and converting it's type
	PDFXEdit.tagRECT rcDR;
	rcDR.left = (int)rc.left;
	rcDR.right = (int)rc.right;
	rcDR.top = (int)rc.bottom;
	rcDR.bottom = (int)rc.top;

	pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDR, 1);
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Fri Jun 09, 2017 3:14 pm

Ok. Thank you. works.
But What is the

Code: Select all

 pPageRegions[i].rcPageRect
?
I thought this is also page rectangle.....

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Mon Jun 12, 2017 9:50 am

Hello Yury,

I've updated the description of this structure:
http://sdkhelp.tracker-software.com/vie ... youtRegion

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Tue Jun 13, 2017 11:43 am

Thanks Alex.
Could you please also point me to some description or sample on how to use pRC_.DrawString(
What I really need is draw Watermark string through the each page of the document. ( opacity is needed )

Thanks again!

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Tue Jun 13, 2017 11:50 am

Hello Yury,

Check out this sample:
https://github.com/tracker-software/PDFCoreSDKExamples

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Tue Jun 13, 2017 1:23 pm

Alex, I'm unable to build this sample. It seems uses VS2105.
Also, it is CoreAPI sample and uses different interfaces than IUIX_RenderContext.

I've spent a lot of time trying to implement simple things with your SDK. This is because it is not documented. This is not my fault.
Could you please give me example on how to do what I need.

I need draw watermark text through the pages. I'm using the RenderContext interface, as you've suggested in your previous posts.

Thanks.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Tue Jun 13, 2017 2:25 pm

Hello Yury,

Well that method is majorly self-explanatory, though I've updated it's description:
http://sdkhelp.tracker-software.com/vie ... DrawString
Basically one problem that you could struggle with is how to obtain the IUIX_Font - though there are the samples for that in the FullDemo application:

Code: Select all

PDFXEdit.IUIX_Theme th = uiInst.Theme;
PDFXEdit.IUIX_Font fnt = th.StdFont[PDFXEdit.UIX_StdFont.UIX_StdFont_Default];
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Yury
User
Posts: 70
Joined: Fri Oct 14, 2011 9:32 am

Re: Watermark

Post by Yury » Wed Jun 14, 2017 1:20 pm

Hello, thank you. I could draw text.

How can I draw image? I tried to use

Code: Select all

IStreamWrapper
class, which is described in some of your posts, but failed.
What I have is .Net Bitmap ( Image ) object.
I need to convert it to PDFXEdit.IUIX_ImageData, so I could use it in pRC_.DrawImage(.
How can I do this?

Code: Select all

System.IO.MemoryStream memStream = new System.IO.MemoryStream();
       watermark.Save( memStream, System.Drawing.Imaging.ImageFormat.Png );
       PDFXEditor.IStreamWrapper sw = new PDFXEditor.IStreamWrapper(memStream);
       _imgWatermark = m_uiInst.CreateImageFromIStream((IStream)sw);
This code produced type cast exception in last row.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4408
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Watermark

Post by Sasha - Tracker Dev Team » Wed Jun 14, 2017 2:57 pm

Hello Yury,

Here's a code sample for you to experiment with:

Code: Select all

public void DrawImage(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage)
{
	PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout;
	PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true);
	PDFXEdit.IPXC_Page page = pView.DocView.Doc.CoreDoc.Pages[nPage];
	PDFXEdit.PXC_Rect rcPage = page.get_Box(PXC_BoxType.PBox_PageBox); ;// = m_rcDraw;
	m_aInst.MathHelper.Rect_Transform(ref p2v, ref rcPage);
	PDFXEdit.tagRECT rcTagPage;
	rcTagPage.left = (int)rcPage.left;
	rcTagPage.top = (int)rcPage.bottom;
	rcTagPage.bottom = (int)rcPage.top;
	rcTagPage.right = (int)rcPage.right;


	//image = (Bitmap)Bitmap.FromFile(@"D:\PageImage.bmp");
	Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
	System.Drawing.Imaging.BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat);
	IUIX_ImageData iData = m_uiInst.CreateNewImage(image.Width, image.Height);
	// Get the address of the first line.
	IntPtr ptr = bmpData.Scan0;
	// Declare an array to hold the bytes of the bitmap.
	int bytes = Math.Abs(bmpData.Stride) * image.Height;
	byte[] rgbValues = new byte[bytes];

	IntPtr outPtr = new IntPtr(iData.Scan0);
	// Copy the RGB values into the array.
	System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
	// Copy the RGB values back to the bitmap
	System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, outPtr, bytes);
	// Unlock the bits.
	image.UnlockBits(bmpData);
	PDFXEdit.tagRECT rcImage;
	rcImage.left = 0;
	rcImage.right = image.Width;
	rcImage.bottom = image.Height;
	rcImage.top = 0;
	pRC_.DrawImage(iData, rcTagPage, rcImage, rcTagPage, (int)UIX_ImageScaleTypes.UIX_ImageScale_Stretch, (int)UIX_ImageScaleTypes.UIX_ImageScale_Stretch);
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply