Merging XFDF using the Express REST API. Error - Invalid input

Which product are you using?
PDF.js Express REST API

PDF.js Express Version
Latest

Detailed description of issue
I’ve successfully merged XFDF in PDF using the REST API through a POST request. However, when I attempted to implement the same functionality in .NET by calling the REST API, I encountered an error. The error message reads: "Code 20: Invalid input. I’ve tried different PDF files, but the error remains the same every time.

Expected behaviour
It should merge XFDF in PDF and return PDF file.

Does your issue happen with every document, or just one?
Every document

Link to document
This is sample test PDF - https://www.clickdimensions.com/links/TestPDFfile.pdf

Code snippet

var httpClient = new HttpClient();
var formData = new MultipartFormDataContent();
formData.Add(new StringContent("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\"><pdf-info xmlns=\"http://www.pdftron.com/pdfinfo\" version=\"2\" import-version=\"4\" /><fields /><annots><ink page=\"0\" rect=\"568.680,257.710,593.950,560.210\" color=\"#E44234\" flags=\"print\" name=\"b63b8878-d15e-d2cd-69b9-c4a1043ee3d2\" title=\"Guest\" subject=\"Free Hand\" date=\"D:20240417164837+05'30'\" creationdate=\"D:20240417164833+05'30'\"><inklist><gesture>584.49,559.21;584.49,558.15;584.49,557.1;584.49,554.98;584.49,550.75;584.49,543.34;584.49,535.9300000000001;584.49,528.53;585.55,524.29;585.55,521.12;585.55,517.95;585.55,514.77;585.55,513.71;585.55,512.6600000000001;586.61,511.6;586.61,510.54;586.61,509.48;586.61,508.42;586.61,507.36;586.61,506.31;586.61,504.19;586.61,503.13;586.61,502.07;586.61,501.02;586.61,499.96;586.61,498.9;586.61,497.84;586.61,496.78;586.61,495.73;586.61,494.67;586.61,492.55;586.61,491.49;586.61,488.32;586.61,486.2;586.61,484.09;586.61,480.91;586.61,476.68;586.61,472.45;586.61,468.21;586.61,463.98;586.61,460.81;586.61,457.63;586.61,454.46;586.61,453.4;586.61,451.28;586.61,447.05;586.61,444.94;586.61,441.76;587.66,436.47;588.72,431.18;588.72,426.95;588.72,423.77;588.72,420.6;588.72,416.37;588.72,414.25;589.78,411.08;589.78,407.9;589.78,405.78;589.78,404.73;589.78,402.61;589.78,400.49;589.78,398.38;589.78,395.2;589.78,392.03;589.78,389.91;589.78,387.8;589.78,386.74;589.78,384.62;589.78,383.56;589.78,382.51;589.78,381.45;589.78,380.39;589.78,379.33;589.78,378.27;589.78,377.22;589.78,376.16;589.78,374.04;589.78,371.92;589.78,369.81;589.78,367.69;589.78,365.58;589.78,363.46;589.78,361.34;590.84,359.23;590.84,356.05;590.84,352.88;591.9,349.7;591.9,346.53;591.9,342.3;591.9,339.12;591.9,334.89;591.9,331.72;591.9,326.43;591.9,322.19;591.9,317.96;591.9,313.73;591.9,307.38;591.9,303.15;591.9,298.91;591.9,294.68;591.9,291.51;591.9,290.45;592.95,288.33;592.95,289.39;592.95,292.57;592.95,298.91;592.95,309.5;592.95,320.08;592.95,330.66;592.95,343.36;592.95,354.99;592.95,366.63;591.9,380.39;589.78,392.03;589.78,399.44;588.72,407.9;587.66,416.37;587.66,423.77;587.66,432.24;587.66,437.53;587.66,444.94;587.66,453.4;587.66,459.75;587.66,465.04;586.61,469.27;586.61,472.45;586.61,475.62;586.61,478.8;586.61,480.91;586.61,483.03;586.61,486.2;586.61,490.43;586.61,493.61;586.61,498.9;586.61,504.19;586.61,511.6;586.61,515.8299999999999;586.61,522.1800000000001;586.61,527.47;586.61,530.64;586.61,531.7;586.61,533.8199999999999;586.61,534.88;586.61,535.9300000000001;586.61,536.99;586.61,538.05;585.55,539.11;585.55,540.17;585.55,541.22;584.49,542.28;584.49,543.34;583.43,544.4;582.37,544.4;581.31,543.34;581.31,533.8199999999999;581.31,515.8299999999999;581.31,492.55;581.31,461.87;581.31,423.77;581.31,388.85;581.31,351.82;581.31,320.08;583.43,295.74;583.43,275.64;583.43,262.94000000000005;583.43,258.71000000000004;583.43,259.76;583.43,265.04999999999995;583.43,279.87;583.43,296.8;583.43,320.08;583.43,348.65;583.43,382.51;582.37,420.6;582.37,455.52;582.37,480.91;582.37,504.19;581.31,519;581.31,528.53;581.31,532.76;581.31,533.8199999999999;580.26,533.8199999999999;580.26,532.76;580.26,528.53;580.26,519;580.26,506.31;581.31,490.43;583.43,474.56;583.43,458.69;583.43,444.94;584.49,436.47;585.55,432.24;585.55,430.12;585.55,433.3;585.55,442.82;585.55,458.69;585.55,479.85;585.55,494.67;585.55,511.6;585.55,530.64;583.43,540.17;581.31,546.52;580.26,547.5699999999999;580.26,546.52;580.26,544.4;580.26,536.99;580.26,521.12;580.26,499.96;580.26,467.16;583.43,434.35;585.55,399.44;585.55,374.04;585.55,350.76;585.55,339.12;585.55,334.89;585.55,332.77;585.55,333.83;585.55,343.36;585.55,362.4;585.55,383.56;585.55,401.55;585.55,423.77;583.43,451.28;578.14,481.97;573.91,506.31;572.85,517.95;572.85,522.1800000000001;571.79,523.24;571.79,521.12;571.79,513.71;571.79,502.07;572.85,490.43;572.85,480.91;572.85,468.21;572.85,454.46;572.85,441.76;572.85,429.06;572.85,419.54;572.85,413.19;572.85,410.02;572.85,411.08;572.85,415.31;572.85,423.77;572.85,430.12;571.79,436.47;571.79,438.59;569.68,441.76;569.68,442.82;569.68,443.88</gesture></inklist></ink><square page=\"0\" rect=\"567.560,105.280,598.240,226.960\" color=\"#E44234\" flags=\"print\" name=\"30820083-f674-0600-bd10-704864f5d1da\" title=\"Guest\" subject=\"Rectangle\" date=\"D:20240417164841+05'30'\" creationdate=\"D:20240417164840+05'30'\"/><circle page=\"0\" rect=\"433.640,579.470,590.640,757.820\" color=\"#E44234\" flags=\"print\" name=\"720caa28-b27c-0cbf-276e-1f9f6c6d7f81\" title=\"Guest\" subject=\"Ellipse\" date=\"D:20240417164851+05'30'\" creationdate=\"D:20240417164849+05'30'\"/><line page=\"0\" rect=\"464.680,160.880,466.680,362.600\" color=\"#E44234\" flags=\"print\" name=\"e7226a87-2a72-3cb6-4ae6-65de3ac9f043\" title=\"Guest\" subject=\"Line\" date=\"D:20240417164858+05'30'\" creationdate=\"D:20240417164856+05'30'\" start=\"465.68,361.6\" end=\"465.68,161.88\"/><line page=\"0\" rect=\"436.920,420.400,490.180,516.390\" color=\"#E44234\" flags=\"print\" name=\"84e42ce6-9993-9765-f7a5-edecea943554\" title=\"Guest\" subject=\"Line\" date=\"D:20240417164913+05'30'\" IT=\"LineArrow\" creationdate=\"D:20240417164912+05'30'\" start=\"437.92,515.39\" end=\"489.18,421.4\" tail=\"OpenArrow\"/><line page=\"0\" rect=\"420.900,425.740,473.090,470.460\" color=\"#E44234\" flags=\"print\" name=\"fad4ee84-1fff-a39a-7455-5e35b40ffb74\" title=\"Guest\" subject=\"Line\" date=\"D:20240417164914+05'30'\" IT=\"LineArrow\" creationdate=\"D:20240417164913+05'30'\" start=\"421.9,469.46\" end=\"472.09,426.74\" tail=\"OpenArrow\"/><line page=\"0\" rect=\"441.190,404.380,475.230,496.100\" color=\"#E44234\" flags=\"print\" name=\"f3a446d0-c483-a040-b68d-3e1aab92a486\" title=\"Guest\" subject=\"Line\" date=\"D:20240417164915+05'30'\" IT=\"LineArrow\" creationdate=\"D:20240417164914+05'30'\" start=\"474.23,495.1\" end=\"442.19,405.38\" tail=\"OpenArrow\"/><square page=\"0\" rect=\"100,592,300,642\" color=\"#000000\" flags=\"print\" name=\"dab14f47-98ac-cad0-9079-010cc261c5b9\" subject=\"Rectangle\" date=\"D:20240417164928+05'30'\" creationdate=\"D:20240417164928+05'30'\"><trn-custom-data bytes=\"{&quot;trn-annot-no-delete&quot;:&quot;true&quot;}\"/></square></annots><pages><defmtx matrix=\"1,0,0,-1,0,792\" /></pages></xfdf>"), "xfdf");
formData.Add(new StringContent("https://www.clickdimensions.com/links/TestPDFfile.pdf"), "file");

var response = await httpClient.PostAsync("https://api.pdfjs.express/xfdf/merge", formData);
string jsonResponse = await response.Content.ReadAsStringAsync();

Hi there,

The Merge API requires you to append the XFDF and the file with the following formats as shown in this guide:

Perhaps StringContent is not setting it as the correct type? Could you please try converting the PDF to a different format (i.e. blob) and then using the API and see if that works for you?

Best regards,
Kevin Kim

Hi Kkim

Yes, I am passing XFDF and file URL as string As per the document on (Merging XFDF using the Express REST API | Documentation).

As you can see it works in Postman with the same data.

Hi there,

Does it still fail if you use the utility package?

If so, could you please share a minimal runnable sample project?

Best regards,
Kevin Kim