Can the Core API perform these functions?

A forum for questions or concerns related to the PDF-XChange Core API SDK

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

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
mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Can the Core API perform these functions?

Post by mmasood » Fri Feb 19, 2016 4:31 pm

Hi,

I am evaluating the Core API and here is a list of things that I need to achieve using only the Core API:

1. Open/Edit PDF document of any version (e.g. 1.4,1.5,1.6,1.7)
2. Manipulate PDF Forms and get Field positions of each of the fields present in a PDF form.
3. Draw fields/text on any custom location in the PDF document.
4. Merge multiple PDF documents.
5. Add watermarks.
6. Handle different page sizes of the PDF document.
7. Handle page angles
8. Add margins to a page and redraw a page
9. Layer support

So my question is

Can I do all of the above with the Core API?

Thanks,
M

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Mon Feb 22, 2016 7:27 am

Hello mmasood,

You can do these things using the Core API. Though if you want interactivity i.e. control on the form that would display your document and allow interactive features you should use the Editor SDK. Also, using the Editor SDK will allow to simplify the usage of our core functionality via using the operations. For example, merging the documents will require a big piece of code to be written in the Core API and the Editor SDK will allow to do that just by using one operation call.

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Can the Core API perform these functions?

Post by mmasood » Thu Feb 25, 2016 2:12 pm

Hi Alex,

I am using Editor SDK per your suggestion. I am using C# as the development language. I have been able to open a PDF Form and enter my own text in the fields. The next step that I need your help with are:

1. How can I access the coordinates of different fields on the PDF Form?
2. How can I take a PDF page and embed it on specific coordinates on another PDF page?

Can you provide me some sample code using the Editor SDK to perform these operations in C# or VB.NET?

Thanks.
M

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Thu Feb 25, 2016 3:25 pm

Hello mmasood,

1. You can get a Widget from the Field using this property http://sdkhelp.tracker-software.com/vie ... eld_Widget. And then you can get annotation http://sdkhelp.tracker-software.com/vie ... ation_Rect property to get it's coordinates on a page.

2. We can do that, but the problem is that we only can flatten or exclude fields when doing the embedding process. Please add more details to what you want and I'll write you a sample.

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Can the Core API perform these functions?

Post by mmasood » Thu Feb 25, 2016 6:20 pm

Hi Alex,

Thanks for the information, I am able to get the coordinates from the Form controls.

Regarding point 2, i think that flattening the fields will work in my case. However, if it does not work, can I embed the page from the second pdf and then draw/create the controls on the desired coordinates?

Can you provide me with the code for flattening the controls and embedding the second page at the specified coordinates in C# or VB.NET?

Regards,
M

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Fri Feb 26, 2016 2:52 pm

Hello mmasood,

Here's the sample on how to do that. Note that there are few issues with this functionality and it will be available in one of the nearest future builds.

