ParamConverter.cs 128 KB

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