private void DrawTable() { PDPage pDPage; PDDocument pDDocument = new PDDocument(); pDPage = (this.pageSettings.size != null ? new PDPage(this.pageSettings.size.PDFBoxRectangle) : new PDPage()); PDRectangle mediaBox = pDPage.getMediaBox(); int num = this.contents.Count <List <string> >(); int num1 = this.contents.ElementAt <List <string> >(0).Count <string>(); float width = mediaBox.getWidth() - (this.pageSettings.marginLeft + this.pageSettings.marginRight); float single = width / (float)num1; float rowHeight = this.tableSettings.RowHeight; float height = mediaBox.getHeight() - this.pageSettings.marginTop; float single1 = height - this.pageSettings.marginBottom; float single2 = rowHeight * (float)num; int num2 = num; int num3 = 1; int num4 = 0; if (single2 > single1) { num2 = (int)Math.Floor((double)(single1 / rowHeight)); num3 = (int)Math.Ceiling((double)num / (double)num2); single2 = (float)num2 * rowHeight; num4 = num % num2; } int num5 = 0; for (int i = 0; i < num3; i++) { pDPage = (this.pageSettings.size != null ? new PDPage(this.pageSettings.size.PDFBoxRectangle) : new PDPage()); pDDocument.addPage(pDPage); PDPageContentStream pDPageContentStream = new PDPageContentStream(pDDocument, pDPage); if ((i != num3 - 1 ? false : num4 > 0)) { num2 = num4; single2 = rowHeight * (float)num2; } float single3 = height; for (int j = 0; j <= num2; j++) { pDPageContentStream.drawLine(this.pageSettings.marginLeft, single3, this.pageSettings.marginLeft + width, single3); single3 = single3 - rowHeight; } float single4 = this.pageSettings.marginLeft; for (int k = 0; k <= num1; k++) { pDPageContentStream.drawLine(single4, height, single4, height - single2); single4 = single4 + single; } pDPageContentStream.setFont(this.pageSettings.Font.PDFBoxFont, this.pageSettings.FontSize); float cellMargin = this.pageSettings.marginLeft + this.tableSettings.CellMargin; float single5 = height - 15f; for (int l = 0; l < num2; l++) { foreach (string item in this.contents[num5]) { pDPageContentStream.beginText(); pDPageContentStream.newLineAtOffset(cellMargin, single5); pDPageContentStream.showText(item); pDPageContentStream.endText(); cellMargin = cellMargin + single; } single5 = single5 - rowHeight; cellMargin = this.pageSettings.marginLeft + this.tableSettings.CellMargin; num5++; } pDPageContentStream.close(); } pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument); pDDocument.save(this.outputPDF); }
internal void createPDFFromText(string pdfFile) { string str; bool flag; PDDocument pDDocument = new PDDocument(); PDFHelper.DisplayTrialPopupIfNecessary(); PDFHelper.CheckOutputFolder(Path.GetDirectoryName(pdfFile)); try { this.pdfFileName = pdfFile; Reader fileReader = new FileReader(this.textFile); int num = 40; if (this.font == null) { this.font = PDFType1Font.TIMES_ROMAN; } float height = this.font.PDFBoxFont.getBoundingBox().getHeight() / 1000f; PDRectangle lETTER = PDRectangle.LETTER; if (this.isLandescape) { lETTER = new PDRectangle(lETTER.getHeight(), lETTER.getWidth()); } height = height * this.fontSize * 1.05f; string[] strArrays = System.IO.File.ReadAllLines(this.textFile); PDPage pDPage = new PDPage(lETTER); PDPageContentStream pDPageContentStream = null; float single = -1f; float width = pDPage.getMediaBox().getWidth() - (float)(2 * num); bool flag1 = true; string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str1 = strArrays1[i]; flag1 = false; string str2 = Regex.Replace(str1, "\\t|\\n|\\r", ""); string[] strArrays2 = str2.Replace("[\\n\\r]+$", "").Split(new char[] { ' ' }); int num1 = 0; while (num1 < (int)strArrays2.Length) { StringBuilder stringBuilder = new StringBuilder(); float stringWidth = 0f; bool flag2 = false; do { string str3 = ""; int num2 = strArrays2[num1].IndexOf('\f'); if (num2 != -1) { flag2 = true; str = strArrays2[num1].Substring(0, num2); if (num2 < strArrays2[num1].Length) { str3 = strArrays2[num1].Substring(num2 + 1); } } else { str = strArrays2[num1]; } if ((str.Length > 0 ? true : !flag2)) { stringBuilder.Append(str); stringBuilder.Append(" "); } if ((!flag2 ? false : str3.Length != 0)) { strArrays2[num1] = str3; } else { num1++; } if (!flag2) { if (num1 < (int)strArrays2.Length) { string str4 = strArrays2[num1]; num2 = str4.IndexOf('\f'); if (num2 != -1) { str4 = str4.Substring(0, num2); } string str5 = string.Concat(stringBuilder.ToString(), " ", str4); try { stringWidth = this.font.PDFBoxFont.getStringWidth(str5) / 1000f * this.fontSize; } catch (Exception exception) { } } flag = (num1 >= (int)strArrays2.Length ? false : stringWidth < width); } else { break; } }while (flag); if (single < (float)num) { pDPage = new PDPage(lETTER); pDDocument.addPage(pDPage); if (pDPageContentStream != null) { pDPageContentStream.endText(); pDPageContentStream.close(); } pDPageContentStream = new PDPageContentStream(pDDocument, pDPage); pDPageContentStream.setFont(this.font.PDFBoxFont, this.fontSize); pDPageContentStream.beginText(); single = pDPage.getMediaBox().getHeight() - (float)num + height; pDPageContentStream.newLineAtOffset((float)num, single); } if (pDPageContentStream == null) { throw new java.io.IOException("Error:Expected non-null content stream."); } pDPageContentStream.newLineAtOffset(0f, -height); single = single - height; try { pDPageContentStream.showText(stringBuilder.ToString()); if (flag2) { pDPage = new PDPage(lETTER); pDDocument.addPage(pDPage); pDPageContentStream.endText(); pDPageContentStream.close(); pDPageContentStream = new PDPageContentStream(pDDocument, pDPage); pDPageContentStream.setFont(this.font.PDFBoxFont, this.fontSize); pDPageContentStream.beginText(); single = pDPage.getMediaBox().getHeight() - (float)num + height; pDPageContentStream.newLineAtOffset((float)num, single); } } catch (Exception exception1) { } } } if (flag1) { pDDocument.addPage(pDPage); } if (pDPageContentStream != null) { pDPageContentStream.endText(); pDPageContentStream.close(); } if (PDFHelper.AddStamp) { pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument); } try { pDDocument.save(pdfFile); } catch (Exception exception3) { Exception exception2 = exception3; throw new PDFToolkitException(exception2.Message, exception2.InnerException); } } catch (Exception exception5) { Exception exception4 = exception5; if (pDDocument != null) { pDDocument.close(); } throw exception4; } }
public void SetSize(PageSize pageSize) { this.size = PDFHelper.GetPDFRectangle(pageSize); }
public bool AddAnnotation(PDFAnnotation annotation, PDFDocument doc) { bool result; try { List annotations = this.PDFBoxPage.getAnnotations(); PDRectangle rectangle = new PDRectangle(annotation.Position.X, this.MediaBox.Height - annotation.Position.Y - annotation.Position.Height, annotation.Position.Width, annotation.Position.Height); annotation.pdfAnotation.setRectangle(rectangle); bool flag = annotation.type == PDFAnnotationType.PDFAnnotationLine; if (flag) { PDAnnotationLine pDAnnotationLine = (PDAnnotationLine)annotation.pdfAnotation; float[] array = new float[4]; switch (annotation.Direction) { case PDFDirection.DIAGONALLEFTUP: array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); break; case PDFDirection.DIAGONALRIGHTUP: array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); break; case PDFDirection.DIAGONALRIGHTDOWN: array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); break; case PDFDirection.DIAGONALLEFTDOWN: array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); break; } pDAnnotationLine.setLine(array); annotations.add(pDAnnotationLine); } else { bool flag2 = annotation.type == PDFAnnotationType.PDFAnnotationTextMarkup; if (flag2) { PDAnnotationTextMarkup pDAnnotationTextMarkup = (PDAnnotationTextMarkup)annotation.pdfAnotation; float[] array2 = new float[8]; array2[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array2[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getUpperRightY() - 2f; array2[2] = annotation.Position.PDFBoxRectangle.getUpperRightX(); array2[3] = array2[1]; array2[4] = array2[0]; array2[5] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - 2f; array2[6] = array2[2]; array2[7] = array2[5]; pDAnnotationTextMarkup.setQuadPoints(array2); annotations.add(pDAnnotationTextMarkup); } else { bool flag3 = annotation.type == PDFAnnotationType.PDFAnnotationLink; if (flag3) { PDAnnotationLink pDAnnotationLink = (PDAnnotationLink)annotation.pdfAnotation; bool flag4 = !string.IsNullOrEmpty(annotation.LinkURL); if (flag4) { PDActionURI pDActionURI = new PDActionURI(); pDActionURI.setURI(annotation.LinkURL); pDAnnotationLink.setAction(pDActionURI); } else { Console.WriteLine("The PDFAnnotationLink has no LinkURL property. Set this property for the link to work well."); } annotations.add(pDAnnotationLink); } else { bool flag5 = annotation.type == PDFAnnotationType.PDFAnnotationRubberStamp; if (flag5) { PDAnnotationRubberStamp pDAnnotationRubberStamp = (PDAnnotationRubberStamp)annotation.pdfAnotation; pDAnnotationRubberStamp.setName("TopSecret"); pDAnnotationRubberStamp.setAppearance(PDFHelper.GetRubberStampAppearance(doc, annotation.Position, annotation.SubType)); pDAnnotationRubberStamp.setRectangle(rectangle); annotations.add(pDAnnotationRubberStamp); } else { annotations.add(annotation.pdfAnotation); } } } } result = true; } catch (Exception ex) { throw new PDFToolkitException(ex.Message, ex); } return(result); }
public PDFPage(PageSize pageSize) { this.page = new PDPage(); this.MediaBox = PDFHelper.GetPDFRectangle(pageSize); }
private static string CreateLogo(string stampText, int angle) { RotateFlipType rotateFlipType; string str; string str1 = ""; try { int num = angle; if (num == 90) { rotateFlipType = RotateFlipType.Rotate270FlipNone; } else if (num == 180) { rotateFlipType = RotateFlipType.Rotate180FlipNone; } else { rotateFlipType = (num == 270 ? RotateFlipType.Rotate90FlipNone : RotateFlipType.RotateNoneFlipNone); } using (Bitmap bitmap = new Bitmap(1, 1)) { int num1 = 0; int num2 = 0; System.Drawing.Font font = new System.Drawing.Font("Times New Roman", 10f); using (Graphics graphic = Graphics.FromImage(bitmap)) { SizeF sizeF = graphic.MeasureString(stampText, font); num1 = Math.Max((int)sizeF.Width, 250); sizeF = graphic.MeasureString(stampText, font); num2 = Math.Max((int)sizeF.Height, 30); using (Bitmap bitmap1 = new Bitmap(bitmap, new Size(num1, num2))) { using (Graphics graphic1 = Graphics.FromImage(bitmap1)) { graphic1.Clear(Color.Transparent); graphic1.InterpolationMode = InterpolationMode.HighQualityBilinear; graphic1.SmoothingMode = SmoothingMode.AntiAlias; graphic1.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; graphic1.DrawString(stampText, font, new SolidBrush(Color.Black), 0f, 0f); graphic1.Flush(); } if (rotateFlipType != RotateFlipType.RotateNoneFlipNone) { bitmap1.RotateFlip(rotateFlipType); } str1 = Path.Combine(Path.GetTempPath(), "aquaforest\\pdftoolkit\\stamp.png"); PDFHelper.CheckOutputFolder(Path.GetDirectoryName(str1)); bitmap1.Save(str1, ImageFormat.Png); } } } str = str1; } catch (Exception exception1) { Exception exception = exception1; Console.WriteLine(string.Concat(exception.Message, Environment.NewLine, exception.StackTrace)); str = str1; } return(str); }
private static void Check30DayLicence(int numberOfDays, bool IsTrial) { string str = "{YTh394jhu9JD31O8923XMOAL1}"; string str1 = "{5O2sTNBpaXdVVcMw13083pFWkL}"; string value = ""; string value1 = ""; try { using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Classes\\OpID")) { value = (string)registryKey.GetValue(str); value1 = (string)registryKey.GetValue(str1); } if ((string.IsNullOrEmpty(value1) ? true : string.IsNullOrEmpty(value))) { throw new PDFToolkitException(); } } catch (Exception exception) { MessageBox.Show("License tampered with!"); Environment.Exit(1); } if ((value != "YyNTY4dfltMT456N5M0JDDoyNj9EYzNTBENDg4QTg0QgddsQTMiAQjAzREUc3OEo3RCRjUxN0MD7MjAx0MkM1RkTUxNUNBQURE3QjUyN0ZGRUM" ? true : value1 != "ZBMzBENzYMAxMiAU1NzYwDowMjM0wOTZERkNCMDowMENUJEDtQkxNERc1MOTcvMjjFEREEwOUDNjgxRNUQxQjQxNzY3NTkIxODUFGT9aNG7nwNkIwR")) { string[] strArrays = PDFHelper.DecryptDate(value).Split(new char[] { ';' }); value = strArrays[0].ToString(); strArrays = PDFHelper.DecryptDate(value1).Split(new char[] { ';' }); value1 = strArrays[0].ToString(); string str2 = strArrays[1].ToString(); string str3 = strArrays[2].ToString(); if (str2 == PDFToolkit.LicenseKey) { DateTime dateTime = DateTime.Parse(value); DateTime dateTime1 = DateTime.Parse(value1); if ((DateTime.Compare(DateTime.Now, dateTime) < 0 || DateTime.Compare(dateTime1, DateTime.Now) > 0 ? true : DateTime.Compare(dateTime, dateTime1) < 0)) { MessageBox.Show("License tampered with! Please change your system date to continue."); Environment.Exit(1); } if (DateTime.Compare(DateTime.Now, dateTime1.AddDays((double)numberOfDays)) > 0) { DateTime dateTime2 = new DateTime(1901, 1, 1); try { using (RegistryKey registryKey1 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Classes\\OpID")) { registryKey1.SetValue(str1, PDFHelper.EncryptDate(string.Format("{0};{1};{2}", new object[] { dateTime2.ToString(), PDFToolkit.LicenseKey, PDFToolkit.LicenseKey, IsTrial.ToString() })), RegistryValueKind.String); } bool flag = false; using (RegistryKey registryKey2 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Classes\\OpID\\Data", true)) { string[] valueNames = registryKey2.GetValueNames(); for (int i = 0; i < (int)valueNames.Length; i++) { string str4 = valueNames[i]; if ((string)registryKey2.GetValue(str4) != "AxMiAREEwNUQxQjc1MjM0OO1NzYwQGOUQxNzY3NTkkZBTwJEDMzBENRURDNjgxRjFEZERkNCMT9aNG7ncvMjwMDowMowMDtENUzYxNEIxODUwNkITF") { if (PDFToolkit.LicenseKey == PDFHelper.DecryptDate((string)registryKey2.GetValue(str4)).Split(new char[] { ';' })[1].ToString()) { flag = true; break; } } } } if (!flag) { using (RegistryKey registryKey3 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Classes\\OpID\\Data")) { Guid guid = Guid.NewGuid(); registryKey3.SetValue(guid.ToString(), PDFHelper.EncryptDate(string.Format("{0};{1};{2}", dateTime2.ToString(), PDFToolkit.LicenseKey, IsTrial.ToString()))); } } } catch (Exception exception1) { MessageBox.Show(exception1.Message); Environment.Exit(1); } MessageBox.Show(string.Format("This message is being displayed because either your {0} day license has expired or the license has been tampered with.\n\nIf you would like to purchase a new license then please contact \"[email protected]\".", numberOfDays)); Environment.Exit(1); } } else { using (RegistryKey registryKey4 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Classes\\OpID", true)) { registryKey4.SetValue(str1, PDFHelper.EncryptDate(string.Format("{0};{1};{2}", DateTime.Now, PDFToolkit.LicenseKey, IsTrial.ToString()))); } } } else { using (RegistryKey registryKey5 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Classes\\OpID", true)) { registryKey5.SetValue(str1, PDFHelper.EncryptDate(string.Format("{0};{1};{2}", DateTime.Now, PDFToolkit.LicenseKey, IsTrial.ToString()))); } } try { using (RegistryKey registryKey6 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Classes\\OpID")) { DateTime now = DateTime.Now; registryKey6.SetValue(str, PDFHelper.EncryptDate(now.ToString()), RegistryValueKind.String); } } catch (Exception exception2) { MessageBox.Show(exception2.Message); Environment.Exit(1); } }