Code: Select all

		private PDFXEdit.PXC_Matrix RectToRectMatrix(PDFXEdit.PXC_Rect from, PDFXEdit.PXC_Rect to)
		{
			PDFXEdit.PXC_Matrix m;
			if ((to.right == to.left) || (to.top == to.bottom) ||
			(from.left == from.right) || (from.top == from.bottom))
			{
				m.a = m.d = 1.0;
			}
			else
			{
				m.a = ((to.right - to.left) / (from.right - from.left));
				m.d = ((to.top - to.bottom) / (from.top - from.bottom));
			}
			m.b = 0;
			m.c = 0;
			m.e = (to.left - from.left * m.a);
			m.f = (to.bottom - from.bottom * m.d);
			return m;
		}

		private PDFXEdit.PXC_Matrix Multiply(PDFXEdit.PXC_Matrix m1, PDFXEdit.PXC_Matrix m2)
		{
			double t0 = (double)(m1.a * m2.a + m1.b * m2.c);
			double t2 = (double)(m1.c * m2.a + m1.d * m2.c);
			double t4 = (double)(m1.e * m2.a + m1.f * m2.c + m2.e);
			m1.b = (double)(m1.a * m2.b + m1.b * m2.d);
			m1.d = (double)(m1.c * m2.b + m1.d * m2.d);
			m1.f = (double)(m1.e * m2.b + m1.f * m2.d + m2.f);
			m1.a = t0;
			m1.c = t2;
			m1.e = t4;
			return m1;
		}

		private double Determinant(PDFXEdit.PXC_Matrix m)
		{
			double dd = (m.a * m.d - m.b * m.c);
			return ((dd == 0) ? 1.0 : (1.0 / dd));
		}

		private PDFXEdit.PXC_Matrix Invert(PDFXEdit.PXC_Matrix dest)
		{
			double det = Determinant(dest);

			double t0 = dest.d * det;
			dest.d = dest.a * det;
			dest.b = -dest.b * det;
			dest.c = -dest.c * det;

			double t4 = -dest.e * t0 - dest.f * dest.c;
			dest.f = -dest.e * dest.b - dest.f * dest.d;

			dest.a = t0;
			dest.e = t4;
			return dest;
		}
		void UpdateMinMax(double v, ref double vMin, ref double vMax)
		{
			if (vMin > v)
				vMin = v;
			if (vMax < v)
				vMax = v;
		}

		private void Transform(PDFXEdit.PXC_Matrix m1, ref double x, ref double y)
		{
			double tx = x;
			x = (tx * m1.a + y * m1.c + m1.e);
			y = (tx * m1.b + y * m1.d + m1.f);
		}

		private void TransformRect(PDFXEdit.PXC_Matrix m1, ref PDFXEdit.PXC_Rect rcPageBox)
		{
			double x = rcPageBox.left;
			double y = rcPageBox.bottom;
			Transform(m1, ref x, ref y);
			double x1 = x;
			double x2 = x;
			double y1 = y;
			double y2 = y;
			x = rcPageBox.left;
			y = rcPageBox.top;
			Transform(m1, ref x, ref y);
			UpdateMinMax(x, ref x1, ref x2);
			UpdateMinMax(y, ref y1, ref y2);
			x = rcPageBox.right;
			y = rcPageBox.top;
			Transform(m1, ref x, ref y);
			UpdateMinMax(x, ref x1, ref x2);
			UpdateMinMax(y, ref y1, ref y2);
			x = rcPageBox.right;
			y = rcPageBox.bottom;
			Transform(m1, ref x, ref y);
			UpdateMinMax(x, ref x1, ref x2);
			UpdateMinMax(y, ref y1, ref y2);
			rcPageBox.left = x1;
			rcPageBox.right = x2;
			rcPageBox.bottom = y1;
			rcPageBox.top = y2;
		}

		private void getFormFieldsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			PDFXEdit.IPXC_Document SrcDoc = pxcInst.OpenDocumentFromFile("D:\\TestFile.pdf", null);
			PDFXEdit.IPXC_Document DestDoc = pxcInst.OpenDocumentFromFile("D:\\TestFile1.pdf", null);
			PDFXEdit.IPXC_PagesOverlayInfo poi = pxcInst.CreatePagesOverlayInfo();
			//Getting source page
			PDFXEdit.IPXC_Page srcPage = SrcDoc.Pages[0];
			//Getting source page matrix
			PDFXEdit.PXC_Matrix srcPageMatrix = srcPage.GetMatrix(PDFXEdit.PXC_BoxType.PBox_PageBox);
			//Getting source page Page Box without rotation
			PDFXEdit.PXC_Rect srcRect = srcPage.get_Box(PDFXEdit.PXC_BoxType.PBox_PageBox);
			//Getting visual source Page Box by transforming it through matrix
			TransformRect(srcPageMatrix, ref srcRect);
			//Getting destination page
			PDFXEdit.IPXC_Page destPage = DestDoc.Pages[0];
			//Getting destination page matrix
			PDFXEdit.PXC_Matrix destPageMatrix = destPage.GetMatrix(PDFXEdit.PXC_BoxType.PBox_PageBox);
			//Getting destination page Page Box without rotation
			PDFXEdit.PXC_Rect destRect = destPage.get_Box(PDFXEdit.PXC_BoxType.PBox_PageBox);
			//Getting visual destination Page Box by transforming it through matrix
			TransformRect(destPageMatrix, ref destRect);
			//Forming resulting rectangle by indenting from the visual destination rectangle borders
			destRect.bottom += 100;
			destRect.top -= 100;
			destRect.left += 100;
			destRect.right -= 100;
			//We'll insert the visual src page into visual dest page indented rectangle including page rotations and clipping
			PDFXEdit.PXC_Matrix pageToRectMatrix = RectToRectMatrix(srcRect, destRect);
			//For that we invert and multiply matrix
			destPageMatrix = Invert(destPageMatrix);
			pageToRectMatrix = Multiply(pageToRectMatrix, destPageMatrix);
			//Inserting new data into the pages overlay info meaning we insert 0 source page into 0 destination page using the constructed matrix
			poi.InsertNew2(0, 0, ref pageToRectMatrix);
			//Applying overlays for the destination document
			DestDoc.Pages.OverlayPages(SrcDoc, poi);
			//Saving the document
			DestDoc.WriteToFile("D:\\TestFile_res.pdf");
		}
