Closed Robmcmon closed 3 years ago
Hello @Robmcmon, thanks for reaching out and providing the report. I will take a look and let you know what might be going wrong.
Ok so I went back to a old version that I had working 100% merging and everything and it resulted in this same error:
Unexpected error value: { type: "InvalidPDF", message: "Exception: \n\t Message: XML Parsing error\n\t Conditional expression: false\n\t Version : 8.0.0.76136\n\t Platform : Windows\n\t Architecture : AMD64\n\t Filename : XMLParser.cpp\n\t Function : trn::XML::XMLParser::Advance\n\t Linenumber : 132\n" }
Perhaps something changed with the PDF formatting from Adobe or something?
Okay, the XML with XFDF string is valid:
I think the issue is with the URL when it is trying to create the document. Could you please share what urlx.href
resolves to? We might need to add some options to tell what file to expect from the URL since it might not have the extension at the end of it, but would be good to see to confirm.
Feel free to schedule a debug session here: https://calendly.com/andrey_pdftron/30min.
so originally wrote a version of the code removing firebase and using a graphql, nodejs (rest api),knex(orm) and postgresql(db). However that backend had a bit of issues but it worked and the annotations would merge into the pdf between two users. I just retested that with only one user signing and it gave the error but when I re-tested it with two separate users it works great and I'm pulling the URL the same way but locally.
However I switched over to a graphql, typescript, typeorm, postgresql(db) new backend which I love and have everything working besides the merge annotations which resulted in the error above. I believe it might come down the how I am saving the XML into the database as its a bit more tricky to save that json field in typeorm... I have posted a question on it here: https://stackoverflow.com/questions/66002320/returning-a-json-column-in-typeorm-query
Thanks for the offer for the debug session. I've gone ahead and schedule a session for tomorrow but wanted to give you some background.
Technically graphql only supports Int, Float, String, Boolean and ID, so everything else is sent as one of those but then serialized or deserialized into a custom "Scalar".
It looks like maybe you are trying to pass an array of strings as a string?
Not sure though -- you can share your graphql schema.
I have the xfdf column defined like so this makes it a json column:
@Column({ type: 'json', nullable: true })
@Field(() => [String],{
nullable: true
})
xfdf: [String];
Then in my input type I have it defined as so in the export class:
@Field(() => [String],{
nullable: true
})
xfdf: [String];
This results in it being stored in the database like so:
[["<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xfdf xmlns=\"http://ns.adobe.com/xfdf/\" ...."]]
I've tried storing it several different ways however this way was effective in the previously version with my nodejs backend.
however when I do it this way now I get that error on retrieving prior to merging;
Unhandled Rejection (Error): GraphQL error: String cannot represent value: ["
I switched the column to pure json because after reviewing how I had it working before it is what worked. if not then I make it a simple array however then I run into the merge annotation error I mentioned before.
Hi Rob, one thing to try is to use xml-js
to go back and forth between XML and JSON for easier storage.
import WebViewer from '@pdftron/webviewer';
import convert from 'xml-js';
import './App.css';
const App = () => {
const viewer = useRef(null);
// if using a class, equivalent of componentDidMount
useEffect(() => {
WebViewer(
{
path: '/webviewer/lib',
initialDoc: '/files/PDFTRON_about.pdf',
},
viewer.current,
).then((instance) => {
const { docViewer, Annotations } = instance;
const annotManager = docViewer.getAnnotationManager();
const xfdf = `<?xml version="1.0" encoding="UTF-8"?><xfdf xmlns="http://ns.adobe.com/xfdf/" xmlns:xml="" xml:space="preserve"><fields><field name="robert@mydomain.com"><field name="io_SIGNATURE_16121228784590"><value>_DEFAULT</value></field></field></fields><annots><ink page="0" rect="141.353,462.4451018329939,460.397,581.139" color="#000000" flags="print" name="bb08dcd4-eb07-413b-bb35-31edf0397635" title="Guest" subject="Signature" date="D:20210131115455-08'00'" creationdate="D:20210131115454-08'00'"><inklist><gesture>149.25870672097759,538.9391317040055;150.1611846571623,538.9391317040055;155.57605227427024,544.353 9993211134;165.50330957230145,555.1837345553292;180.84543448744063,567.8184256619145;205.21233876442636 ,578.6481608961303;220.55446367956552,579.550638832315;222.35941955193482,578.6481608961303;221.4569416 1575017,566.0134697895452;206.11481670061102,545.256477257298;177.235522742702,526.3044405974201;151.06 366259334695,511.8647936184657;142.94136116768502,507.3524039375425;168.2107433808554,505.5474480651730 6;237.70154446707403,499.23010251188055;349.60880855397147,483.88797759674134;431.7343007467754,468.545 8526816021;442.56403598099115,464.03346300067886;438.95412423625254,464.03346300067886;430.831822810590 6,464.03346300067886;429.92934487440607,464.9359409368635;429.0268669382213,479.3755879158181;440.75908 010862184,492.9127569585879;454.29624915139175,504.64497012898846;458.808638832315,510.9623156822811;45 8.808638832315,514.5722274270197;456.10120502376105,518.1821391717583</gesture></inklist></ink></annots><pages><defmtx matrix="1,0,0,-1,0,792"/></pages></xfdf>`;
const json = convert.xml2json(xfdf);
const xfdfAfterConversion = convert.json2xml(json);
docViewer.on('documentLoaded', () => {
annotManager.importAnnotations(xfdfAfterConversion);
});
});
}, []);
return (
<div className="App">
<div className="header">React sample</div>
<div className="webviewer" ref={viewer}></div>
</div>
);
};
export default App;
Please reach out to support@pdftron.com if you have any more questions.
I'm attempting to merge my annotations from a new URL on my domain and the xfdf data stored in the database and receive the following error but am unsure what it means or how to troubleshoot that.
I pull the pdf link this:
It happens when I attempt to add the xml data via let res to this:
await PDFNet.FDFDoc.createFromXFDF(res);
This is what is contained inside of "res":
<?xml version="1.0" encoding="UTF-8"?><xfdf xmlns="http://ns.adobe.com/xfdf/" xmlns:xml="" xml:space="preserve"><fields><field name="robert@mydomain.com"><field name="io_SIGNATURE_16121228784590"><value>_DEFAULT</value></field></field></fields><annots><ink page="0" rect="141.353,462.4451018329939,460.397,581.139" color="#000000" flags="print" name="bb08dcd4-eb07-413b-bb35-31edf0397635" title="Guest" subject="Signature" date="D:20210131115455-08'00'" creationdate="D:20210131115454-08'00'"><inklist><gesture>149.25870672097759,538.9391317040055;150.1611846571623,538.9391317040055;155.57605227427024,544.353 9993211134;165.50330957230145,555.1837345553292;180.84543448744063,567.8184256619145;205.21233876442636 ,578.6481608961303;220.55446367956552,579.550638832315;222.35941955193482,578.6481608961303;221.4569416 1575017,566.0134697895452;206.11481670061102,545.256477257298;177.235522742702,526.3044405974201;151.06 366259334695,511.8647936184657;142.94136116768502,507.3524039375425;168.2107433808554,505.5474480651730 6;237.70154446707403,499.23010251188055;349.60880855397147,483.88797759674134;431.7343007467754,468.545 8526816021;442.56403598099115,464.03346300067886;438.95412423625254,464.03346300067886;430.831822810590 6,464.03346300067886;429.92934487440607,464.9359409368635;429.0268669382213,479.3755879158181;440.75908 010862184,492.9127569585879;454.29624915139175,504.64497012898846;458.808638832315,510.9623156822811;45 8.808638832315,514.5722274270197;456.10120502376105,518.1821391717583</gesture></inklist></ink></annots><pages><defmtx matrix="1,0,0,-1,0,792"/></pages></xfdf>
So based on the error I'm unsure if its a XML issue or a PDF issue in the way that I'm storing the file in the urlx.href link.. Any help in troubleshooting would be appreciated.