ParamConverter.cs 125 KB

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