ParamConverter.cs 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219
  1. using ComPDFKit.Import;
  2. using ComPDFKit.Measure;
  3. using ComPDFKit.PDFAnnotation;
  4. using ComPDFKit.PDFAnnotation.Form;
  5. using ComPDFKit.PDFDocument;
  6. using ComPDFKit.PDFDocument.Action;
  7. using ComPDFKit.PDFPage;
  8. using ComPDFKit.PDFPage.Edit;
  9. using ComPDFKit.Tool.SettingParam;
  10. using ComPDFKit.Tool.UndoManger;
  11. using ComPDFKit.Viewer.Helper;
  12. using ComPDFKitViewer.Helper;
  13. using ComPDFKitViewer;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Windows;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using static ComPDFKit.PDFAnnotation.CTextAttribute;
  21. using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
  22. namespace ComPDFKit.Tool.Help
  23. {
  24. /// <summary>
  25. /// Some quick conversion tools for parameters
  26. /// </summary>
  27. public static class ParamConverter
  28. {
  29. public enum FormField
  30. {
  31. /// <summary>
  32. /// Visible
  33. /// </summary>
  34. Visible,
  35. /// <summary>
  36. /// Hidden
  37. /// </summary>
  38. Hidden,
  39. /// <summary>
  40. /// Visible but unprintable
  41. /// </summary>
  42. VisibleNoPrint,
  43. /// <summary>
  44. /// Hidden but printable
  45. /// </summary>
  46. HiddenPrintable
  47. }
  48. public static AnnotHistory CreateHistory(CPDFAnnotation cPDFAnnotation)
  49. {
  50. AnnotHistory annotHistory = null;
  51. switch (cPDFAnnotation.Type)
  52. {
  53. case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
  54. break;
  55. case C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN:
  56. break;
  57. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  58. annotHistory = new StickyNoteAnnotHistory();
  59. break;
  60. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  61. annotHistory = new LinkAnnotHistory();
  62. break;
  63. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  64. annotHistory = new FreeTextAnnotHistory();
  65. break;
  66. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  67. if ((cPDFAnnotation as CPDFLineAnnotation).IsMeasured())
  68. {
  69. annotHistory = new LineMeasureAnnotHistory();
  70. }
  71. else
  72. {
  73. annotHistory = new LineAnnotHistory();
  74. }
  75. break;
  76. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  77. annotHistory = new SquareAnnotHistory();
  78. break;
  79. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  80. annotHistory = new CircleAnnotHistory();
  81. break;
  82. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  83. annotHistory = new PolygonMeasureAnnotHistory();
  84. break;
  85. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  86. annotHistory = new PolyLineMeasureAnnotHistory();
  87. break;
  88. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  89. annotHistory = new HighlightAnnotHistory();
  90. break;
  91. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  92. annotHistory = new UnderlineAnnotHistory();
  93. break;
  94. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  95. annotHistory = new SquigglyAnnotHistory();
  96. break;
  97. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  98. annotHistory = new StrikeoutAnnotHistory();
  99. break;
  100. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  101. annotHistory = new StampAnnotHistory();
  102. break;
  103. case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
  104. break;
  105. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  106. annotHistory = new InkAnnotHistory();
  107. break;
  108. case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
  109. break;
  110. case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
  111. break;
  112. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  113. annotHistory = new SoundAnnotHistory();
  114. break;
  115. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  116. break;
  117. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  118. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  119. {
  120. case C_WIDGET_TYPE.WIDGET_NONE:
  121. break;
  122. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  123. annotHistory = new PushButtonHistory();
  124. break;
  125. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  126. annotHistory = new CheckBoxHistory();
  127. break;
  128. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  129. annotHistory = new RadioButtonHistory();
  130. break;
  131. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  132. annotHistory = new TextBoxHistory();
  133. break;
  134. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  135. annotHistory = new ComboBoxHistory();
  136. break;
  137. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  138. annotHistory = new ListBoxHistory();
  139. break;
  140. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  141. annotHistory = new SignatureHistory();
  142. break;
  143. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  144. break;
  145. default:
  146. break;
  147. }
  148. break;
  149. case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
  150. break;
  151. case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
  152. break;
  153. case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
  154. break;
  155. case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
  156. break;
  157. case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
  158. break;
  159. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  160. break;
  161. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  162. annotHistory = new RedactAnnotHistory();
  163. break;
  164. case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
  165. break;
  166. default:
  167. break;
  168. }
  169. return annotHistory;
  170. }
  171. public static bool RemovePageAnnot(Dictionary<int, List<int>> removeAnnots, CPDFViewer cPDFViewer)
  172. {
  173. CPDFDocument cPDFDocument = cPDFViewer.GetDocument();
  174. if (cPDFDocument == null || removeAnnots.Count <= 0)
  175. {
  176. return false;
  177. }
  178. GroupHistory historyGroup = new GroupHistory();
  179. foreach (int pageIndex in removeAnnots.Keys)
  180. {
  181. CPDFPage pageCore = cPDFDocument.PageAtIndex(pageIndex);
  182. List<CPDFAnnotation> cPDFAnnotations = pageCore.GetAnnotations();
  183. foreach (int annotIndex in removeAnnots[pageIndex])
  184. {
  185. CPDFAnnotation cPDFAnnotation = cPDFAnnotations.ElementAtOrDefault(annotIndex);
  186. if (cPDFAnnotation != null)
  187. {
  188. AnnotParam annotParam = CPDFDataConverterToAnnotParam(cPDFDocument, pageIndex, cPDFAnnotation);
  189. if (annotParam is StampParam stampParam)
  190. {
  191. if (stampParam.StampType == C_STAMP_TYPE.IMAGE_STAMP)
  192. {
  193. stampParam.CopyImageAnnot = CPDFAnnotation.CopyAnnot(cPDFAnnotation);
  194. }
  195. }
  196. AnnotHistory annotHistory = CreateHistory(cPDFAnnotation);
  197. annotHistory.CurrentParam = annotParam;
  198. annotHistory.PDFDoc = cPDFDocument;
  199. annotHistory.Action = HistoryAction.Remove;
  200. historyGroup.Histories.Add(annotHistory);
  201. }
  202. }
  203. }
  204. if (historyGroup.Histories.Count > 0)
  205. {
  206. cPDFViewer.UndoManager.AddHistory(historyGroup);
  207. }
  208. foreach (int pageIndex in removeAnnots.Keys)
  209. {
  210. CPDFPage pageCore = cPDFDocument.PageAtIndex(pageIndex);
  211. List<CPDFAnnotation> cPDFAnnotations = pageCore.GetAnnotations();
  212. foreach (int annotIndex in removeAnnots[pageIndex])
  213. {
  214. CPDFAnnotation cPDFAnnotation = cPDFAnnotations.ElementAtOrDefault(annotIndex);
  215. if (cPDFAnnotation != null)
  216. {
  217. cPDFAnnotation.RemoveAnnot();
  218. }
  219. }
  220. }
  221. return true;
  222. }
  223. public static FormField ConverterWidgetFormFlags(int Flags, bool IsHidden)
  224. {
  225. int flag = Flags;
  226. bool invisible = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible) != 0;
  227. bool noview = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView) != 0;
  228. bool print = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint) != 0;
  229. if (noview && print)
  230. {
  231. return FormField.HiddenPrintable;
  232. }
  233. if (IsHidden || noview || invisible)
  234. {
  235. return FormField.Hidden;
  236. }
  237. bool visibleflag = !IsHidden && !invisible && !noview && !print;
  238. if (visibleflag)
  239. {
  240. return FormField.VisibleNoPrint;
  241. }
  242. return FormField.Visible;
  243. }
  244. public static int GetFormFlags(FormField field, CPDFWidget widget)
  245. {
  246. int flag = widget.GetFlags();
  247. switch (field)
  248. {
  249. case FormField.Hidden:
  250. widget.SetIsHidden(true);
  251. flag = widget.GetFlags();
  252. break;
  253. case FormField.Visible:
  254. {
  255. int newflag = (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagHidden
  256. | (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible;
  257. flag &= ~newflag;
  258. flag |= (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint;
  259. }
  260. break;
  261. case FormField.VisibleNoPrint:
  262. {
  263. int newflag = (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint |
  264. (int)CPDFAnnotationFlags.CPDFAnnotationFlagHidden | (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible;
  265. flag &= ~newflag;
  266. }
  267. break;
  268. case FormField.HiddenPrintable:
  269. {
  270. flag = flag | (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint;
  271. }
  272. break;
  273. default:
  274. break;
  275. }
  276. return flag;
  277. }
  278. public static Color ConverterByteForColor(byte[] bytes)
  279. {
  280. if (bytes != null && bytes.Length == 3)
  281. {
  282. return new Color { R = bytes[0], G = bytes[1], B = bytes[2], A = 255};
  283. }
  284. return new Color { R = 0, G = 0, B = 0, A = 0 };
  285. }
  286. public static void ParseDashStyle(DashStyle dashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle)
  287. {
  288. if (dashStyle == DashStyles.Solid || dashStyle == null)
  289. {
  290. LineDash = new float[0];
  291. BorderStyle = C_BORDER_STYLE.BS_SOLID;
  292. }
  293. else
  294. {
  295. List<float> floatArray = new List<float>();
  296. foreach (double num in dashStyle.Dashes)
  297. {
  298. floatArray.Add((float)num);
  299. }
  300. LineDash = floatArray.ToArray();
  301. BorderStyle = C_BORDER_STYLE.BS_DASHDED;
  302. }
  303. }
  304. public static AnnotParam CPDFDataConverterToAnnotParam(CPDFDocument cPDFDocument, int PageIndex, CPDFAnnotation cPDFAnnotation)
  305. {
  306. if (cPDFAnnotation == null && !cPDFAnnotation.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid())
  307. {
  308. return null;
  309. }
  310. AnnotParam annotParam = null;
  311. if (cPDFAnnotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  312. {
  313. annotParam = WidgetConverter(cPDFDocument, cPDFAnnotation);
  314. }
  315. else
  316. {
  317. annotParam = AnnotConverter(cPDFDocument, cPDFAnnotation);
  318. }
  319. if (annotParam != null)
  320. {
  321. annotParam.PageIndex = PageIndex;
  322. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(annotParam.PageIndex, false);
  323. List<CPDFAnnotation> cPDFAnnotations = cPDFPage.GetAnnotations();
  324. annotParam.AnnotIndex = cPDFAnnotations.IndexOf(cPDFAnnotation);
  325. }
  326. return annotParam;
  327. }
  328. public static PDFEditParam CPDFDataConverterToPDFEitParam(CPDFDocument cPDFDocument, CPDFEditArea cPDFEditArea, int pageIndex)
  329. {
  330. PDFEditParam annotParam = null;
  331. if (cPDFEditArea == null && !cPDFEditArea.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid() && pageIndex >= 0)
  332. {
  333. return null;
  334. }
  335. switch (cPDFEditArea.Type)
  336. {
  337. case CPDFEditType.None:
  338. break;
  339. case CPDFEditType.EditText:
  340. annotParam = GetTextEditParam(cPDFDocument, cPDFEditArea as CPDFEditTextArea, pageIndex);
  341. break;
  342. case CPDFEditType.EditImage:
  343. annotParam = GetImageEditParam(cPDFDocument, cPDFEditArea as CPDFEditImageArea, pageIndex);
  344. break;
  345. case CPDFEditType.EditPath:
  346. annotParam = GetPathEditParam(cPDFDocument, cPDFEditArea as CPDFEditPathArea, pageIndex);
  347. break;
  348. default:
  349. break;
  350. }
  351. return annotParam;
  352. }
  353. #region PDFEdit
  354. internal static TextEditParam GetTextEditParam(CPDFDocument cPDFDocument, CPDFEditTextArea cPDFEditArea, int pageIndex)
  355. {
  356. TextEditParam textEditParam = new TextEditParam();
  357. string fontName = "Helvetica";
  358. float fontSize = 14;
  359. byte[] fontColor = {0,0,0};
  360. byte transparency = 255;
  361. bool isBold = false;
  362. bool isItalic = false;
  363. cPDFEditArea.GetTextStyle(ref fontName,ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  364. textEditParam.FontName = fontName;
  365. textEditParam.FontSize = fontSize;
  366. textEditParam.FontColor = fontColor;
  367. textEditParam.Transparency = transparency;
  368. textEditParam.TextAlign = cPDFEditArea.GetTextSectionAlign();
  369. textEditParam.EditType = CPDFEditType.EditText;
  370. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  371. CPDFEditPage editPage = docPage.GetEditPage();
  372. textEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  373. textEditParam.PageIndex = pageIndex;
  374. if(string.IsNullOrEmpty(cPDFEditArea.SelectText))
  375. {
  376. textEditParam.IsBold = isBold;
  377. textEditParam.IsItalic = isItalic;
  378. }
  379. else
  380. {
  381. textEditParam.IsBold = cPDFEditArea.IsCharsFontBold();
  382. textEditParam.IsItalic = cPDFEditArea.IsCharsFontItalic();
  383. }
  384. return textEditParam;
  385. }
  386. internal static ImageEditParam GetImageEditParam(CPDFDocument cPDFDocument, CPDFEditImageArea cPDFEditArea, int pageIndex)
  387. {
  388. ImageEditParam imageEditParam = new ImageEditParam();
  389. imageEditParam.Transparency = cPDFEditArea.GetImageTransparency();
  390. imageEditParam.Rotate = cPDFEditArea.GetRotation();
  391. imageEditParam.ClipRect = cPDFEditArea.GetClipRect();
  392. imageEditParam.EditType = CPDFEditType.EditImage;
  393. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  394. CPDFEditPage editPage = docPage.GetEditPage();
  395. imageEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  396. imageEditParam.PageIndex = pageIndex;
  397. return imageEditParam;
  398. }
  399. internal static PathEditParam GetPathEditParam(CPDFDocument cPDFDocument, CPDFEditPathArea cPDFEditArea, int pageIndex)
  400. {
  401. PathEditParam pathEditParam = new PathEditParam();
  402. pathEditParam.Transparency = cPDFEditArea.GetTransparency();
  403. pathEditParam.Rotate = cPDFEditArea.GetRotation();
  404. pathEditParam.StrokeColor = cPDFEditArea.GetStrokeColor();
  405. pathEditParam.FillColor = cPDFEditArea.GetFillColor();
  406. pathEditParam.ClipRect = cPDFEditArea.GetClipRect();
  407. pathEditParam.EditType = CPDFEditType.EditPath;
  408. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  409. CPDFEditPage editPage = docPage.GetEditPage();
  410. pathEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  411. pathEditParam.PageIndex = pageIndex;
  412. return pathEditParam;
  413. }
  414. #endregion
  415. #region Widegt
  416. internal static AnnotParam WidgetConverter(CPDFDocument document, CPDFAnnotation cPDFAnnotation)
  417. {
  418. AnnotParam annotParam = null;
  419. if (cPDFAnnotation is CPDFWidget)
  420. {
  421. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  422. {
  423. case C_WIDGET_TYPE.WIDGET_NONE:
  424. break;
  425. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  426. annotParam = GetPushButtonParam(document, cPDFAnnotation as CPDFPushButtonWidget);
  427. break;
  428. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  429. annotParam = GetCheckBoxParam(cPDFAnnotation as CPDFCheckBoxWidget);
  430. break;
  431. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  432. annotParam = GetRadioButtonParam(cPDFAnnotation as CPDFRadioButtonWidget);
  433. break;
  434. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  435. annotParam = GetTextBoxParam(cPDFAnnotation as CPDFTextWidget);
  436. break;
  437. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  438. annotParam = GetComboBoxParam(cPDFAnnotation as CPDFComboBoxWidget);
  439. break;
  440. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  441. annotParam = GetListBoxParam(cPDFAnnotation as CPDFListBoxWidget);
  442. break;
  443. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  444. annotParam = GetSignatureParam(cPDFAnnotation as CPDFSignatureWidget);
  445. break;
  446. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  447. break;
  448. default:
  449. break;
  450. }
  451. }
  452. return annotParam;
  453. }
  454. internal static PushButtonParam GetPushButtonParam(CPDFDocument document, CPDFPushButtonWidget cPDFWidget)
  455. {
  456. PushButtonParam pushButtonParam = null;
  457. if (cPDFWidget != null && cPDFWidget.IsValid())
  458. {
  459. pushButtonParam = new PushButtonParam();
  460. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  461. pushButtonParam.IsBold = IsBold(cTextAttribute.FontName);
  462. pushButtonParam.IsItalic = IsItalic(cTextAttribute.FontName);
  463. pushButtonParam.Text = cPDFWidget.GetButtonTitle();
  464. pushButtonParam.FontColor = cTextAttribute.FontColor;
  465. pushButtonParam.FontName = cTextAttribute.FontName;
  466. pushButtonParam.FontSize = cTextAttribute.FontSize;
  467. CPDFAction cPDFAction = cPDFWidget.GetButtonAction();
  468. if (cPDFAction != null)
  469. {
  470. switch (cPDFAction.ActionType)
  471. {
  472. case C_ACTION_TYPE.ACTION_TYPE_URI:
  473. pushButtonParam.Uri = (cPDFAction as CPDFUriAction)?.GetUri();
  474. break;
  475. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  476. CPDFGoToAction gotoAction = cPDFAction as CPDFGoToAction;
  477. CPDFDestination dest = gotoAction.GetDestination(document);
  478. pushButtonParam.DestinationPageIndex = dest.PageIndex;
  479. pushButtonParam.DestinationPosition = new CPoint(dest.Position_X, dest.Position_Y);
  480. break;
  481. default:
  482. break;
  483. }
  484. pushButtonParam.Action = cPDFAction.ActionType;
  485. }
  486. pushButtonParam.WidgetType = cPDFWidget.WidgetType;
  487. pushButtonParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  488. byte[] LineColor = new byte[3];
  489. pushButtonParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  490. pushButtonParam.LineColor = LineColor;
  491. byte[] BgColor = new byte[3];
  492. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  493. pushButtonParam.HasBgColor = hasBgColor;
  494. pushButtonParam.BgColor = BgColor;
  495. pushButtonParam.LineWidth = cPDFWidget.GetBorderWidth();
  496. pushButtonParam.FieldName = cPDFWidget.GetFieldName();
  497. pushButtonParam.Flags = cPDFWidget.GetFlags();
  498. pushButtonParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  499. pushButtonParam.IsHidden = cPDFWidget.GetIsHidden();
  500. GetAnnotCommonParam(cPDFWidget, pushButtonParam);
  501. }
  502. return pushButtonParam;
  503. }
  504. internal static CheckBoxParam GetCheckBoxParam(CPDFCheckBoxWidget cPDFWidget)
  505. {
  506. CheckBoxParam checkBoxParam = null;
  507. if (cPDFWidget != null && cPDFWidget.IsValid())
  508. {
  509. checkBoxParam = new CheckBoxParam();
  510. checkBoxParam.CheckStyle = cPDFWidget.GetWidgetCheckStyle();
  511. checkBoxParam.IsChecked = cPDFWidget.IsChecked();
  512. checkBoxParam.WidgetType = cPDFWidget.WidgetType;
  513. checkBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  514. byte[] LineColor = new byte[3];
  515. checkBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  516. checkBoxParam.LineColor = LineColor;
  517. byte[] BgColor = new byte[3];
  518. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  519. checkBoxParam.HasBgColor = hasBgColor;
  520. checkBoxParam.BgColor = BgColor;
  521. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  522. checkBoxParam.FontColor = cTextAttribute.FontColor;
  523. checkBoxParam.FontName = cTextAttribute.FontName;
  524. checkBoxParam.FontSize = cTextAttribute.FontSize;
  525. checkBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  526. checkBoxParam.FieldName = cPDFWidget.GetFieldName();
  527. checkBoxParam.Flags = cPDFWidget.GetFlags();
  528. checkBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  529. checkBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  530. GetAnnotCommonParam(cPDFWidget, checkBoxParam);
  531. }
  532. return checkBoxParam;
  533. }
  534. internal static RadioButtonParam GetRadioButtonParam(CPDFRadioButtonWidget cPDFWidget)
  535. {
  536. RadioButtonParam radioButtonParam = null;
  537. if (cPDFWidget != null && cPDFWidget.IsValid())
  538. {
  539. radioButtonParam = new RadioButtonParam();
  540. radioButtonParam.CheckStyle = cPDFWidget.GetWidgetCheckStyle();
  541. radioButtonParam.IsChecked = cPDFWidget.IsChecked();
  542. radioButtonParam.WidgetType = cPDFWidget.WidgetType;
  543. radioButtonParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  544. byte[] LineColor = new byte[3];
  545. radioButtonParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  546. radioButtonParam.LineColor = LineColor;
  547. byte[] BgColor = new byte[3];
  548. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  549. radioButtonParam.HasBgColor = hasBgColor;
  550. radioButtonParam.BgColor = BgColor;
  551. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  552. radioButtonParam.FontColor = cTextAttribute.FontColor;
  553. radioButtonParam.FontName = cTextAttribute.FontName;
  554. radioButtonParam.FontSize = cTextAttribute.FontSize;
  555. radioButtonParam.LineWidth = cPDFWidget.GetBorderWidth();
  556. radioButtonParam.FieldName = cPDFWidget.GetFieldName();
  557. radioButtonParam.Flags = cPDFWidget.GetFlags();
  558. radioButtonParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  559. radioButtonParam.IsHidden = cPDFWidget.GetIsHidden();
  560. GetAnnotCommonParam(cPDFWidget, radioButtonParam);
  561. }
  562. return radioButtonParam;
  563. }
  564. internal static TextBoxParam GetTextBoxParam(CPDFTextWidget cPDFWidget)
  565. {
  566. TextBoxParam textBoxParam = null;
  567. if (cPDFWidget != null && cPDFWidget.IsValid())
  568. {
  569. textBoxParam = new TextBoxParam();
  570. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  571. textBoxParam.Text = cPDFWidget.Text;
  572. textBoxParam.IsMultiLine = cPDFWidget.IsMultiLine;
  573. textBoxParam.IsPassword = cPDFWidget.IsPassword;
  574. textBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  575. textBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  576. textBoxParam.Alignment = cPDFWidget.Alignment;
  577. textBoxParam.WidgetType = cPDFWidget.WidgetType;
  578. textBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  579. byte[] LineColor = new byte[3];
  580. textBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  581. textBoxParam.LineColor = LineColor;
  582. byte[] BgColor = new byte[3];
  583. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  584. textBoxParam.HasBgColor = hasBgColor;
  585. textBoxParam.BgColor = BgColor;
  586. textBoxParam.FontColor = cTextAttribute.FontColor;
  587. textBoxParam.FontName = cTextAttribute.FontName;
  588. textBoxParam.FontSize = cTextAttribute.FontSize;
  589. textBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  590. textBoxParam.FieldName = cPDFWidget.GetFieldName();
  591. textBoxParam.Flags = cPDFWidget.GetFlags();
  592. textBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  593. textBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  594. GetAnnotCommonParam(cPDFWidget, textBoxParam);
  595. }
  596. return textBoxParam;
  597. }
  598. internal static ComboBoxParam GetComboBoxParam(CPDFComboBoxWidget cPDFWidget)
  599. {
  600. ComboBoxParam comboBoxParam = null;
  601. if (cPDFWidget != null && cPDFWidget.IsValid())
  602. {
  603. comboBoxParam = new ComboBoxParam();
  604. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  605. comboBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  606. comboBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  607. //Support for multiple selections needs to be adjusted later.
  608. CWidgetItem[] cWidgetItem = cPDFWidget.LoadWidgetItems();
  609. CWidgetItem cWidgetItem1 = cPDFWidget.GetSelectedItem();
  610. if (cWidgetItem != null)
  611. {
  612. for (int i = 0; i < cWidgetItem.Length; i++)
  613. {
  614. CWidgetItem item = cWidgetItem[i];
  615. comboBoxParam.OptionItems.Add(item.Value, item.Text);
  616. if (cWidgetItem1 != null && cWidgetItem1.Text == item.Text && cWidgetItem1.Value == item.Value)
  617. {
  618. comboBoxParam.SelectItemsIndex = new List<int> { i };
  619. }
  620. }
  621. }
  622. comboBoxParam.WidgetType = cPDFWidget.WidgetType;
  623. comboBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  624. byte[] LineColor = new byte[3];
  625. comboBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  626. comboBoxParam.LineColor = LineColor;
  627. byte[] BgColor = new byte[3];
  628. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  629. comboBoxParam.HasBgColor = hasBgColor;
  630. comboBoxParam.BgColor = BgColor;
  631. comboBoxParam.FontColor = cTextAttribute.FontColor;
  632. comboBoxParam.FontName = cTextAttribute.FontName;
  633. comboBoxParam.FontSize = cTextAttribute.FontSize;
  634. comboBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  635. comboBoxParam.FieldName = cPDFWidget.GetFieldName();
  636. comboBoxParam.Flags = cPDFWidget.GetFlags();
  637. comboBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  638. comboBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  639. GetAnnotCommonParam(cPDFWidget, comboBoxParam);
  640. }
  641. return comboBoxParam;
  642. }
  643. internal static ListBoxParam GetListBoxParam(CPDFListBoxWidget cPDFWidget)
  644. {
  645. ListBoxParam listBoxParam = null;
  646. if (cPDFWidget != null && cPDFWidget.IsValid())
  647. {
  648. listBoxParam = new ListBoxParam();
  649. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  650. listBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  651. listBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  652. CWidgetItem[] cWidgetItem = cPDFWidget.LoadWidgetItems();
  653. //Support for multiple selections needs to be adjusted later.
  654. CWidgetItem cWidgetItem1 = cPDFWidget.GetSelectedItem();
  655. if (cWidgetItem != null)
  656. {
  657. for (int i = 0; i < cWidgetItem.Length; i++)
  658. {
  659. CWidgetItem item = cWidgetItem[i];
  660. listBoxParam.OptionItems.Add(item.Value, item.Text);
  661. if (cWidgetItem1 != null && cWidgetItem1.Text == item.Text && cWidgetItem1.Value == item.Value)
  662. {
  663. listBoxParam.SelectItemsIndex = new List<int> { i };
  664. }
  665. }
  666. }
  667. listBoxParam.WidgetType = cPDFWidget.WidgetType;
  668. listBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  669. byte[] LineColor = new byte[3];
  670. listBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  671. listBoxParam.LineColor = LineColor;
  672. byte[] BgColor = new byte[3];
  673. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  674. listBoxParam.HasBgColor = hasBgColor;
  675. listBoxParam.BgColor = BgColor;
  676. listBoxParam.FontColor = cTextAttribute.FontColor;
  677. listBoxParam.FontName = cTextAttribute.FontName;
  678. listBoxParam.FontSize = cTextAttribute.FontSize;
  679. listBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  680. listBoxParam.FieldName = cPDFWidget.GetFieldName();
  681. listBoxParam.Flags = cPDFWidget.GetFlags();
  682. listBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  683. listBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  684. GetAnnotCommonParam(cPDFWidget, listBoxParam);
  685. }
  686. return listBoxParam;
  687. }
  688. internal static SignatureParam GetSignatureParam(CPDFSignatureWidget cPDFWidget)
  689. {
  690. SignatureParam signatureParam = null;
  691. if (cPDFWidget != null && cPDFWidget.IsValid())
  692. {
  693. signatureParam = new SignatureParam();
  694. signatureParam.WidgetType = cPDFWidget.WidgetType;
  695. signatureParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  696. byte[] LineColor = new byte[3];
  697. signatureParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  698. signatureParam.LineColor = LineColor;
  699. byte[] BgColor = new byte[3];
  700. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  701. signatureParam.HasBgColor = hasBgColor;
  702. signatureParam.BgColor = BgColor;
  703. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  704. signatureParam.FontColor = cTextAttribute.FontColor;
  705. signatureParam.FontName = cTextAttribute.FontName;
  706. signatureParam.FontSize = cTextAttribute.FontSize;
  707. signatureParam.LineWidth = cPDFWidget.GetBorderWidth();
  708. signatureParam.FieldName = cPDFWidget.GetFieldName();
  709. signatureParam.Flags = cPDFWidget.GetFlags();
  710. signatureParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  711. signatureParam.IsHidden = cPDFWidget.GetIsHidden();
  712. GetAnnotCommonParam(cPDFWidget, signatureParam);
  713. }
  714. return signatureParam;
  715. }
  716. #endregion
  717. #region Annot
  718. internal static AnnotParam MeasureAnnotConverter(CPDFAnnotation pdfAnnot)
  719. {
  720. if (pdfAnnot == null || pdfAnnot.IsValid() == false)
  721. {
  722. return null;
  723. }
  724. switch (pdfAnnot.Type)
  725. {
  726. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  727. {
  728. CPDFLineAnnotation lineAnnot = pdfAnnot as CPDFLineAnnotation;
  729. if (lineAnnot != null)
  730. {
  731. return GetLineMeasureParam(lineAnnot);
  732. }
  733. }
  734. break;
  735. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  736. {
  737. CPDFPolylineAnnotation polylineAnnot = pdfAnnot as CPDFPolylineAnnotation;
  738. if (polylineAnnot != null)
  739. {
  740. return GetPolylineParam(polylineAnnot);
  741. }
  742. }
  743. break;
  744. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  745. {
  746. CPDFPolygonAnnotation polygonAnnot = pdfAnnot as CPDFPolygonAnnotation;
  747. if (polygonAnnot != null)
  748. {
  749. return GetPolygonParam(polygonAnnot);
  750. }
  751. }
  752. break;
  753. }
  754. return null;
  755. }
  756. internal static AnnotParam AnnotConverter(CPDFDocument pdfDoc, CPDFAnnotation pdfAnnot)
  757. {
  758. if (pdfAnnot == null || pdfAnnot.IsValid() == false)
  759. {
  760. return null;
  761. }
  762. switch (pdfAnnot.Type)
  763. {
  764. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  765. {
  766. CPDFSquareAnnotation squareAnnot = pdfAnnot as CPDFSquareAnnotation;
  767. if (squareAnnot != null)
  768. {
  769. return GetSquareParam(squareAnnot);
  770. }
  771. }
  772. break;
  773. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  774. {
  775. CPDFCircleAnnotation circleAnnot = pdfAnnot as CPDFCircleAnnotation;
  776. if (circleAnnot != null)
  777. {
  778. return GetCircleParam(circleAnnot);
  779. }
  780. }
  781. break;
  782. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  783. {
  784. CPDFLineAnnotation lineAnnot = pdfAnnot as CPDFLineAnnotation;
  785. if (lineAnnot != null)
  786. {
  787. if(lineAnnot.IsMeasured())
  788. {
  789. return GetLineMeasureParam(lineAnnot);
  790. }
  791. return GetLineParam(lineAnnot);
  792. }
  793. }
  794. break;
  795. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  796. {
  797. CPDFInkAnnotation inkAnnot = pdfAnnot as CPDFInkAnnotation;
  798. if (inkAnnot != null)
  799. {
  800. return GetInkParam(inkAnnot);
  801. }
  802. }
  803. break;
  804. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  805. {
  806. CPDFFreeTextAnnotation freetextAnnot = pdfAnnot as CPDFFreeTextAnnotation;
  807. if (freetextAnnot != null)
  808. {
  809. return GetFreeTextParam(freetextAnnot);
  810. }
  811. }
  812. break;
  813. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  814. {
  815. CPDFHighlightAnnotation highlightAnnot = pdfAnnot as CPDFHighlightAnnotation;
  816. if (highlightAnnot != null)
  817. {
  818. return GetHighlightParam(highlightAnnot);
  819. }
  820. }
  821. break;
  822. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  823. {
  824. CPDFUnderlineAnnotation underlineAnnot = pdfAnnot as CPDFUnderlineAnnotation;
  825. if (underlineAnnot != null)
  826. {
  827. return GetUnderlineParam(underlineAnnot);
  828. }
  829. }
  830. break;
  831. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  832. {
  833. CPDFStrikeoutAnnotation strikeoutAnnot = pdfAnnot as CPDFStrikeoutAnnotation;
  834. if (strikeoutAnnot != null)
  835. {
  836. return GetStrikeoutParam(strikeoutAnnot);
  837. }
  838. }
  839. break;
  840. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  841. {
  842. CPDFSquigglyAnnotation squigglyAnnot = pdfAnnot as CPDFSquigglyAnnotation;
  843. if (squigglyAnnot != null)
  844. {
  845. return GetSquigglyParam(squigglyAnnot);
  846. }
  847. }
  848. break;
  849. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  850. {
  851. CPDFTextAnnotation stickyAnnot = pdfAnnot as CPDFTextAnnotation;
  852. if (stickyAnnot != null)
  853. {
  854. return GetStickynoteParam(stickyAnnot);
  855. }
  856. }
  857. break;
  858. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  859. {
  860. CPDFStampAnnotation stampAnnot = pdfAnnot as CPDFStampAnnotation;
  861. if (stampAnnot != null)
  862. {
  863. return GetStampParam(stampAnnot);
  864. }
  865. }
  866. break;
  867. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  868. {
  869. CPDFLinkAnnotation linkAnnot = pdfAnnot as CPDFLinkAnnotation;
  870. if (linkAnnot != null)
  871. {
  872. return GetLinkParam(linkAnnot, pdfDoc);
  873. }
  874. }
  875. break;
  876. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  877. {
  878. CPDFSoundAnnotation soundAnnot = pdfAnnot as CPDFSoundAnnotation;
  879. if (soundAnnot != null)
  880. {
  881. return GetSoundParam(soundAnnot);
  882. }
  883. }
  884. break;
  885. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  886. {
  887. CPDFRedactAnnotation redactAnnot= pdfAnnot as CPDFRedactAnnotation;
  888. if(redactAnnot != null)
  889. {
  890. return GetRedactParam(redactAnnot);
  891. }
  892. }
  893. break;
  894. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  895. {
  896. CPDFPolylineAnnotation polylineAnnot= pdfAnnot as CPDFPolylineAnnotation;
  897. if (polylineAnnot!=null && polylineAnnot.IsMeasured())
  898. {
  899. return GetPolyLineMeasureParam(polylineAnnot);
  900. }
  901. }
  902. break;
  903. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  904. {
  905. CPDFPolygonAnnotation polygonAnnot= pdfAnnot as CPDFPolygonAnnotation;
  906. if(polygonAnnot!=null)
  907. {
  908. return GetPolygonMeasureParam(polygonAnnot);
  909. }
  910. }
  911. break;
  912. default:
  913. break;
  914. }
  915. return null;
  916. }
  917. internal static void GetAnnotCommonParam(CPDFAnnotation pdfAnnot, AnnotParam annotParam)
  918. {
  919. if (pdfAnnot == null || annotParam == null || !pdfAnnot.IsValid())
  920. {
  921. return;
  922. }
  923. annotParam.CurrentType = pdfAnnot.Type;
  924. annotParam.Author = pdfAnnot.GetAuthor();
  925. annotParam.Transparency = pdfAnnot.GetTransparency();
  926. annotParam.Content = pdfAnnot.GetContent();
  927. annotParam.UpdateTime = pdfAnnot.GetModifyDate();
  928. annotParam.CreateTime = pdfAnnot.GetCreationDate();
  929. annotParam.Locked = pdfAnnot.GetIsLocked();
  930. annotParam.ClientRect = pdfAnnot.GetRect();
  931. annotParam.AnnotIndex = pdfAnnot.Page.GetAnnotations().IndexOf(pdfAnnot);
  932. //Annotation object exists, but the list cannot be found, it can only be a newly created annotation object.
  933. if (annotParam.AnnotIndex == -1)
  934. {
  935. annotParam.AnnotIndex = pdfAnnot.Page.GetAnnotCount() - 1;
  936. }
  937. annotParam.PageIndex = pdfAnnot.Page.PageIndex;
  938. }
  939. internal static SquareParam GetSquareParam(CPDFSquareAnnotation squareAnnot)
  940. {
  941. if (squareAnnot == null || squareAnnot.IsValid() == false)
  942. {
  943. return null;
  944. }
  945. SquareParam squareParam = new SquareParam();
  946. if (squareAnnot.LineColor != null && squareAnnot.LineColor.Length == 3)
  947. {
  948. squareParam.LineColor = new byte[3]
  949. {
  950. squareAnnot.LineColor[0],
  951. squareAnnot.LineColor[1],
  952. squareAnnot.LineColor[2]
  953. };
  954. }
  955. if (squareAnnot.HasBgColor && squareAnnot.BgColor != null)
  956. {
  957. if (squareAnnot.BgColor.Length == 3)
  958. {
  959. squareParam.HasBgColor = true;
  960. squareParam.BgColor = new byte[3]
  961. {
  962. squareAnnot.BgColor[0],
  963. squareAnnot.BgColor[1],
  964. squareAnnot.BgColor[2]
  965. };
  966. }
  967. }
  968. squareParam.LineWidth = squareAnnot.LineWidth;
  969. squareParam.BorderStyle = squareAnnot.BorderStyle;
  970. if (squareAnnot.Dash != null && squareAnnot.Dash.Length > 0)
  971. {
  972. squareParam.LineDash = new float[squareAnnot.Dash.Length];
  973. squareAnnot.Dash.CopyTo(squareParam.LineDash, 0);
  974. }
  975. GetAnnotCommonParam(squareAnnot, squareParam);
  976. return squareParam;
  977. }
  978. internal static CircleParam GetCircleParam(CPDFCircleAnnotation circleAnnot)
  979. {
  980. if (circleAnnot == null || circleAnnot.IsValid() == false)
  981. {
  982. return null;
  983. }
  984. CircleParam circleParam = new CircleParam();
  985. if (circleAnnot.LineColor != null && circleAnnot.LineColor.Length == 3)
  986. {
  987. circleParam.LineColor = new byte[3]
  988. {
  989. circleAnnot.LineColor[0],
  990. circleAnnot.LineColor[1],
  991. circleAnnot.LineColor[2]
  992. };
  993. }
  994. if (circleAnnot.HasBgColor && circleAnnot.BgColor != null)
  995. {
  996. if (circleAnnot.BgColor.Length == 3)
  997. {
  998. circleParam.HasBgColor = true;
  999. circleParam.BgColor = new byte[3]
  1000. {
  1001. circleAnnot.BgColor[0],
  1002. circleAnnot.BgColor[1],
  1003. circleAnnot.BgColor[2]
  1004. };
  1005. }
  1006. }
  1007. circleParam.LineWidth = circleAnnot.LineWidth;
  1008. circleParam.BorderStyle = circleAnnot.BorderStyle;
  1009. if (circleAnnot.Dash != null && circleAnnot.Dash.Length > 0)
  1010. {
  1011. circleParam.LineDash = new float[circleAnnot.Dash.Length];
  1012. circleAnnot.Dash.CopyTo(circleParam.LineDash, 0);
  1013. }
  1014. GetAnnotCommonParam(circleAnnot, circleParam);
  1015. return circleParam;
  1016. }
  1017. private static AnnotParam GetPolylineParam(CPDFPolylineAnnotation polylineAnnot)
  1018. {
  1019. if (polylineAnnot == null || polylineAnnot.IsValid() == false)
  1020. {
  1021. return null;
  1022. }
  1023. PolyLineMeasureParam polylineParam = new PolyLineMeasureParam();
  1024. if (polylineAnnot.LineColor != null && polylineAnnot.LineColor.Length == 3)
  1025. {
  1026. polylineParam.LineColor = new byte[3]
  1027. {
  1028. polylineAnnot.LineColor[0],
  1029. polylineAnnot.LineColor[1],
  1030. polylineAnnot.LineColor[2]
  1031. };
  1032. }
  1033. polylineParam.LineWidth = polylineAnnot.LineWidth;
  1034. polylineParam.BorderStyle = polylineAnnot.BorderStyle;
  1035. if (polylineAnnot.Dash != null && polylineAnnot.Dash.Length > 0)
  1036. {
  1037. polylineParam.LineDash = new float[polylineAnnot.Dash.Length];
  1038. polylineAnnot.Dash.CopyTo(polylineParam.LineDash, 0);
  1039. }
  1040. if (polylineAnnot.Points != null && polylineAnnot.Points.Count > 0)
  1041. {
  1042. polylineParam.SavePoints = new List<CPoint>();
  1043. foreach (CPoint point in polylineAnnot.Points)
  1044. {
  1045. polylineParam.SavePoints.Add(point);
  1046. }
  1047. }
  1048. CTextAttribute cTextAttribute = polylineAnnot.GetTextAttribute();
  1049. polylineParam.FontName = cTextAttribute.FontName;
  1050. polylineParam.FontSize = cTextAttribute.FontSize;
  1051. polylineParam.FontColor = cTextAttribute.FontColor;
  1052. GetAnnotCommonParam(polylineAnnot, polylineParam);
  1053. return polylineParam;
  1054. }
  1055. private static AnnotParam GetPolygonParam(CPDFPolygonAnnotation polygonAnnot)
  1056. {
  1057. if (polygonAnnot == null || polygonAnnot.IsValid() == false)
  1058. {
  1059. return null;
  1060. }
  1061. PolygonMeasureParam polygonParam = new PolygonMeasureParam();
  1062. if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
  1063. {
  1064. polygonParam.LineColor = new byte[3]
  1065. {
  1066. polygonAnnot.LineColor[0],
  1067. polygonAnnot.LineColor[1],
  1068. polygonAnnot.LineColor[2]
  1069. };
  1070. }
  1071. if(polygonAnnot.HasBgColor && polygonAnnot.BgColor != null)
  1072. {
  1073. polygonParam.HasFillColor = true;
  1074. polygonParam.FillColor = new byte[3]
  1075. {
  1076. polygonAnnot.BgColor[0],
  1077. polygonAnnot.BgColor[1],
  1078. polygonAnnot.BgColor[2]
  1079. };
  1080. }
  1081. polygonParam.LineWidth = polygonAnnot.LineWidth;
  1082. polygonParam.BorderStyle = polygonAnnot.BorderStyle;
  1083. if (polygonAnnot.Dash != null && polygonAnnot.Dash.Length > 0)
  1084. {
  1085. polygonParam.LineDash = new float[polygonAnnot.Dash.Length];
  1086. polygonAnnot.Dash.CopyTo(polygonParam.LineDash, 0);
  1087. }
  1088. if (polygonAnnot.Points != null && polygonAnnot.Points.Count > 0)
  1089. {
  1090. polygonParam.SavePoints = new List<CPoint>();
  1091. foreach (CPoint point in polygonAnnot.Points)
  1092. {
  1093. polygonParam.SavePoints.Add(point);
  1094. }
  1095. }
  1096. CTextAttribute cTextAttribute = polygonAnnot.GetTextAttribute();
  1097. polygonParam.FontName = cTextAttribute.FontName;
  1098. polygonParam.FontSize = cTextAttribute.FontSize;
  1099. polygonParam.FontColor = cTextAttribute.FontColor;
  1100. GetAnnotCommonParam(polygonAnnot, polygonParam);
  1101. return polygonParam;
  1102. }
  1103. internal static LineParam GetLineParam(CPDFLineAnnotation lineAnnot)
  1104. {
  1105. if (lineAnnot == null || lineAnnot.IsValid() == false)
  1106. {
  1107. return null;
  1108. }
  1109. LineParam lineParam = new LineParam();
  1110. if (lineAnnot.LineColor != null && lineAnnot.LineColor.Length == 3)
  1111. {
  1112. lineParam.LineColor = new byte[3]
  1113. {
  1114. lineAnnot.LineColor[0],
  1115. lineAnnot.LineColor[1],
  1116. lineAnnot.LineColor[2]
  1117. };
  1118. }
  1119. if (lineAnnot.HasBgColor && lineAnnot.BgColor != null)
  1120. {
  1121. if (lineAnnot.BgColor.Length == 3)
  1122. {
  1123. lineParam.HasBgColor = true;
  1124. lineParam.BgColor = new byte[3]
  1125. {
  1126. lineAnnot.BgColor[0],
  1127. lineAnnot.BgColor[1],
  1128. lineAnnot.BgColor[2]
  1129. };
  1130. }
  1131. }
  1132. lineParam.LineWidth = lineAnnot.LineWidth;
  1133. lineParam.BorderStyle = lineAnnot.BorderStyle;
  1134. if (lineAnnot.Dash != null && lineAnnot.Dash.Length > 0)
  1135. {
  1136. lineParam.LineDash = new float[lineAnnot.Dash.Length];
  1137. lineAnnot.Dash.CopyTo(lineParam.LineDash, 0);
  1138. }
  1139. lineParam.HeadLineType = lineAnnot.HeadLineType;
  1140. lineParam.TailLineType = lineAnnot.TailLineType;
  1141. if (lineAnnot.Points != null && lineAnnot.Points.Length == 2)
  1142. {
  1143. lineParam.HeadPoint = lineAnnot.Points[0];
  1144. lineParam.TailPoint = lineAnnot.Points[1];
  1145. }
  1146. GetAnnotCommonParam(lineAnnot, lineParam);
  1147. return lineParam;
  1148. }
  1149. internal static LineMeasureParam GetLineMeasureParam(CPDFLineAnnotation lineAnnot)
  1150. {
  1151. if (lineAnnot == null || lineAnnot.IsValid() == false || lineAnnot.IsMeasured()==false)
  1152. {
  1153. return null;
  1154. }
  1155. LineMeasureParam measureParam = new LineMeasureParam();
  1156. CPDFDistanceMeasure distanceMeasure = lineAnnot.GetDistanceMeasure();
  1157. measureParam.measureInfo = distanceMeasure.MeasureInfo;
  1158. if (lineAnnot.LineColor != null && lineAnnot.LineColor.Length == 3)
  1159. {
  1160. measureParam.LineColor = new byte[3] { lineAnnot.LineColor[0], lineAnnot.LineColor[1], lineAnnot.LineColor[2] };
  1161. }
  1162. measureParam.BorderStyle = lineAnnot.BorderStyle;
  1163. measureParam.LineWidth = lineAnnot.LineWidth;
  1164. measureParam.Transparency = lineAnnot.Transparency;
  1165. measureParam.LineDash = lineAnnot.Dash;
  1166. CTextAttribute textAttr = lineAnnot.GetTextAttribute();
  1167. measureParam.FontName = textAttr.FontName;
  1168. measureParam.FontSize = textAttr.FontSize;
  1169. if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
  1170. {
  1171. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1172. }
  1173. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1174. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1175. measureParam.HeadLineType=lineAnnot.HeadLineType;
  1176. measureParam.TailLineType=lineAnnot.TailLineType;
  1177. measureParam.HeadPoint = lineAnnot.Points[0];
  1178. measureParam.TailPoint = lineAnnot.Points[1];
  1179. GetAnnotCommonParam(lineAnnot, measureParam);
  1180. return measureParam;
  1181. }
  1182. internal static InkParam GetInkParam(CPDFInkAnnotation inkAnnot)
  1183. {
  1184. if (inkAnnot == null || inkAnnot.IsValid() == false)
  1185. {
  1186. return null;
  1187. }
  1188. InkParam inkParam = new InkParam();
  1189. inkParam.Thickness = inkAnnot.Thickness;
  1190. if (inkAnnot.InkColor != null && inkAnnot.InkColor.Length == 3)
  1191. {
  1192. inkParam.InkColor = new byte[3]
  1193. {
  1194. inkAnnot.InkColor[0],
  1195. inkAnnot.InkColor[1],
  1196. inkAnnot.InkColor[2]
  1197. };
  1198. }
  1199. if (inkAnnot.InkPath != null && inkAnnot.InkPath.Count > 0)
  1200. {
  1201. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  1202. foreach (List<CPoint> copyList in inkAnnot.InkPath)
  1203. {
  1204. if (copyList.Count == 0)
  1205. {
  1206. continue;
  1207. }
  1208. List<CPoint> saveList = new List<CPoint>();
  1209. foreach (CPoint item in copyList)
  1210. {
  1211. saveList.Add(item);
  1212. }
  1213. if (saveList.Count > 0)
  1214. {
  1215. inkPath.Add(saveList);
  1216. }
  1217. }
  1218. if (inkPath.Count > 0)
  1219. {
  1220. inkParam.InkPath = inkPath;
  1221. }
  1222. }
  1223. if(inkAnnot.Dash!=null && inkAnnot.Dash.Length>0)
  1224. {
  1225. inkParam.Dash =new float[inkAnnot.Dash.Length];
  1226. inkAnnot.Dash.CopyTo(inkParam.Dash, 0);
  1227. }
  1228. GetAnnotCommonParam(inkAnnot, inkParam);
  1229. return inkParam;
  1230. }
  1231. internal static FreeTextParam GetFreeTextParam(CPDFFreeTextAnnotation freetextAnnot)
  1232. {
  1233. if (freetextAnnot == null || freetextAnnot.IsValid() == false)
  1234. {
  1235. return null;
  1236. }
  1237. FreeTextParam freetextParam = new FreeTextParam();
  1238. if (freetextAnnot.LineColor != null && freetextAnnot.LineColor.Length == 3)
  1239. {
  1240. freetextParam.LineColor = new byte[3]
  1241. {
  1242. freetextAnnot.LineColor[0],
  1243. freetextAnnot.LineColor[1],
  1244. freetextAnnot.LineColor[2]
  1245. };
  1246. }
  1247. if (freetextAnnot.HasBgColor && freetextAnnot.BgColor != null)
  1248. {
  1249. if (freetextAnnot.BgColor.Length == 3)
  1250. {
  1251. freetextParam.HasBgColor = true;
  1252. freetextParam.BgColor = new byte[3]
  1253. {
  1254. freetextAnnot.BgColor[0],
  1255. freetextAnnot.BgColor[1],
  1256. freetextAnnot.BgColor[2]
  1257. };
  1258. }
  1259. }
  1260. freetextParam.LineWidth = freetextAnnot.LineWidth;
  1261. if (freetextAnnot.FreeTextDa != null)
  1262. {
  1263. byte[] fontColor = freetextAnnot.FreeTextDa.FontColor;
  1264. if (fontColor != null && fontColor.Length == 3)
  1265. {
  1266. freetextParam.FontColor = new byte[3]
  1267. {
  1268. fontColor[0],
  1269. fontColor[1],
  1270. fontColor[2]
  1271. };
  1272. }
  1273. string fontName = freetextAnnot.FreeTextDa.FontName;
  1274. if (!string.IsNullOrEmpty(fontName))
  1275. {
  1276. freetextParam.FontName = fontName;
  1277. freetextParam.IsBold = IsBold(fontName);
  1278. freetextParam.IsItalic = IsItalic(fontName);
  1279. }
  1280. freetextParam.FontSize = freetextAnnot.FreeTextDa.FontSize;
  1281. freetextParam.Alignment = freetextAnnot.Alignment;
  1282. }
  1283. if (freetextAnnot.Dash != null && freetextAnnot.Dash.Length > 0)
  1284. {
  1285. freetextParam.Dash = new float[freetextAnnot.Dash.Length];
  1286. freetextAnnot.Dash.CopyTo(freetextParam.Dash, 0);
  1287. }
  1288. GetAnnotCommonParam(freetextAnnot, freetextParam);
  1289. return freetextParam;
  1290. }
  1291. internal static HighlightParam GetHighlightParam(CPDFHighlightAnnotation highlightAnnot)
  1292. {
  1293. if (highlightAnnot == null || highlightAnnot.IsValid() == false)
  1294. {
  1295. return null;
  1296. }
  1297. HighlightParam highlightParam = new HighlightParam();
  1298. if (highlightAnnot.Color != null && highlightAnnot.Color.Length == 3)
  1299. {
  1300. highlightParam.HighlightColor = new byte[3]
  1301. {
  1302. highlightAnnot.Color[0],
  1303. highlightAnnot.Color[1],
  1304. highlightAnnot.Color[2]
  1305. };
  1306. }
  1307. if (highlightAnnot.QuardRects != null && highlightAnnot.QuardRects.Count > 0)
  1308. {
  1309. List<CRect> saveList = new List<CRect>();
  1310. foreach (CRect saveRect in highlightAnnot.QuardRects)
  1311. {
  1312. saveList.Add(saveRect);
  1313. }
  1314. highlightParam.QuardRects = saveList;
  1315. }
  1316. GetAnnotCommonParam(highlightAnnot, highlightParam);
  1317. return highlightParam;
  1318. }
  1319. internal static UnderlineParam GetUnderlineParam(CPDFUnderlineAnnotation underlineAnnot)
  1320. {
  1321. if (underlineAnnot == null || underlineAnnot.IsValid() == false)
  1322. {
  1323. return null;
  1324. }
  1325. UnderlineParam underlineParam = new UnderlineParam();
  1326. if (underlineAnnot.Color != null && underlineAnnot.Color.Length == 3)
  1327. {
  1328. underlineParam.UnderlineColor = new byte[3]
  1329. {
  1330. underlineAnnot.Color[0],
  1331. underlineAnnot.Color[1],
  1332. underlineAnnot.Color[2]
  1333. };
  1334. }
  1335. if (underlineAnnot.QuardRects != null && underlineAnnot.QuardRects.Count > 0)
  1336. {
  1337. List<CRect> saveList = new List<CRect>();
  1338. foreach (CRect saveRect in underlineAnnot.QuardRects)
  1339. {
  1340. saveList.Add(saveRect);
  1341. }
  1342. underlineParam.QuardRects = saveList;
  1343. }
  1344. GetAnnotCommonParam(underlineAnnot, underlineParam);
  1345. return underlineParam;
  1346. }
  1347. internal static StrikeoutParam GetStrikeoutParam(CPDFStrikeoutAnnotation strikeoutAnnot)
  1348. {
  1349. if (strikeoutAnnot == null || strikeoutAnnot.IsValid() == false)
  1350. {
  1351. return null;
  1352. }
  1353. StrikeoutParam strikeoutParam = new StrikeoutParam();
  1354. if (strikeoutAnnot.Color != null && strikeoutAnnot.Color.Length == 3)
  1355. {
  1356. strikeoutParam.StrikeoutColor = new byte[3]
  1357. {
  1358. strikeoutAnnot.Color[0],
  1359. strikeoutAnnot.Color[1],
  1360. strikeoutAnnot.Color[2]
  1361. };
  1362. }
  1363. if (strikeoutAnnot.QuardRects != null && strikeoutAnnot.QuardRects.Count > 0)
  1364. {
  1365. List<CRect> saveList = new List<CRect>();
  1366. foreach (CRect saveRect in strikeoutAnnot.QuardRects)
  1367. {
  1368. saveList.Add(saveRect);
  1369. }
  1370. strikeoutParam.QuardRects = saveList;
  1371. }
  1372. GetAnnotCommonParam(strikeoutAnnot, strikeoutParam);
  1373. return strikeoutParam;
  1374. }
  1375. internal static SquigglyParam GetSquigglyParam(CPDFSquigglyAnnotation squigglyAnnot)
  1376. {
  1377. if (squigglyAnnot == null || squigglyAnnot.IsValid() == false)
  1378. {
  1379. return null;
  1380. }
  1381. SquigglyParam squigglyParam = new SquigglyParam();
  1382. if (squigglyAnnot.Color != null && squigglyAnnot.Color.Length == 3)
  1383. {
  1384. squigglyParam.SquigglyColor = new byte[3]
  1385. {
  1386. squigglyAnnot.Color[0],
  1387. squigglyAnnot.Color[1],
  1388. squigglyAnnot.Color[2]
  1389. };
  1390. }
  1391. if (squigglyAnnot.QuardRects != null && squigglyAnnot.QuardRects.Count > 0)
  1392. {
  1393. List<CRect> saveList = new List<CRect>();
  1394. foreach (CRect saveRect in squigglyAnnot.QuardRects)
  1395. {
  1396. saveList.Add(saveRect);
  1397. }
  1398. squigglyParam.QuardRects = saveList;
  1399. }
  1400. GetAnnotCommonParam(squigglyAnnot, squigglyParam);
  1401. return squigglyParam;
  1402. }
  1403. internal static StickyNoteParam GetStickynoteParam(CPDFTextAnnotation stickyAnnot)
  1404. {
  1405. if (stickyAnnot == null || stickyAnnot.IsValid() == false)
  1406. {
  1407. return null;
  1408. }
  1409. StickyNoteParam stickyParam = new StickyNoteParam();
  1410. if (stickyAnnot.Color != null && stickyAnnot.Color.Length == 3)
  1411. {
  1412. stickyParam.StickyNoteColor = new byte[3]
  1413. {
  1414. stickyAnnot.Color[0],
  1415. stickyAnnot.Color[1],
  1416. stickyAnnot.Color[2]
  1417. };
  1418. }
  1419. stickyParam.IconName=stickyAnnot.GetIconName();
  1420. GetAnnotCommonParam(stickyAnnot, stickyParam);
  1421. return stickyParam;
  1422. }
  1423. internal static StampParam GetStampParam(CPDFStampAnnotation stampAnnot)
  1424. {
  1425. if (stampAnnot == null || stampAnnot.IsValid() == false)
  1426. {
  1427. return null;
  1428. }
  1429. StampParam stampParam = new StampParam();
  1430. C_STAMP_TYPE stampType = stampAnnot.GetStampType();
  1431. switch (stampType)
  1432. {
  1433. case C_STAMP_TYPE.STANDARD_STAMP:
  1434. {
  1435. stampParam.StampText = stampAnnot.GetStandardStamp();
  1436. stampParam.StampType = stampType;
  1437. }
  1438. break;
  1439. case C_STAMP_TYPE.TEXT_STAMP:
  1440. {
  1441. string stampText = string.Empty;
  1442. string dateText = string.Empty;
  1443. C_TEXTSTAMP_SHAPE stampShape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_NONE;
  1444. C_TEXTSTAMP_COLOR stampColor = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE;
  1445. stampAnnot.GetTextStamp(ref stampText,
  1446. ref dateText,
  1447. ref stampShape,
  1448. ref stampColor);
  1449. stampParam.StampText = stampText;
  1450. stampParam.DateText = dateText;
  1451. stampParam.TextStampShape = stampShape;
  1452. stampParam.TextStampColor = stampColor;
  1453. stampParam.StampType = stampType;
  1454. }
  1455. break;
  1456. case C_STAMP_TYPE.IMAGE_STAMP:
  1457. case C_STAMP_TYPE.UNKNOWN_STAMP:
  1458. {
  1459. stampParam.StampType = stampType;
  1460. CRect rawRect = stampAnnot.GetRect();
  1461. int width = (int)(rawRect.width() / 72D * 96D);
  1462. int height = (int)(rawRect.height() / 72D * 96D);
  1463. if (width > 0 && height > 0)
  1464. {
  1465. Rect rotateRect = new Rect(0, 0, width, height);
  1466. Matrix rotateMatrix = new Matrix();
  1467. rotateMatrix.RotateAt(-90 * stampAnnot.Page.Rotation, width / 2, height / 2);
  1468. rotateRect.Transform(rotateMatrix);
  1469. int imageWidth = (int)rotateRect.Width;
  1470. int imageHeight = (int)rotateRect.Height;
  1471. byte[] ImageArray = new byte[imageWidth * imageHeight * 4];
  1472. stampAnnot.RenderAnnot(imageWidth, imageHeight, ImageArray);
  1473. WriteableBitmap writeBitmap = new WriteableBitmap(
  1474. imageWidth,
  1475. imageHeight,
  1476. 96,
  1477. 96,
  1478. PixelFormats.Bgra32,
  1479. null);
  1480. writeBitmap.WritePixels(new Int32Rect(0, 0, imageWidth, imageHeight), ImageArray, imageWidth * 4, 0);
  1481. PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
  1482. pngEncoder.Frames.Add(BitmapFrame.Create(writeBitmap));
  1483. MemoryStream memStream = new MemoryStream();
  1484. pngEncoder.Save(memStream);
  1485. stampParam.ImageStream = memStream;
  1486. }
  1487. }
  1488. break;
  1489. default:
  1490. return null;
  1491. }
  1492. stampParam.PageRotation = stampAnnot.Page.Rotation;
  1493. stampParam.Rotation = stampAnnot.AnnotationRotator.GetRotation();
  1494. CRect sourceRect = new CRect();
  1495. stampAnnot.GetSourceRect(ref sourceRect);
  1496. stampParam.SourceRect = sourceRect;
  1497. GetAnnotCommonParam(stampAnnot, stampParam);
  1498. return stampParam;
  1499. }
  1500. internal static LinkParam GetLinkParam(CPDFLinkAnnotation linkAnnot, CPDFDocument pdfDoc)
  1501. {
  1502. if (linkAnnot == null || linkAnnot.IsValid() == false)
  1503. {
  1504. return null;
  1505. }
  1506. LinkParam linkParam = new LinkParam();
  1507. CPDFAction linkAction = linkAnnot.GetLinkAction();
  1508. if (linkAction != null)
  1509. {
  1510. switch (linkAction.ActionType)
  1511. {
  1512. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  1513. {
  1514. CPDFGoToAction gotoAction = linkAction as CPDFGoToAction;
  1515. if (gotoAction != null && pdfDoc != null && pdfDoc.IsValid())
  1516. {
  1517. CPDFDestination dest = gotoAction.GetDestination(pdfDoc);
  1518. if (dest != null)
  1519. {
  1520. linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_GOTO;
  1521. linkParam.DestinationPageIndex = dest.PageIndex;
  1522. linkParam.DestinationPosition = new CPoint(dest.Position_X, dest.Position_Y);
  1523. }
  1524. }
  1525. }
  1526. break;
  1527. case C_ACTION_TYPE.ACTION_TYPE_URI:
  1528. {
  1529. CPDFUriAction urlAction = linkAction as CPDFUriAction;
  1530. if (urlAction != null)
  1531. {
  1532. linkParam.Uri = urlAction.GetUri();
  1533. linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_URI;
  1534. }
  1535. }
  1536. break;
  1537. default:
  1538. break;
  1539. }
  1540. }
  1541. GetAnnotCommonParam(linkAnnot, linkParam);
  1542. return linkParam;
  1543. }
  1544. internal static SoundParam GetSoundParam(CPDFSoundAnnotation stampAnnot)
  1545. {
  1546. if (stampAnnot == null || stampAnnot.IsValid() == false)
  1547. {
  1548. return null;
  1549. }
  1550. SoundParam soundParam = new SoundParam();
  1551. GetAnnotCommonParam(stampAnnot, soundParam);
  1552. return soundParam;
  1553. }
  1554. internal static RedactParam GetRedactParam(CPDFRedactAnnotation redactAnnot)
  1555. {
  1556. if(redactAnnot == null || redactAnnot.IsValid() == false)
  1557. {
  1558. return null;
  1559. }
  1560. RedactParam redactParam = new RedactParam();
  1561. if (redactAnnot.OutlineColor != null && redactAnnot.OutlineColor.Length == 3)
  1562. {
  1563. redactParam.LineColor = new byte[3] { redactAnnot.OutlineColor[0], redactAnnot.OutlineColor[1], redactAnnot.OutlineColor[2] };
  1564. }
  1565. if (redactAnnot.FillColor != null && redactAnnot.FillColor.Length == 3)
  1566. {
  1567. redactParam.BgColor = new byte[3] { redactAnnot.FillColor[0], redactAnnot.FillColor[1], redactAnnot.FillColor[2] };
  1568. }
  1569. if (redactAnnot.TextDa != null)
  1570. {
  1571. if (redactAnnot.TextDa.FontColor != null && redactAnnot.TextDa.FontColor.Length == 3)
  1572. {
  1573. redactParam.FontColor = new byte[3] { redactAnnot.TextDa.FontColor[0], redactAnnot.TextDa.FontColor[1], redactAnnot.TextDa.FontColor[2] };
  1574. }
  1575. redactParam.FontName= redactAnnot.TextDa.FontName;
  1576. redactParam.FontSize = redactAnnot.TextDa.FontSize;
  1577. redactParam.Alignment=redactAnnot.TextAlignment;
  1578. }
  1579. if(redactAnnot.QuardRects!=null)
  1580. {
  1581. redactParam.QuardRects = new List<CRect>(redactAnnot.QuardRects);
  1582. }
  1583. redactParam.OverlayText = redactAnnot.OverlayText;
  1584. GetAnnotCommonParam(redactAnnot, redactParam);
  1585. return redactParam;
  1586. }
  1587. internal static PolyLineMeasureParam GetPolyLineMeasureParam(CPDFPolylineAnnotation polylineAnnot)
  1588. {
  1589. if (polylineAnnot == null || polylineAnnot.IsValid() == false || polylineAnnot.IsMeasured()==false)
  1590. {
  1591. return null;
  1592. }
  1593. PolyLineMeasureParam measureParam = new PolyLineMeasureParam();
  1594. CPDFPerimeterMeasure perimeterMeasure = polylineAnnot.GetPerimeterMeasure();
  1595. measureParam.measureInfo= perimeterMeasure.MeasureInfo;
  1596. if (polylineAnnot.LineColor != null && polylineAnnot.LineColor.Length == 3)
  1597. {
  1598. measureParam.LineColor = new byte[3] { polylineAnnot.LineColor[0], polylineAnnot.LineColor[1], polylineAnnot.LineColor[2] };
  1599. }
  1600. measureParam.SavePoints = polylineAnnot.Points;
  1601. measureParam.BorderStyle = polylineAnnot.BorderStyle;
  1602. measureParam.LineWidth=polylineAnnot.LineWidth;
  1603. measureParam.Transparency=polylineAnnot.Transparency;
  1604. measureParam.LineDash=polylineAnnot.Dash;
  1605. CTextAttribute textAttr = polylineAnnot.GetTextAttribute();
  1606. measureParam.FontName = textAttr.FontName;
  1607. measureParam.FontSize = textAttr.FontSize;
  1608. if(textAttr.FontColor!=null && textAttr.FontColor.Length == 3)
  1609. {
  1610. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1611. }
  1612. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1613. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1614. GetAnnotCommonParam(polylineAnnot, measureParam);
  1615. return measureParam;
  1616. }
  1617. internal static PolygonMeasureParam GetPolygonMeasureParam(CPDFPolygonAnnotation polygonAnnot)
  1618. {
  1619. if (polygonAnnot == null || polygonAnnot.IsValid() == false)
  1620. {
  1621. return null;
  1622. }
  1623. PolygonMeasureParam measureParam = new PolygonMeasureParam();
  1624. if(polygonAnnot.IsMeasured())
  1625. {
  1626. CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
  1627. measureParam.measureInfo = areaMeasure.MeasureInfo;
  1628. CTextAttribute textAttr = polygonAnnot.GetTextAttribute();
  1629. measureParam.FontName = textAttr.FontName;
  1630. measureParam.FontSize = textAttr.FontSize;
  1631. if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
  1632. {
  1633. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1634. }
  1635. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1636. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1637. }
  1638. if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
  1639. {
  1640. measureParam.LineColor = new byte[] { polygonAnnot.LineColor[0], polygonAnnot.LineColor[1], polygonAnnot.LineColor[2] };
  1641. }
  1642. if(polygonAnnot.HasBgColor && polygonAnnot.BgColor!=null && polygonAnnot.BgColor.Length == 3)
  1643. {
  1644. measureParam.HasFillColor = true;
  1645. measureParam.FillColor = new byte[] { polygonAnnot.BgColor[0], polygonAnnot.BgColor[1], polygonAnnot.BgColor[2] };
  1646. }
  1647. measureParam.SavePoints = polygonAnnot.Points;
  1648. measureParam.BorderStyle = polygonAnnot.BorderStyle;
  1649. measureParam.LineWidth = polygonAnnot.LineWidth;
  1650. measureParam.Transparency = polygonAnnot.Transparency;
  1651. measureParam.LineDash = polygonAnnot.Dash;
  1652. measureParam.BorderEffector = polygonAnnot.GetAnnotBorderEffector();
  1653. GetAnnotCommonParam(polygonAnnot, measureParam);
  1654. return measureParam;
  1655. }
  1656. #endregion
  1657. public static bool SetParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1658. {
  1659. bool successful = false;
  1660. if (cPDFAnnotation == null && !cPDFAnnotation.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid())
  1661. {
  1662. return successful;
  1663. }
  1664. if (cPDFAnnotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  1665. {
  1666. successful = SetWidgetParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1667. }
  1668. else
  1669. {
  1670. successful = SetAnnotParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1671. }
  1672. return successful;
  1673. }
  1674. #region SetWidegt
  1675. internal static bool SetWidgetParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1676. {
  1677. bool successful = false;
  1678. if (cPDFAnnotation is CPDFWidget)
  1679. {
  1680. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  1681. {
  1682. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  1683. successful = SetPushButtonParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1684. break;
  1685. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  1686. successful = SetCheckBoxParamForPDFAnnot(cPDFAnnotation, param);
  1687. break;
  1688. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  1689. successful = SetRadioButtonParamForPDFAnnot(cPDFAnnotation, param);
  1690. break;
  1691. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  1692. successful = SetTextBoxParamForPDFAnnot(cPDFAnnotation, param);
  1693. break;
  1694. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  1695. successful = SetComboBoxParamForPDFAnnot(cPDFAnnotation, param);
  1696. break;
  1697. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  1698. successful = SetListBoxParamForPDFAnnot(cPDFAnnotation, param);
  1699. break;
  1700. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  1701. successful = SetSignatureParamForPDFAnnot(cPDFAnnotation, param);
  1702. break;
  1703. default:
  1704. successful = false;
  1705. break;
  1706. }
  1707. }
  1708. return successful;
  1709. }
  1710. internal static bool SetPushButtonParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1711. {
  1712. PushButtonParam CurrentParam = param as PushButtonParam;
  1713. CPDFPushButtonWidget pushbuttonWidget = cPDFAnnotation as CPDFPushButtonWidget;
  1714. bool successful = false;
  1715. if (pushbuttonWidget == null && !pushbuttonWidget.IsValid() && CurrentParam == null)
  1716. {
  1717. return successful;
  1718. }
  1719. else
  1720. {
  1721. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1722. {
  1723. pushbuttonWidget.SetFieldName(CurrentParam.FieldName);
  1724. }
  1725. if (CurrentParam.HasLineColor)
  1726. {
  1727. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1728. {
  1729. pushbuttonWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1730. }
  1731. }
  1732. if (CurrentParam.HasBgColor)
  1733. {
  1734. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1735. {
  1736. pushbuttonWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1737. }
  1738. }
  1739. if (!string.IsNullOrEmpty(CurrentParam.Text))
  1740. {
  1741. pushbuttonWidget.SetButtonTitle(CurrentParam.Text);
  1742. }
  1743. pushbuttonWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1744. pushbuttonWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1745. CTextAttribute textAttr = new CTextAttribute();
  1746. byte[] fontColor = new byte[3];
  1747. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1748. {
  1749. fontColor = CurrentParam.FontColor;
  1750. }
  1751. textAttr.FontColor = fontColor;
  1752. textAttr.FontSize = (float)CurrentParam.FontSize;
  1753. textAttr.FontName = ObtainFontName(
  1754. GetFontType(CurrentParam.FontName),
  1755. CurrentParam.IsBold,
  1756. CurrentParam.IsItalic);
  1757. pushbuttonWidget.SetTextAttribute(textAttr);
  1758. switch (CurrentParam.Action)
  1759. {
  1760. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  1761. {
  1762. CPDFGoToAction gotoAction = new CPDFGoToAction();
  1763. CPDFDestination destination = new CPDFDestination();
  1764. destination.Position_X = CurrentParam.DestinationPosition.x;
  1765. destination.Position_Y = CurrentParam.DestinationPosition.y;
  1766. destination.PageIndex = CurrentParam.DestinationPageIndex;
  1767. gotoAction.SetDestination(cPDFDocument, destination);
  1768. pushbuttonWidget.SetButtonAction(gotoAction);
  1769. }
  1770. break;
  1771. case C_ACTION_TYPE.ACTION_TYPE_URI:
  1772. {
  1773. CPDFUriAction uriAction = new CPDFUriAction();
  1774. uriAction.SetUri(CurrentParam.Uri);
  1775. pushbuttonWidget.SetButtonAction(uriAction);
  1776. }
  1777. break;
  1778. default:
  1779. break;
  1780. }
  1781. pushbuttonWidget.SetRect(CurrentParam.ClientRect);
  1782. pushbuttonWidget.SetFlags(CurrentParam.Flags);
  1783. pushbuttonWidget.SetIsLocked(CurrentParam.Locked);
  1784. pushbuttonWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1785. pushbuttonWidget.SetIsHidden(CurrentParam.IsHidden);
  1786. pushbuttonWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1787. pushbuttonWidget.UpdateFormAp();
  1788. successful = true;
  1789. return successful;
  1790. }
  1791. }
  1792. internal static bool SetCheckBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1793. {
  1794. CheckBoxParam CurrentParam = param as CheckBoxParam;
  1795. CPDFCheckBoxWidget checkboxWidget = cPDFAnnotation as CPDFCheckBoxWidget;
  1796. bool successful = false;
  1797. if (checkboxWidget == null && !checkboxWidget.IsValid() && CurrentParam == null)
  1798. {
  1799. return successful;
  1800. }
  1801. else
  1802. {
  1803. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1804. {
  1805. checkboxWidget.SetFieldName(CurrentParam.FieldName);
  1806. }
  1807. checkboxWidget.SetWidgetCheckStyle(CurrentParam.CheckStyle);
  1808. checkboxWidget.SetChecked(CurrentParam.IsChecked);
  1809. if (CurrentParam.HasLineColor)
  1810. {
  1811. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1812. {
  1813. checkboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1814. }
  1815. }
  1816. if (CurrentParam.HasBgColor)
  1817. {
  1818. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1819. {
  1820. checkboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1821. }
  1822. }
  1823. checkboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1824. checkboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1825. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1826. {
  1827. CTextAttribute textAttr = checkboxWidget.GetTextAttribute();
  1828. textAttr.FontColor = CurrentParam.FontColor;
  1829. checkboxWidget.SetTextAttribute(textAttr);
  1830. }
  1831. checkboxWidget.SetRect(CurrentParam.ClientRect);
  1832. checkboxWidget.SetFlags(CurrentParam.Flags);
  1833. checkboxWidget.SetIsLocked(CurrentParam.Locked);
  1834. checkboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1835. checkboxWidget.SetIsHidden(CurrentParam.IsHidden);
  1836. checkboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1837. checkboxWidget.UpdateFormAp();
  1838. successful = true;
  1839. return successful;
  1840. }
  1841. }
  1842. internal static bool SetRadioButtonParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1843. {
  1844. RadioButtonParam CurrentParam = param as RadioButtonParam;
  1845. CPDFRadioButtonWidget radioWidget = cPDFAnnotation as CPDFRadioButtonWidget;
  1846. bool successful = false;
  1847. if (radioWidget == null && !radioWidget.IsValid() && CurrentParam == null)
  1848. {
  1849. return successful;
  1850. }
  1851. else
  1852. {
  1853. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1854. {
  1855. radioWidget.SetFieldName(CurrentParam.FieldName);
  1856. }
  1857. radioWidget.SetWidgetCheckStyle(CurrentParam.CheckStyle);
  1858. radioWidget.SetChecked(CurrentParam.IsChecked);
  1859. if (CurrentParam.HasLineColor)
  1860. {
  1861. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1862. {
  1863. radioWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1864. }
  1865. }
  1866. if (CurrentParam.HasBgColor)
  1867. {
  1868. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1869. {
  1870. radioWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1871. }
  1872. }
  1873. radioWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1874. radioWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1875. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1876. {
  1877. CTextAttribute textAttr = radioWidget.GetTextAttribute();
  1878. textAttr.FontColor = CurrentParam.FontColor;
  1879. radioWidget.SetTextAttribute(textAttr);
  1880. }
  1881. radioWidget.SetRect(CurrentParam.ClientRect);
  1882. radioWidget.SetFlags(CurrentParam.Flags);
  1883. radioWidget.SetIsLocked(CurrentParam.Locked);
  1884. radioWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1885. radioWidget.SetIsHidden(CurrentParam.IsHidden);
  1886. radioWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1887. radioWidget.UpdateFormAp();
  1888. successful = true;
  1889. return successful;
  1890. }
  1891. }
  1892. internal static bool SetTextBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1893. {
  1894. TextBoxParam CurrentParam = param as TextBoxParam;
  1895. CPDFTextWidget textWidget = cPDFAnnotation as CPDFTextWidget;
  1896. bool successful = false;
  1897. if (textWidget == null && !textWidget.IsValid() && CurrentParam == null)
  1898. {
  1899. return successful;
  1900. }
  1901. else
  1902. {
  1903. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1904. {
  1905. textWidget.SetFieldName(CurrentParam.FieldName);
  1906. }
  1907. if (CurrentParam.HasLineColor)
  1908. {
  1909. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1910. {
  1911. textWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1912. }
  1913. }
  1914. if (CurrentParam.HasBgColor)
  1915. {
  1916. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1917. {
  1918. textWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1919. }
  1920. }
  1921. if (!string.IsNullOrEmpty(CurrentParam.Text))
  1922. {
  1923. textWidget.SetText(CurrentParam.Text);
  1924. }
  1925. CTextAttribute textAttr = new CTextAttribute();
  1926. byte[] fontColor = new byte[3];
  1927. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1928. {
  1929. fontColor = CurrentParam.FontColor;
  1930. }
  1931. textAttr.FontColor = fontColor;
  1932. textAttr.FontSize = (float)CurrentParam.FontSize;
  1933. textAttr.FontName = ObtainFontName(
  1934. GetFontType(CurrentParam.FontName),
  1935. CurrentParam.IsBold,
  1936. CurrentParam.IsItalic);
  1937. textWidget.SetTextAttribute(textAttr);
  1938. textWidget.SetJustification(CurrentParam.Alignment);
  1939. textWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1940. textWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1941. textWidget.SetMultiLine(CurrentParam.IsMultiLine);
  1942. textWidget.SetRect(CurrentParam.ClientRect);
  1943. textWidget.SetFlags(CurrentParam.Flags);
  1944. textWidget.SetIsLocked(CurrentParam.Locked);
  1945. textWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1946. textWidget.SetIsHidden(CurrentParam.IsHidden);
  1947. textWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1948. textWidget.UpdateFormAp();
  1949. successful = true;
  1950. return successful;
  1951. }
  1952. }
  1953. internal static bool SetComboBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1954. {
  1955. ComboBoxParam CurrentParam = param as ComboBoxParam;
  1956. CPDFComboBoxWidget comboboxWidget = cPDFAnnotation as CPDFComboBoxWidget;
  1957. bool successful = false;
  1958. if (comboboxWidget == null && !comboboxWidget.IsValid() && CurrentParam == null)
  1959. {
  1960. return successful;
  1961. }
  1962. else
  1963. {
  1964. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1965. {
  1966. comboboxWidget.SetFieldName(CurrentParam.FieldName);
  1967. }
  1968. if (CurrentParam.HasLineColor)
  1969. {
  1970. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1971. {
  1972. comboboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1973. }
  1974. }
  1975. if (CurrentParam.HasBgColor)
  1976. {
  1977. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1978. {
  1979. comboboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1980. }
  1981. }
  1982. comboboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1983. comboboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1984. CTextAttribute textAttr = new CTextAttribute();
  1985. byte[] fontColor = new byte[3];
  1986. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1987. {
  1988. fontColor = CurrentParam.FontColor;
  1989. }
  1990. textAttr.FontColor = fontColor;
  1991. textAttr.FontSize = (float)CurrentParam.FontSize;
  1992. textAttr.FontName = ObtainFontName(
  1993. GetFontType(CurrentParam.FontName),
  1994. CurrentParam.IsBold,
  1995. CurrentParam.IsItalic);
  1996. comboboxWidget.SetTextAttribute(textAttr);
  1997. if (CurrentParam.OptionItems != null && CurrentParam.OptionItems.Count > 0)
  1998. {
  1999. int addIndex = 0;
  2000. foreach (string key in CurrentParam.OptionItems.Keys)
  2001. {
  2002. comboboxWidget.AddOptionItem(addIndex, CurrentParam.OptionItems[key], key);
  2003. addIndex++;
  2004. }
  2005. }
  2006. if (CurrentParam.SelectItemsIndex != null && CurrentParam.SelectItemsIndex.Count > 0)
  2007. {
  2008. comboboxWidget.SelectItem(CurrentParam.SelectItemsIndex[0]);
  2009. }
  2010. comboboxWidget.SetRect(CurrentParam.ClientRect);
  2011. comboboxWidget.SetFlags(CurrentParam.Flags);
  2012. comboboxWidget.SetIsLocked(CurrentParam.Locked);
  2013. comboboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  2014. comboboxWidget.SetIsHidden(CurrentParam.IsHidden);
  2015. comboboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2016. comboboxWidget.UpdateFormAp();
  2017. successful = true;
  2018. return successful;
  2019. }
  2020. }
  2021. internal static bool SetListBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2022. {
  2023. ListBoxParam CurrentParam = param as ListBoxParam;
  2024. CPDFListBoxWidget listboxWidget = cPDFAnnotation as CPDFListBoxWidget;
  2025. bool successful = false;
  2026. if (listboxWidget == null && !listboxWidget.IsValid() && CurrentParam == null)
  2027. {
  2028. return successful;
  2029. }
  2030. else
  2031. {
  2032. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  2033. {
  2034. listboxWidget.SetFieldName(CurrentParam.FieldName);
  2035. }
  2036. if (CurrentParam.HasLineColor)
  2037. {
  2038. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2039. {
  2040. listboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  2041. }
  2042. }
  2043. if (CurrentParam.HasBgColor)
  2044. {
  2045. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2046. {
  2047. listboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  2048. }
  2049. }
  2050. listboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  2051. listboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  2052. CTextAttribute textAttr = new CTextAttribute();
  2053. byte[] fontColor = new byte[3];
  2054. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2055. {
  2056. fontColor = CurrentParam.FontColor;
  2057. }
  2058. textAttr.FontColor = fontColor;
  2059. textAttr.FontSize = (float)CurrentParam.FontSize;
  2060. textAttr.FontName = ObtainFontName(
  2061. GetFontType(CurrentParam.FontName),
  2062. CurrentParam.IsBold,
  2063. CurrentParam.IsItalic);
  2064. listboxWidget.SetTextAttribute(textAttr);
  2065. if (CurrentParam.OptionItems != null && CurrentParam.OptionItems.Count > 0)
  2066. {
  2067. int addIndex = 0;
  2068. foreach (string key in CurrentParam.OptionItems.Keys)
  2069. {
  2070. listboxWidget.AddOptionItem(addIndex, CurrentParam.OptionItems[key], key);
  2071. addIndex++;
  2072. }
  2073. }
  2074. if (CurrentParam.SelectItemsIndex != null && CurrentParam.SelectItemsIndex.Count > 0)
  2075. {
  2076. listboxWidget.SelectItem(CurrentParam.SelectItemsIndex[0]);
  2077. }
  2078. listboxWidget.SetRect(CurrentParam.ClientRect);
  2079. listboxWidget.SetFlags(CurrentParam.Flags);
  2080. listboxWidget.SetIsLocked(CurrentParam.Locked);
  2081. listboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  2082. listboxWidget.SetIsHidden(CurrentParam.IsHidden);
  2083. listboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2084. listboxWidget.UpdateFormAp();
  2085. successful = true;
  2086. return successful;
  2087. }
  2088. }
  2089. internal static bool SetSignatureParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2090. {
  2091. SignatureParam CurrentParam = param as SignatureParam;
  2092. CPDFSignatureWidget signWidget = cPDFAnnotation as CPDFSignatureWidget;
  2093. bool successful = false;
  2094. if (signWidget == null && !signWidget.IsValid() && CurrentParam == null)
  2095. {
  2096. return successful;
  2097. }
  2098. else
  2099. {
  2100. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  2101. {
  2102. signWidget.SetFieldName(CurrentParam.FieldName);
  2103. }
  2104. if (CurrentParam.HasLineColor)
  2105. {
  2106. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2107. {
  2108. signWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  2109. }
  2110. }
  2111. if (CurrentParam.HasBgColor)
  2112. {
  2113. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2114. {
  2115. signWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  2116. }
  2117. }
  2118. signWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  2119. signWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  2120. signWidget.SetRect(CurrentParam.ClientRect);
  2121. signWidget.SetFlags(CurrentParam.Flags);
  2122. signWidget.SetIsLocked(CurrentParam.Locked);
  2123. signWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  2124. signWidget.SetIsHidden(CurrentParam.IsHidden);
  2125. signWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2126. signWidget.UpdateFormAp();
  2127. successful = true;
  2128. return successful;
  2129. }
  2130. }
  2131. #endregion
  2132. #region SetAnnot
  2133. internal static bool SetAnnotParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2134. {
  2135. bool successful = false;
  2136. if (cPDFAnnotation != null)
  2137. {
  2138. switch (cPDFAnnotation.Type)
  2139. {
  2140. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  2141. successful = SetSquareAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2142. break;
  2143. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  2144. successful = SetCircleAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2145. break;
  2146. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  2147. successful = SetLineAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2148. break;
  2149. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  2150. successful = SetInkAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2151. break;
  2152. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  2153. successful = SetFreeTextAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2154. break;
  2155. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  2156. successful = SetHighlightAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2157. break;
  2158. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  2159. successful = SetUnderlineAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2160. break;
  2161. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  2162. successful = SetStrikeoutAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2163. break;
  2164. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  2165. successful = SetSquigglyAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2166. break;
  2167. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  2168. successful = SetTextAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2169. break;
  2170. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  2171. successful = SetStampAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2172. break;
  2173. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  2174. successful = SetLinkAnnotParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  2175. break;
  2176. default:
  2177. break;
  2178. }
  2179. }
  2180. return successful;
  2181. }
  2182. internal static bool SetSquareAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2183. {
  2184. SquareParam CurrentParam = param as SquareParam;
  2185. CPDFSquareAnnotation squareAnnot = cPDFAnnotation as CPDFSquareAnnotation;
  2186. bool successful = false;
  2187. if (squareAnnot == null && !squareAnnot.IsValid() && CurrentParam == null)
  2188. {
  2189. return successful;
  2190. }
  2191. else
  2192. {
  2193. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2194. {
  2195. squareAnnot.SetLineColor(CurrentParam.LineColor);
  2196. }
  2197. if (CurrentParam.HasBgColor)
  2198. {
  2199. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2200. {
  2201. squareAnnot.SetBgColor(CurrentParam.BgColor);
  2202. }
  2203. }
  2204. squareAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2205. squareAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2206. squareAnnot.SetRect(CurrentParam.ClientRect);
  2207. List<float> floatArray = new List<float>();
  2208. if (CurrentParam.LineDash != null)
  2209. {
  2210. foreach (float num in CurrentParam.LineDash)
  2211. {
  2212. floatArray.Add(num);
  2213. }
  2214. }
  2215. squareAnnot.SetBorderStyle(CurrentParam.BorderStyle, floatArray.ToArray());
  2216. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2217. {
  2218. squareAnnot.SetAuthor(CurrentParam.Author);
  2219. }
  2220. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2221. {
  2222. squareAnnot.SetContent(CurrentParam.Content);
  2223. }
  2224. squareAnnot.SetIsLocked(CurrentParam.Locked);
  2225. squareAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2226. squareAnnot.UpdateAp();
  2227. successful = true;
  2228. return successful;
  2229. }
  2230. }
  2231. internal static bool SetCircleAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2232. {
  2233. CircleParam CurrentParam = param as CircleParam;
  2234. CPDFCircleAnnotation circleAnnot = cPDFAnnotation as CPDFCircleAnnotation;
  2235. bool successful = false;
  2236. if (circleAnnot == null && !circleAnnot.IsValid() && CurrentParam == null)
  2237. {
  2238. return successful;
  2239. }
  2240. else
  2241. {
  2242. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2243. {
  2244. circleAnnot.SetLineColor(CurrentParam.LineColor);
  2245. }
  2246. if (CurrentParam.HasBgColor)
  2247. {
  2248. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2249. {
  2250. circleAnnot.SetBgColor(CurrentParam.BgColor);
  2251. }
  2252. }
  2253. circleAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2254. circleAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2255. circleAnnot.SetRect(CurrentParam.ClientRect);
  2256. List<float> floatArray = new List<float>();
  2257. if (CurrentParam.LineDash != null)
  2258. {
  2259. foreach (float num in CurrentParam.LineDash)
  2260. {
  2261. floatArray.Add(num);
  2262. }
  2263. }
  2264. circleAnnot.SetBorderStyle(CurrentParam.BorderStyle, floatArray.ToArray());
  2265. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2266. {
  2267. circleAnnot.SetAuthor(CurrentParam.Author);
  2268. }
  2269. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2270. {
  2271. circleAnnot.SetContent(CurrentParam.Content);
  2272. }
  2273. circleAnnot.SetIsLocked(CurrentParam.Locked);
  2274. circleAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2275. circleAnnot.UpdateAp();
  2276. successful = true;
  2277. return successful;
  2278. }
  2279. }
  2280. internal static bool SetLineAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2281. {
  2282. LineParam CurrentParam = param as LineParam;
  2283. CPDFLineAnnotation lineAnnot = cPDFAnnotation as CPDFLineAnnotation;
  2284. bool successful = false;
  2285. if (lineAnnot == null && !lineAnnot.IsValid() && CurrentParam == null)
  2286. {
  2287. return successful;
  2288. }
  2289. else
  2290. {
  2291. if (CurrentParam.HeadLineType != C_LINE_TYPE.LINETYPE_NONE || CurrentParam.TailLineType != C_LINE_TYPE.LINETYPE_NONE)
  2292. {
  2293. lineAnnot.SetLineType(CurrentParam.HeadLineType, CurrentParam.TailLineType);
  2294. }
  2295. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2296. {
  2297. lineAnnot.SetLineColor(CurrentParam.LineColor);
  2298. }
  2299. if (CurrentParam.HasBgColor)
  2300. {
  2301. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2302. {
  2303. lineAnnot.SetBgColor(CurrentParam.BgColor);
  2304. }
  2305. }
  2306. lineAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2307. lineAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2308. lineAnnot.SetLinePoints(CurrentParam.HeadPoint, CurrentParam.TailPoint);
  2309. lineAnnot.SetRect(CurrentParam.ClientRect);
  2310. List<float> floatArray = new List<float>();
  2311. if (CurrentParam.LineDash != null)
  2312. {
  2313. foreach (float num in CurrentParam.LineDash)
  2314. {
  2315. floatArray.Add(num);
  2316. }
  2317. }
  2318. lineAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
  2319. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2320. {
  2321. lineAnnot.SetAuthor(CurrentParam.Author);
  2322. }
  2323. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2324. {
  2325. lineAnnot.SetContent(CurrentParam.Content);
  2326. }
  2327. lineAnnot.SetIsLocked(CurrentParam.Locked);
  2328. lineAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2329. lineAnnot.UpdateAp();
  2330. successful = true;
  2331. return successful;
  2332. }
  2333. }
  2334. internal static bool SetInkAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2335. {
  2336. InkParam CurrentParam = param as InkParam;
  2337. CPDFInkAnnotation inkAnnot = cPDFAnnotation as CPDFInkAnnotation;
  2338. bool successful = false;
  2339. if (inkAnnot == null && !inkAnnot.IsValid() && CurrentParam == null)
  2340. {
  2341. return successful;
  2342. }
  2343. else
  2344. {
  2345. if (CurrentParam.InkColor != null && CurrentParam.InkColor.Length == 3)
  2346. {
  2347. inkAnnot.SetInkColor(CurrentParam.InkColor);
  2348. }
  2349. inkAnnot.SetThickness((float)CurrentParam.Thickness);
  2350. inkAnnot.SetInkPath(CurrentParam.InkPath);
  2351. inkAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2352. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2353. {
  2354. inkAnnot.SetAuthor(CurrentParam.Author);
  2355. }
  2356. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2357. {
  2358. inkAnnot.SetContent(CurrentParam.Content);
  2359. }
  2360. inkAnnot.SetIsLocked(CurrentParam.Locked);
  2361. inkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2362. inkAnnot.UpdateAp();
  2363. successful = true;
  2364. return successful;
  2365. }
  2366. }
  2367. internal static bool SetHighlightAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2368. {
  2369. HighlightParam CurrentParam = param as HighlightParam;
  2370. CPDFHighlightAnnotation highlightAnnot = cPDFAnnotation as CPDFHighlightAnnotation;
  2371. bool successful = false;
  2372. if (highlightAnnot == null && !highlightAnnot.IsValid() && CurrentParam == null)
  2373. {
  2374. return successful;
  2375. }
  2376. else
  2377. {
  2378. highlightAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2379. if (CurrentParam.QuardRects != null)
  2380. {
  2381. highlightAnnot.SetQuardRects(CurrentParam.QuardRects);
  2382. }
  2383. if (CurrentParam.HighlightColor != null && CurrentParam.HighlightColor.Length == 3)
  2384. {
  2385. highlightAnnot.SetColor(CurrentParam.HighlightColor);
  2386. }
  2387. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2388. {
  2389. highlightAnnot.SetAuthor(CurrentParam.Author);
  2390. }
  2391. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2392. {
  2393. highlightAnnot.SetContent(CurrentParam.Content);
  2394. }
  2395. highlightAnnot.SetRect(CurrentParam.ClientRect);
  2396. highlightAnnot.SetIsLocked(CurrentParam.Locked);
  2397. highlightAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2398. highlightAnnot.UpdateAp();
  2399. successful = true;
  2400. return successful;
  2401. }
  2402. }
  2403. internal static bool SetUnderlineAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2404. {
  2405. UnderlineParam CurrentParam = param as UnderlineParam;
  2406. CPDFUnderlineAnnotation underlineAnnot = cPDFAnnotation as CPDFUnderlineAnnotation;
  2407. bool successful = false;
  2408. if (underlineAnnot == null && !underlineAnnot.IsValid() && CurrentParam == null)
  2409. {
  2410. return successful;
  2411. }
  2412. else
  2413. {
  2414. underlineAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2415. underlineAnnot.SetRect(CurrentParam.ClientRect);
  2416. if (CurrentParam.QuardRects != null)
  2417. {
  2418. underlineAnnot.SetQuardRects(CurrentParam.QuardRects);
  2419. }
  2420. if (CurrentParam.UnderlineColor != null && CurrentParam.UnderlineColor.Length == 3)
  2421. {
  2422. underlineAnnot.SetColor(CurrentParam.UnderlineColor);
  2423. }
  2424. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2425. {
  2426. underlineAnnot.SetAuthor(CurrentParam.Author);
  2427. }
  2428. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2429. {
  2430. underlineAnnot.SetContent(CurrentParam.Content);
  2431. }
  2432. underlineAnnot.SetIsLocked(CurrentParam.Locked);
  2433. underlineAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2434. underlineAnnot.UpdateAp();
  2435. successful = true;
  2436. return successful;
  2437. }
  2438. }
  2439. internal static bool SetStrikeoutAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2440. {
  2441. StrikeoutParam CurrentParam = param as StrikeoutParam;
  2442. CPDFStrikeoutAnnotation strikeoutAnnot = cPDFAnnotation as CPDFStrikeoutAnnotation;
  2443. bool successful = false;
  2444. if (strikeoutAnnot == null && !strikeoutAnnot.IsValid() && CurrentParam == null)
  2445. {
  2446. return successful;
  2447. }
  2448. else
  2449. {
  2450. strikeoutAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2451. strikeoutAnnot.SetRect(CurrentParam.ClientRect);
  2452. if (CurrentParam.QuardRects != null)
  2453. {
  2454. strikeoutAnnot.SetQuardRects(CurrentParam.QuardRects);
  2455. }
  2456. if (CurrentParam.StrikeoutColor != null && CurrentParam.StrikeoutColor.Length == 3)
  2457. {
  2458. strikeoutAnnot.SetColor(CurrentParam.StrikeoutColor);
  2459. }
  2460. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2461. {
  2462. strikeoutAnnot.SetAuthor(CurrentParam.Author);
  2463. }
  2464. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2465. {
  2466. strikeoutAnnot.SetContent(CurrentParam.Content);
  2467. }
  2468. strikeoutAnnot.SetIsLocked(CurrentParam.Locked);
  2469. strikeoutAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2470. strikeoutAnnot.UpdateAp();
  2471. successful = true;
  2472. return successful;
  2473. }
  2474. }
  2475. internal static bool SetSquigglyAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2476. {
  2477. SquigglyParam CurrentParam = param as SquigglyParam;
  2478. CPDFSquigglyAnnotation squigglyAnnot = cPDFAnnotation as CPDFSquigglyAnnotation;
  2479. bool successful = false;
  2480. if (squigglyAnnot == null && !squigglyAnnot.IsValid() && CurrentParam == null)
  2481. {
  2482. return successful;
  2483. }
  2484. else
  2485. {
  2486. squigglyAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2487. squigglyAnnot.SetRect(CurrentParam.ClientRect);
  2488. if (CurrentParam.QuardRects != null)
  2489. {
  2490. squigglyAnnot.SetQuardRects(CurrentParam.QuardRects);
  2491. }
  2492. if (CurrentParam.SquigglyColor != null && CurrentParam.SquigglyColor.Length == 3)
  2493. {
  2494. squigglyAnnot.SetColor(CurrentParam.SquigglyColor);
  2495. }
  2496. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2497. {
  2498. squigglyAnnot.SetAuthor(CurrentParam.Author);
  2499. }
  2500. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2501. {
  2502. squigglyAnnot.SetContent(CurrentParam.Content);
  2503. }
  2504. squigglyAnnot.SetIsLocked(CurrentParam.Locked);
  2505. squigglyAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2506. squigglyAnnot.UpdateAp();
  2507. successful = true;
  2508. return successful;
  2509. }
  2510. }
  2511. internal static bool SetFreeTextAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2512. {
  2513. FreeTextParam CurrentParam = param as FreeTextParam;
  2514. CPDFFreeTextAnnotation textAnnot = cPDFAnnotation as CPDFFreeTextAnnotation;
  2515. bool successful = false;
  2516. if (textAnnot == null && !textAnnot.IsValid() && CurrentParam == null)
  2517. {
  2518. return successful;
  2519. }
  2520. else
  2521. {
  2522. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2523. {
  2524. textAnnot.SetLineColor(CurrentParam.LineColor);
  2525. }
  2526. if (CurrentParam.HasBgColor)
  2527. {
  2528. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2529. {
  2530. textAnnot.SetBgColor(CurrentParam.BgColor);
  2531. }
  2532. }
  2533. textAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2534. textAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2535. textAnnot.SetFreetextAlignment(CurrentParam.Alignment);
  2536. CTextAttribute textAttr = new CTextAttribute();
  2537. byte[] fontColor = new byte[3];
  2538. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2539. {
  2540. fontColor = CurrentParam.FontColor;
  2541. }
  2542. textAttr.FontColor = fontColor;
  2543. textAttr.FontSize = (float)CurrentParam.FontSize;
  2544. textAttr.FontName = ObtainFontName(
  2545. GetFontType(CurrentParam.FontName),
  2546. CurrentParam.IsBold,
  2547. CurrentParam.IsItalic);
  2548. textAnnot.SetFreetextDa(textAttr);
  2549. textAnnot.SetRect(CurrentParam.ClientRect);
  2550. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2551. {
  2552. textAnnot.SetAuthor(CurrentParam.Author);
  2553. }
  2554. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2555. {
  2556. textAnnot.SetContent(CurrentParam.Content);
  2557. }
  2558. textAnnot.SetIsLocked(CurrentParam.Locked);
  2559. textAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2560. textAnnot.UpdateAp();
  2561. successful = true;
  2562. return successful;
  2563. }
  2564. }
  2565. internal static bool SetStampAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2566. {
  2567. StampParam CurrentParam = param as StampParam;
  2568. CPDFStampAnnotation stampAnnot = cPDFAnnotation as CPDFStampAnnotation;
  2569. bool successful = false;
  2570. if (stampAnnot == null && !stampAnnot.IsValid() && CurrentParam == null)
  2571. {
  2572. return successful;
  2573. }
  2574. else
  2575. {
  2576. switch (CurrentParam.StampType)
  2577. {
  2578. case C_STAMP_TYPE.STANDARD_STAMP:
  2579. {
  2580. string stampText = CurrentParam.StampText;
  2581. if (stampText == null)
  2582. {
  2583. stampText = string.Empty;
  2584. }
  2585. stampAnnot.SetStandardStamp(stampText, CurrentParam.PageRotation);
  2586. stampAnnot.SetRect(CurrentParam.ClientRect);
  2587. }
  2588. break;
  2589. case C_STAMP_TYPE.TEXT_STAMP:
  2590. {
  2591. string dateText = CurrentParam.DateText;
  2592. string stampText = CurrentParam.StampText;
  2593. if (dateText == null)
  2594. {
  2595. dateText = string.Empty;
  2596. }
  2597. if (stampText == null)
  2598. {
  2599. stampText = string.Empty;
  2600. }
  2601. stampAnnot.SetTextStamp(
  2602. stampText,
  2603. dateText,
  2604. CurrentParam.TextStampShape,
  2605. CurrentParam.TextStampColor,
  2606. CurrentParam.PageRotation);
  2607. stampAnnot.SetRect(CurrentParam.ClientRect);
  2608. }
  2609. break;
  2610. case C_STAMP_TYPE.IMAGE_STAMP:
  2611. {
  2612. byte[] imageData = null;
  2613. int imageWidth = 0;
  2614. int imageHeight = 0;
  2615. PDFHelp.ImageStreamToByte(CurrentParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  2616. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  2617. {
  2618. stampAnnot.SetRect(CurrentParam.ClientRect);
  2619. stampAnnot.SetImageStamp(
  2620. imageData,
  2621. imageWidth,
  2622. imageHeight,
  2623. CurrentParam.PageRotation);
  2624. }
  2625. }
  2626. break;
  2627. default:
  2628. break;
  2629. }
  2630. stampAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2631. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2632. {
  2633. stampAnnot.SetAuthor(CurrentParam.Author);
  2634. }
  2635. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2636. {
  2637. stampAnnot.SetContent(CurrentParam.Content);
  2638. }
  2639. stampAnnot.SetIsLocked(CurrentParam.Locked);
  2640. stampAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2641. stampAnnot.UpdateAp();
  2642. successful = true;
  2643. return successful;
  2644. }
  2645. }
  2646. internal static bool SetLinkAnnotParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2647. {
  2648. LinkParam CurrentParam = param as LinkParam;
  2649. CPDFLinkAnnotation linkAnnot = cPDFAnnotation as CPDFLinkAnnotation;
  2650. bool successful = false;
  2651. if (linkAnnot == null && !linkAnnot.IsValid() && CurrentParam == null)
  2652. {
  2653. return successful;
  2654. }
  2655. else
  2656. {
  2657. switch (CurrentParam.Action)
  2658. {
  2659. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  2660. {
  2661. CPDFGoToAction gotoAction = new CPDFGoToAction();
  2662. CPDFDestination destination = new CPDFDestination();
  2663. destination.Position_X = CurrentParam.DestinationPosition.x;
  2664. destination.Position_Y = CurrentParam.DestinationPosition.y;
  2665. destination.PageIndex = CurrentParam.DestinationPageIndex;
  2666. gotoAction.SetDestination(cPDFDocument, destination);
  2667. linkAnnot.SetLinkAction(gotoAction);
  2668. }
  2669. break;
  2670. case C_ACTION_TYPE.ACTION_TYPE_URI:
  2671. {
  2672. CPDFUriAction uriAction = new CPDFUriAction();
  2673. if (!string.IsNullOrEmpty(CurrentParam.Uri))
  2674. {
  2675. uriAction.SetUri(CurrentParam.Uri);
  2676. }
  2677. linkAnnot.SetLinkAction(uriAction);
  2678. }
  2679. break;
  2680. default:
  2681. break;
  2682. }
  2683. linkAnnot.SetRect(CurrentParam.ClientRect);
  2684. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2685. {
  2686. linkAnnot.SetAuthor(CurrentParam.Author);
  2687. }
  2688. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2689. {
  2690. linkAnnot.SetContent(CurrentParam.Content);
  2691. }
  2692. linkAnnot.SetIsLocked(CurrentParam.Locked);
  2693. linkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2694. linkAnnot.UpdateAp();
  2695. successful = true;
  2696. return successful;
  2697. }
  2698. }
  2699. internal static bool SetTextAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2700. {
  2701. StickyNoteParam textAnnotParam = param as StickyNoteParam;
  2702. CPDFTextAnnotation textAnnot = cPDFAnnotation as CPDFTextAnnotation;
  2703. if (textAnnot == null && !textAnnot.IsValid() && textAnnotParam == null)
  2704. {
  2705. return false;
  2706. }
  2707. else
  2708. {
  2709. if (textAnnotParam.StickyNoteColor != null && textAnnotParam.StickyNoteColor.Length == 3)
  2710. {
  2711. textAnnot.SetColor(textAnnotParam.StickyNoteColor);
  2712. }
  2713. textAnnot.SetTransparency((byte)textAnnotParam.Transparency);
  2714. textAnnot.SetRect(textAnnotParam.ClientRect);
  2715. if (!string.IsNullOrEmpty(textAnnotParam.Author))
  2716. {
  2717. textAnnot.SetAuthor(textAnnotParam.Author);
  2718. }
  2719. if (!string.IsNullOrEmpty(textAnnotParam.Content))
  2720. {
  2721. textAnnot.SetContent(textAnnotParam.Content);
  2722. }
  2723. textAnnot.SetIsLocked(textAnnotParam.Locked);
  2724. textAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2725. textAnnot.UpdateAp();
  2726. return true;
  2727. }
  2728. }
  2729. #endregion
  2730. public static bool SetParamForPDFEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2731. {
  2732. bool successful = false;
  2733. if (cPDFEditArea == null && !cPDFEditArea.IsValid())
  2734. {
  2735. return successful;
  2736. }
  2737. switch (cPDFEditArea.Type)
  2738. {
  2739. case CPDFEditType.EditText:
  2740. SetParamForPDFTextEdit(cPDFEditArea, param);
  2741. break;
  2742. default:
  2743. break;
  2744. }
  2745. return successful;
  2746. }
  2747. internal static bool SetParamForPDFTextEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2748. {
  2749. TextEditParam CurrentParam = param as TextEditParam;
  2750. CPDFEditTextArea cPDFEditTextArea = cPDFEditArea as CPDFEditTextArea;
  2751. bool successful = false;
  2752. if (cPDFEditTextArea == null && !cPDFEditTextArea.IsValid() && CurrentParam == null)
  2753. {
  2754. return successful;
  2755. }
  2756. else
  2757. {
  2758. cPDFEditTextArea.SetCharsFontTransparency(param.Transparency);
  2759. cPDFEditTextArea.SetFrame(
  2760. DataConversionForWPF.RectConversionForCRect(
  2761. new Rect(CurrentParam.ClientRect.left, CurrentParam.ClientRect.top, CurrentParam.ClientRect.width(), CurrentParam.ClientRect.height())
  2762. ));
  2763. cPDFEditTextArea.SetCharsFontSize((float)CurrentParam.FontSize, true);
  2764. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2765. {
  2766. cPDFEditTextArea.SetCharsFontColor(CurrentParam.FontColor[0], CurrentParam.FontColor[1], CurrentParam.FontColor[2]);
  2767. }
  2768. cPDFEditTextArea.SetTextAreaAlign(CurrentParam.TextAlign);
  2769. cPDFEditTextArea.SetCharsFontName(CurrentParam.FontName);
  2770. cPDFEditTextArea.SetCharsFontItalic(CurrentParam.IsItalic);
  2771. cPDFEditTextArea.SetCharsFontBold(CurrentParam.IsBold);
  2772. successful = true;
  2773. return successful;
  2774. }
  2775. }
  2776. internal static bool SetParamForPDFImageEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2777. {
  2778. ImageEditParam CurrentParam = param as ImageEditParam;
  2779. CPDFEditImageArea cPDFEditImageArea = cPDFEditArea as CPDFEditImageArea;
  2780. bool successful = false;
  2781. if (cPDFEditImageArea == null && !cPDFEditImageArea.IsValid() && CurrentParam == null)
  2782. {
  2783. return successful;
  2784. }
  2785. else
  2786. {
  2787. cPDFEditImageArea.SetImageTransparency(param.Transparency);
  2788. cPDFEditImageArea.SetFrame(
  2789. DataConversionForWPF.RectConversionForCRect(
  2790. new Rect(CurrentParam.ClientRect.left, CurrentParam.ClientRect.top, CurrentParam.ClientRect.width(), CurrentParam.ClientRect.height())
  2791. ))
  2792. ;
  2793. cPDFEditImageArea.CutWithRect(
  2794. DataConversionForWPF.RectConversionForCRect(
  2795. new Rect(CurrentParam.ClipRect.left, CurrentParam.ClipRect.top, CurrentParam.ClipRect.width(), CurrentParam.ClipRect.height())
  2796. ));
  2797. successful = true;
  2798. return successful;
  2799. }
  2800. }
  2801. }
  2802. }