ParamConverter.cs 128 KB

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