ParamConverter.cs 127 KB

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