HTH,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

usmanakhtar
User
Posts: 18
Joined: Wed Feb 24, 2016 6:51 pm

Re: Can the Core API perform these functions?

Post by usmanakhtar » Fri Feb 26, 2016 5:24 pm

Hi Alex,

I am trying to use the code you have provided in response to mmasood's last query. In a method getFormFieldsToolStripMenuItem_Click(object sender, EventArgs e) you have used pxcInst instance of some control. Kindly let me know which control is this? I am using PDF-XChange Editor SDK with c# as development language.

Regards,
Usman.

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Fri Feb 26, 2016 7:37 pm

Hello usmanakhtar,

It's the IPXC_Inst that you should have got when you initialize the Core API. I just had a global variable with is for easier usage. As you are using the Editor SDK so that you can look inside the FullDemo sample on how to get it. Also note, that this code won't work correctly right now - our inner methods will be updated for that use in the nearest future builds.

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

usmanakhtar
User
Posts: 18
Joined: Wed Feb 24, 2016 6:51 pm

Re: Can the Core API perform these functions?

Post by usmanakhtar » Mon Feb 29, 2016 9:48 pm

Hi Alex,

Is it possible to convert the pages of one pdf document to images one by one and then put these image on the second pdf document at the specified coordinates.Can we convert page to verctor image. If possible then kindly provide me some code in C# or VB.NET?

Regards,
Usman Akhtar.

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Tue Mar 01, 2016 10:48 am

Hello usmanakhtar,

Yes it's possible and will work as described as in the sample above - Please search the forums and help files before asking questions to avoid duplicate posts.

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

usmanakhtar
User
Posts: 18
Joined: Wed Feb 24, 2016 6:51 pm

Re: Can the Core API perform these functions?

Post by usmanakhtar » Tue Mar 01, 2016 3:45 pm

Hi Alex,

I am trying to flatten the fields on a PDF Form using the "pdfEditor.Doc.CoreDoc.AcroForm.FlattenField" and "pdfEditor.Doc.CoreDoc.AcroForm.FlattenAllFields" methods but I am getting the same exception.

"The method or operation is not implemented."

Can you let me know how can I achieve the flattening of fields or a work around for this?

Regards,
Usman

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Tue Mar 01, 2016 3:51 pm

Hello usmanakhtar,

That means that these methods are not implemented yet. We will try to implement them in the nearest future.
You can use the Editor SDK to do that by using flatten annotations operation:
http://sdkhelp.tracker-software.com/vie ... ts_flatten

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

usmanakhtar
User
Posts: 18
Joined: Wed Feb 24, 2016 6:51 pm

Re: Can the Core API perform these functions?

Post by usmanakhtar » Tue Mar 01, 2016 5:52 pm

Hi,

Thanks Alex. Can you provide me with some code in c# for using "op.annots.flatten" to flatten the document.

Regards,
Usman Akhtar.

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

Re: Can the Core API perform these functions?

Post by Sasha - Tracker Dev Team » Wed Mar 02, 2016 8:20 am

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

Post Reply