Drawing a rect with PDF-Tools
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Drawing a rect with PDF-Tools
Hello!
I used to draw a rectangle of a certain color and thickness in PDF Viewer using annotations (with the JavaScript function addAnnot()).
Could I simply draw a rectangle with any function of the PDF-Tools Library or should I also create an Annotation with the PXCp_Add3DAnnotationW() function? The problem is I'm trying to use only the PDF-Tools in order to manipulate a PDF-Document.
Thanks for any answers!
I used to draw a rectangle of a certain color and thickness in PDF Viewer using annotations (with the JavaScript function addAnnot()).
Could I simply draw a rectangle with any function of the PDF-Tools Library or should I also create an Annotation with the PXCp_Add3DAnnotationW() function? The problem is I'm trying to use only the PDF-Tools in order to manipulate a PDF-Document.
Thanks for any answers!
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi relapse,
Have you tried the
PXCp_AddLineAnnotationW
method?
Cheers,
Stefan
Have you tried the
PXCp_AddLineAnnotationW
method?
Cheers,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Hi!
I have some questions on the PXCp_AddLineAnnotationW function:
1. The last parameter of the function is a pointer to a PXC_CommonAnnotInfo structure. It expects among other things an integer value for a color. Here is an extract from the docs with a pseudo code: I couldn't find any equivalent of that function in WPF. How is that value calculated?
This is an extract from my code:
I didn't define the values for AnnotInfo.m_Border.m_DashArray. No annotation is created. I tested it with JavaScript command this.getAnnots(0); It returns null.
Thanks!
I have some questions on the PXCp_AddLineAnnotationW function:
1. The last parameter of the function is a pointer to a PXC_CommonAnnotInfo structure. It expects among other things an integer value for a color. Here is an extract from the docs with a pseudo code:
Code: Select all
AnnotInfo.m_Color = RGB(200, 0, 100);
2. A comprehension question: should I draw four single lines in order to create a rectangle or can I directly draw a rectangle with that function (with the parameter LPCPXC_RectF rect that specifies the bounding rectangle of the annotation)?RGB(255, 255, 255) = 16777215 ???
This is an extract from my code:
Code: Select all
var borderRect = new PdfXchangePro.PXC_RectF { left = selection.Left,
right = selection.Right,
top = selection.Top,
bottom = selection.Bottom };
int color = 16777215; // RGB(255, 255, 255) ???
var border = new PdfXchangePro.PXC_AnnotBorder { m_Width = StrToDouble(BorderThickness),
m_Type = PdfXchangePro.PXC_AnnotBorderStyle.ABS_Solid };
var borderInfo = new PdfXchangePro.PXC_CommonAnnotInfo{ m_Color = color,
m_Flags = Convert.ToInt32(PdfXchangePro.PXC_AnnotsFlags.AF_ReadOnly),
m_Opacity = _opacity,
m_Border = border };
var startPoint = new PdfXchangePro.PXC_PointF {x = selection.Left, y = selection.Top};
var endPoint = new PdfXchangePro.PXC_PointF {x = selection.Right, y = selection.Bottom};
int retval = PdfXchangePro.PXCp_AddLineAnnotationW(_handle,
0,
ref borderRect,
"xy",
"yx",
ref startPoint,
ref endPoint,
PdfXchangePro.PXC_LineAnnotsType.LAType_None,
PdfXchangePro.PXC_LineAnnotsType.LAType_None,
color,
ref borderInfo); // function returns 0
Thanks!
-
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
Re: Drawing a rect with PDF-Tools
Can you send me PDF generated by your code ?
P.S. RGB is 'macro' is equivalent to the following function
P.S. RGB is 'macro' is equivalent to the following function
Code: Select all
// r, g, and b in range from 0 to 255
ULONG _RGB(int r, int g, int b)
{
return (ULONG)(r + g * 256 + b * 65536);
}
Tracker Software (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
I've got it! I had to close the document in the PDF viewer before creating a line annotation with PDF Tools Library function PXCp_AddLineAnnotationW!
I still don't understand whether I can create a rectangle as one annotation or I have to construct it generating 4 single lines? The third parameter (LPCPXC_RectF rect) in this function is according to the documentation a bounding rectangle of the
annotation. What is the use of it?
One more question. Is it possible to suppress the pop-up annotation dialog that appears after a double-click on the annotation? Are there any parameter in the PXCp_AddLineAnnotationW function to manage it. I've only found the flag PXC_AnnotsFlags.AF_ReadOnly of the PXC_CommonAnnotInfo class, that makes the line annotation (or the annotation bounding rectangle?) read-only.
I still don't understand whether I can create a rectangle as one annotation or I have to construct it generating 4 single lines? The third parameter (LPCPXC_RectF rect) in this function is according to the documentation a bounding rectangle of the
annotation. What is the use of it?
One more question. Is it possible to suppress the pop-up annotation dialog that appears after a double-click on the annotation? Are there any parameter in the PXCp_AddLineAnnotationW function to manage it. I've only found the flag PXC_AnnotsFlags.AF_ReadOnly of the PXC_CommonAnnotInfo class, that makes the line annotation (or the annotation bounding rectangle?) read-only.
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Another question: can I delete an annotation with PDF-Tools?
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi Relapse,
It is definitely possible with the low level functions, but unfortunately the only High Level ones are for adding annotations - not for deleting them.
Best,
Stefan
It is definitely possible with the low level functions, but unfortunately the only High Level ones are for adding annotations - not for deleting them.
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Could you please inform me which one I can use? In the documentation I've only found functions to add annotations, but nothing to delete them.
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hello relapse,
As mentioned before - there are no high level functions that will allow you to delete annotations.
So you will need to read on annotations in the PDF Reference:
http://wwwimages.adobe.com/www.adobe.co ... ce_1-7.pdf
section 8.4 Annotations in the above document
or section 12.4 Annotations in the ISO version of the file:
http://wwwimages.adobe.com/www.adobe.co ... 0_2008.pdf
And then utilize the low level functions described in
3.2.5 PDF Dictionary Functions of our PDF Tools SDK manual to read and manipulate the annotations dictionary as neeed.
Alternatively - you could use JS while you have the files opened in the Viewer AX. This should be quite a lot easier to implement, and will still allow you to create/edit/delete annotations as needed.
Best,
Stefan
Tracker
As mentioned before - there are no high level functions that will allow you to delete annotations.
So you will need to read on annotations in the PDF Reference:
http://wwwimages.adobe.com/www.adobe.co ... ce_1-7.pdf
section 8.4 Annotations in the above document
or section 12.4 Annotations in the ISO version of the file:
http://wwwimages.adobe.com/www.adobe.co ... 0_2008.pdf
And then utilize the low level functions described in
3.2.5 PDF Dictionary Functions of our PDF Tools SDK manual to read and manipulate the annotations dictionary as neeed.
Alternatively - you could use JS while you have the files opened in the Viewer AX. This should be quite a lot easier to implement, and will still allow you to create/edit/delete annotations as needed.
Best,
Stefan
Tracker
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Thanks for your reply. Is there any sample program demonstrating the use of dictionaries?
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi Relapse,
There are some snippets inside the manual, but there isn't anything more complex - as those are low level functions giving you access to the very structure of the PDF File and the way you would like to use such methods will greatly vary from case to case. You will need to get yourself acquainted with the PDF specification to be able to use those successfully.
Best,
Stefan
There are some snippets inside the manual, but there isn't anything more complex - as those are low level functions giving you access to the very structure of the PDF File and the way you would like to use such methods will greatly vary from case to case. You will need to get yourself acquainted with the PDF specification to be able to use those successfully.
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
I do read the pdf specification
I cannot understand how it is possible to access the Annotations-dictionary of a ceratin page.
I've found the function PXCp_ObjectGetDictionary, but it needs an object handle. Where can I get it?
I cannot understand how it is possible to access the Annotations-dictionary of a ceratin page.
I've found the function PXCp_ObjectGetDictionary, but it needs an object handle. Where can I get it?
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi relapse,
You might want to use functions like PXCp_llGetObjectByIndex to obtain an object first, and then here is the sample from the manual for using the PXCp_ObjectGetDictionary function:
Best,
Stefan
You might want to use functions like PXCp_llGetObjectByIndex to obtain an object first, and then here is the sample from the manual for using the PXCp_ObjectGetDictionary function:
Code: Select all
// Retrieve object's dictionary
HPDFOBJECT hObject;
...
HPDFDICTIONARY hDict;
hr = PXCp_ObjectGetDictionary(hObject, &hDict);
if (IS_DS_FAILED(hr))
{
// report error
...
}
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
I try to use the PXC_Rect function in order to draw a real rectangle and not an annotation.
HRESULT PXC_Rect(
_PXCContent* content,
double left,
double top,
double right,
double bottom
);
Parameters
content [in] Parameter content specifies the identifier for the page content to which the function will be applied.
What is this identifier for the page content and how can I get it?
Thanks!
HRESULT PXC_Rect(
_PXCContent* content,
double left,
double top,
double right,
double bottom
);
Parameters
content [in] Parameter content specifies the identifier for the page content to which the function will be applied.
What is this identifier for the page content and how can I get it?
Thanks!
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi Relapse,
This method is from the PXCLIB40 set of functions - those are aimed at creating new PDF document from scratch - so you can not use that to just add a rectangle to an already existing page I am afraid.
Otherwise - you can see how the content identifier is to be set up in the sample projects in
C:\Program Files\Tracker Software\PDF-XChange PRO 4 SDK\Examples\SDKExamples\<<YOUR Programming language>>\PDFXCDemo
Best,
Stefan
This method is from the PXCLIB40 set of functions - those are aimed at creating new PDF document from scratch - so you can not use that to just add a rectangle to an already existing page I am afraid.
Otherwise - you can see how the content identifier is to be set up in the sample projects in
C:\Program Files\Tracker Software\PDF-XChange PRO 4 SDK\Examples\SDKExamples\<<YOUR Programming language>>\PDFXCDemo
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Thanks, Stefan, your patience is honorable.
Is there any difference between
HRESULT PXCp_Init(PDFDocument* pObject, LPCSTR Key, LPCSTR DevCode);
and
HRESULT PXC_NewDocument(_PXCDocument** pdf, LPCSTR key, LPCSTR devCode);
? Are the both parameters PDFDocument* pObject and _PXCDocument** pdf identical?
I've tried to mix the use of the both libraries:
but I've got an AccessViolationException executing the PXC_GetPage function.
I've also found no function to delete a new created (with PXC_Rect) graphical object or is it not possible at all?
Is there any difference between
HRESULT PXCp_Init(PDFDocument* pObject, LPCSTR Key, LPCSTR DevCode);
and
HRESULT PXC_NewDocument(_PXCDocument** pdf, LPCSTR key, LPCSTR devCode);
? Are the both parameters PDFDocument* pObject and _PXCDocument** pdf identical?
I've tried to mix the use of the both libraries:
Code: Select all
int pageContentIdentifier;
int pdfHandle;
int pdfPage = 0;
PdfXchangePro.PXCp_Init(out pdfHandle, PdfXchangePro.SerialNumber, PdfXchangePro.DevelopmentCode);
PdfXchangePro.PXCp_ReadDocumentW(pdfHandle, _tempFile, 0);
PdfXchange.PXC_GetPage(pdfHandle, pdfPage, out pageContentIdentifier);
PdfXchange.PXC_Rect(pdfHandle, 20, 100, 100, 20);
I've also found no function to delete a new created (with PXC_Rect) graphical object or is it not possible at all?
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hi Relapse,
I am afraid you can't mix methods from the two libraries. You will need to create and save a PDF file using the PXC_ methods, and then open it and modify it using the PCXp_ones.
As PCX_ methods are designed for building up PDF files - there are no delete methods - as you are creating a pdf file or page starting from an empty one and only adding the components you want.
Best,
Stefan
I am afraid you can't mix methods from the two libraries. You will need to create and save a PDF file using the PXC_ methods, and then open it and modify it using the PCXp_ones.
As PCX_ methods are designed for building up PDF files - there are no delete methods - as you are creating a pdf file or page starting from an empty one and only adding the components you want.
Best,
Stefan
-
- User
- Posts: 167
- Joined: Wed Jan 18, 2012 11:10 am
Re: Drawing a rect with PDF-Tools
Yesterday I managed to draw a rectangle I needed but the restriction is - it must be a new pdf document. It's a pity!
Now I'm trying to delete line annotations directly in dictionaries. By the way I can create a line annotation of any thickness with the function PXCp_AddLineAnnotationW, there is no such a limit of 20 points as in JS. But I miss very much any examples for handling the dictionaries. I've found an example in the forum https://forum.pdf-xchange.com/ ... nnotationW but it's in C++ and I'm fighting with translation of the of the low-level functions' declarations into C#.
Now I'm trying to delete line annotations directly in dictionaries. By the way I can create a line annotation of any thickness with the function PXCp_AddLineAnnotationW, there is no such a limit of 20 points as in JS. But I miss very much any examples for handling the dictionaries. I've found an example in the forum https://forum.pdf-xchange.com/ ... nnotationW but it's in C++ and I'm fighting with translation of the of the low-level functions' declarations into C#.
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: Drawing a rect with PDF-Tools
Hello Relapse,
Glad to hear that you got it working. And great to hear there are no width limitations with the PXCp_AddLineAnnotationW method.
As for samples for handling dictionaries - I am afraid that I can't help - any any samples would probably be in the PDF Specification itself.
Best,
Stefan
Glad to hear that you got it working. And great to hear there are no width limitations with the PXCp_AddLineAnnotationW method.
As for samples for handling dictionaries - I am afraid that I can't help - any any samples would probably be in the PDF Specification itself.
Best,
Stefan
-
- User
- Posts: 381
- Joined: Mon Jun 13, 2011 5:10 pm
Re: Drawing a rect with PDF-Tools
The best advice here is to look at the C# wrappers for other projects. It is important to use the proper marshalling for types like BSTR and LPWSTR (from C# "string" types). If you look at function declarations for DLL imports in C# you'll often see a function argument prefixed by something like:relapse wrote:Yesterday I managed to draw a rectangle I needed but the restriction is - it must be a new pdf document. It's a pity!
Now I'm trying to delete line annotations directly in dictionaries. By the way I can create a line annotation of any thickness with the function PXCp_AddLineAnnotationW, there is no such a limit of 20 points as in JS. But I miss very much any examples for handling the dictionaries. I've found an example in the forum https://forum.pdf-xchange.com/ ... nnotationW but it's in C++ and I'm fighting with translation of the of the low-level functions' declarations into C#.
Code: Select all
[MarshalAs(UnmanagedType.LPWStr)]
Code: Select all
sometype somefunction([MarshalAs(UnmanagedType.LPWStr)] string InputLPWSTR);
UnmanagedType has a lot of members (LPWStr, BStr, etc) that you can specify for different scenarios. Check MSDN for details or use autocomplete in Visual Studio to see a list.
Also note the use of "ref" and "out" keywords that are used when the API function takes a pointer. "ref" means C# will check to see if the value is initialized; "out" means it may be uninitialized and is expected to be set by the function.
Code: Select all
E.g. C++:
HRESULT calculate_property_of_mystruct(mystruct* input, int* output);
would be imported into C# with:
... calculate_property_of_mystruct(ref mystruct input, out int output);
Lots of reading here:
http://msdn.microsoft.com/en-us/library/26thfadc.aspx
http://msdn.microsoft.com/en-us/library/fzhhdwae.aspx