Skip to content

Commit 5208a8c

Browse files
committed
Improve handling for FDF parameter
Ensure fdf is always listed last in the URL string, per Adobe docs
1 parent ed401ac commit 5208a8c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

pdfobject.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
//Chromium has provided native PDF support since 2011.
5050
//Most modern browsers use Chromium under the hood: Google Chrome, Microsoft Edge, Opera, Brave, Vivaldi, Arc, and more.
51+
//Chromium uses the PDFium rendering engine, which is based on Foxit's PDF rendering engine.
52+
//Note that MS Edge opts to use a different PDF rendering engine. As of 2024, Edge uses a version of Adobe's Reader
5153
let isChromium = (win.chrome !== undefined);
5254

5355
//Safari on macOS has provided native PDF support since 2009.
@@ -64,7 +66,8 @@
6466
/*
6567
Special handling for Internet Explorer 11.
6668
Check for ActiveX support, then whether "AcroPDF.PDF" or "PDF.PdfCtrl" are valid.
67-
IE11 uses ActiveX for Adobe Reader and other PDF plugins, but window.ActiveXObject will evaluate to false. ("ActiveXObject" in window) evaluates to true.
69+
IE11 uses ActiveX for Adobe Reader and other PDF plugins, but window.ActiveXObject will evaluate to false.
70+
("ActiveXObject" in window) evaluates to true.
6871
MS Edge does not support ActiveX so this test will evaluate false for MS Edge.
6972
*/
7073
let validateAX = function (type){
@@ -109,7 +112,8 @@
109112
let string = "";
110113
let prop;
111114
let paramArray = [];
112-
115+
let fdf = "";
116+
113117
//The comment, viewrect, and highlight parameters require page to be set first.
114118

115119
//Check to ensure page is used if comment, viewrect, or highlight are specified
@@ -133,17 +137,31 @@
133137
delete pdfParams.page;
134138
}
135139

140+
//FDF needs to be the last parameter in the string
141+
if(pdfParams.fdf){
142+
fdf = pdfParams.fdf;
143+
delete pdfParams.fdf;
144+
}
145+
146+
//Add all other parameters, as needed
136147
if(pdfParams){
137148

138149
for (prop in pdfParams) {
139150
if (pdfParams.hasOwnProperty(prop)) {
140151
paramArray.push(encodeURIComponent(prop) + "=" + encodeURIComponent(pdfParams[prop]));
141152
}
142-
}
153+
}
154+
155+
//Add fdf as the last parameter, if needed
156+
if(fdf){
157+
paramArray.push("fdf=" + encodeURIComponent(fdf));
158+
}
143159

160+
//Join all parameters in the array into a string
144161
string = paramArray.join("&");
145162

146-
//The string will be empty if no PDF Params found
163+
//The string will be empty if no PDF Parameters were provided
164+
//Only prepend the hash if the string is not empty
147165
if(string){
148166
string = "#" + string;
149167
}

0 commit comments

Comments
 (0)