/* (non-Javadoc) * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String) */ public virtual IList <CssDeclaration> Convert(IElementNode element, String value) { String cssValueEquivalent = null; String cssPropertyEquivalent = null; String elementName = element.Name(); if (TagConstants.FONT.Equals(elementName)) { cssPropertyEquivalent = CssConstants.FONT_SIZE; try { bool signedValue = value.Contains("-") || value.Contains("+"); int htmlFontSize = System.Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture); if (signedValue) { htmlFontSize = 3 + htmlFontSize; } if (htmlFontSize < 2) { cssValueEquivalent = CssConstants.X_SMALL; } else { if (htmlFontSize > 6) { cssValueEquivalent = "48px"; } else { if (htmlFontSize == 2) { cssValueEquivalent = CssConstants.SMALL; } else { if (htmlFontSize == 3) { cssValueEquivalent = CssConstants.MEDIUM; } else { if (htmlFontSize == 4) { cssValueEquivalent = CssConstants.LARGE; } else { if (htmlFontSize == 5) { cssValueEquivalent = CssConstants.X_LARGE; } else { if (htmlFontSize == 6) { cssValueEquivalent = CssConstants.XX_LARGE; } } } } } } } } catch (FormatException) { cssValueEquivalent = CssConstants.MEDIUM; } } else { if (TagConstants.HR.Equals(elementName)) { cssPropertyEquivalent = CssConstants.HEIGHT; cssValueEquivalent = value + CssConstants.PX; } } return(JavaUtil.ArraysAsList(new CssDeclaration(cssPropertyEquivalent, cssValueEquivalent))); }
public PageRangePartAnd(params PageRange.IPageRangePart[] conditions) { this.conditions.AddAll(JavaUtil.ArraysAsList(conditions)); }
public virtual void TestEquals() { Glyph glyph = new Glyph(200, 200, 200); GlyphLine.ActualText actualText = new GlyphLine.ActualText("-"); GlyphLine one = new GlyphLine(new List <Glyph>(JavaUtil.ArraysAsList(glyph)), new List <GlyphLine.ActualText >(JavaUtil.ArraysAsList(actualText)), 0, 1); GlyphLine two = new GlyphLine(new List <Glyph>(JavaUtil.ArraysAsList(glyph)), new List <GlyphLine.ActualText >(JavaUtil.ArraysAsList(actualText)), 0, 1); one.Add(glyph); two.Add(glyph); one.end++; two.end++; NUnit.Framework.Assert.IsTrue(one.Equals(two)); }
/// <summary>Constructs a PDF Collection Sort Dictionary.</summary> /// <param name="keys">the keys of the fields that will be used to sort entries</param> public PdfCollectionSort(String[] keys) : this(new PdfDictionary()) { GetPdfObject().Put(PdfName.S, new PdfArray(JavaUtil.ArraysAsList(keys), true)); }
public virtual void SplitDocumentTest04() { String inputFileName = sourceFolder + "iphone_user_guide.pdf"; PdfDocument inputPdfDoc = new PdfDocument(new PdfReader(inputFileName)); PageRange pageRange1 = new PageRange("even & 80-").AddPageSequence(4, 15).AddSinglePage(18).AddPageSequence (1, 2); PageRange pageRange2 = new PageRange("99,98").AddPageSequence(70, 99); IList <PdfDocument> splitDocuments = new _PdfSplitter_188(inputPdfDoc).ExtractPageRanges(JavaUtil.ArraysAsList (pageRange1, pageRange2)); foreach (PdfDocument pdfDocument in splitDocuments) { pdfDocument.Close(); } for (int i = 1; i <= 2; i++) { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "splitDocument4_" + i + ".pdf", sourceFolder + "cmp/" + "cmp_splitDocument4_" + i.ToString() + ".pdf", destinationFolder, "diff_" )); } }
private static PdfDictionary CopyObject(PdfDictionary source, PdfDictionary destPage, bool parentChangePg, StructureTreeCopier.StructElemCopyingParams copyingParams) { PdfDictionary copied; if (copyingParams.IsCopyFromDestDocument()) { //TODO: detect wether object is needed to be cloned at all copied = source.Clone(ignoreKeysForClone); if (source.IsIndirect()) { copied.MakeIndirect(copyingParams.GetToDocument()); } PdfDictionary pg = source.GetAsDictionary(PdfName.Pg); if (pg != null) { if (copyingParams.IsCopyFromDestDocument()) { if (pg != destPage) { copied.Put(PdfName.Pg, destPage); parentChangePg = true; } else { parentChangePg = false; } } } } else { copied = source.CopyTo(copyingParams.GetToDocument(), ignoreKeysForCopy, true); PdfDictionary obj = source.GetAsDictionary(PdfName.Obj); if (obj != null) { // Link annotations could be not added to the toDocument, so we need to identify this case. // When obj.copyTo is called, and annotation was already copied, we would get this already created copy. // If it was already copied and added, /P key would be set. Otherwise /P won't be set. obj = obj.CopyTo(copyingParams.GetToDocument(), JavaUtil.ArraysAsList(PdfName.P), false); copied.Put(PdfName.Obj, obj); } PdfDictionary nsDict = source.GetAsDictionary(PdfName.NS); if (nsDict != null) { PdfDictionary copiedNsDict = CopyNamespaceDict(nsDict, copyingParams); copied.Put(PdfName.NS, copiedNsDict); } PdfDictionary pg = source.GetAsDictionary(PdfName.Pg); if (pg != null) { PdfDictionary pageAnalog = copyingParams.GetPage2page().Get(pg); if (pageAnalog == null) { pageAnalog = destPage; parentChangePg = true; } else { parentChangePg = false; } copied.Put(PdfName.Pg, pageAnalog); } } PdfObject k = source.Get(PdfName.K); if (k != null) { if (k.IsArray()) { PdfArray kArr = (PdfArray)k; PdfArray newArr = new PdfArray(); for (int i = 0; i < kArr.Size(); i++) { PdfObject copiedKid = CopyObjectKid(kArr.Get(i), copied, destPage, parentChangePg, copyingParams); if (copiedKid != null) { newArr.Add(copiedKid); } } if (!newArr.IsEmpty()) { if (newArr.Size() == 1) { copied.Put(PdfName.K, newArr.Get(0)); } else { copied.Put(PdfName.K, newArr); } } } else { PdfObject copiedKid = CopyObjectKid(k, copied, destPage, parentChangePg, copyingParams); if (copiedKid != null) { copied.Put(PdfName.K, copiedKid); } } } return copied; }
public override IList <Rectangle> InitElementAreas(LayoutArea area) { return(JavaUtil.ArraysAsList(new Rectangle(area.GetBBox()).SetWidth(area.GetBBox().GetWidth() / 2), new Rectangle (area.GetBBox()).SetWidth(area.GetBBox().GetWidth() / 2).MoveRight(area.GetBBox().GetWidth() / 2))); }
public virtual void TestBengaliScript() { String imgPath = TEST_IMAGES_DIRECTORY + "bengali_01.jpeg"; FileInfo file = new FileInfo(imgPath); String expected = "ইংরজে"; tesseractReader.SetTesseract4OcrEngineProperties(tesseractReader.GetTesseract4OcrEngineProperties().SetPathToTessData (new FileInfo(SCRIPT_TESS_DATA_DIRECTORY))); // correct result with specified spanish language NUnit.Framework.Assert.IsTrue(GetTextFromPdf(tesseractReader, file, 1, JavaCollectionsUtil.SingletonList <String >("Bengali"), JavaUtil.ArraysAsList(FREE_SANS_FONT_PATH, KOSUGI_FONT_PATH)).StartsWith(expected)); }
public virtual void TextJapaneseText() { String imgPath = TEST_IMAGES_DIRECTORY + "japanese_01.png"; FileInfo file = new FileInfo(imgPath); String expected = "日 本 語\n文法"; // correct result with specified japanese language NUnit.Framework.Assert.AreEqual(expected, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList("jpn" ), KOSUGI_FONT_PATH)); }
public virtual void TestChinese() { String imgPath = TEST_IMAGES_DIRECTORY + "chinese_01.jpg"; FileInfo file = new FileInfo(imgPath); String expected = "你 好\nni hao"; // correct result with specified spanish language NUnit.Framework.Assert.AreEqual(expected, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList("chi_sim" , "chi_tra"), NOTO_SANS_SC_FONT_PATH)); NUnit.Framework.Assert.AreEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("chi_sim"), NOTO_SANS_SC_FONT_PATH)); NUnit.Framework.Assert.AreEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("chi_tra"), NOTO_SANS_SC_FONT_PATH)); // incorrect result when languages are not specified // or languages were specified in the wrong order NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("chi_sim"))); NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("chi_tra"))); NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList("chi_sim" , "chi_tra"))); NUnit.Framework.Assert.IsFalse(GetTextFromPdf(tesseractReader, file, new List <String>()).Contains(expected )); }
public virtual void TestSpanishWithTessData() { String imgPath = TEST_IMAGES_DIRECTORY + "spanish_01.jpg"; FileInfo file = new FileInfo(imgPath); String expectedSpanish = "Aquí\nhablamos\nespañol"; // correct result with specified spanish language NUnit.Framework.Assert.AreEqual(expectedSpanish, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil .SingletonList <String>("spa"))); NUnit.Framework.Assert.AreEqual(expectedSpanish, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList ("spa", "eng"))); NUnit.Framework.Assert.AreEqual(expectedSpanish, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList ("eng", "spa"))); // incorrect result when languages are not specified // or languages were specified in the wrong order NUnit.Framework.Assert.AreNotEqual(expectedSpanish, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil .SingletonList <String>("eng"))); NUnit.Framework.Assert.AreNotEqual(expectedSpanish, GetTextFromPdf(tesseractReader, file, new List <String> ())); }
public virtual void TestHindiTextWithEng() { String imgPath = TEST_IMAGES_DIRECTORY + "hindi_02.jpg"; FileInfo file = new FileInfo(imgPath); String expected = "मानक हनिदी\nHindi"; // correct result with specified arabic+english languages NUnit.Framework.Assert.AreEqual(expected, GetTextFromPdf(tesseractReader, file, JavaUtil.ArraysAsList("hin" , "eng"), NOTO_SANS_FONT_PATH)); // incorrect result without specified english language NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("hin"), NOTO_SANS_FONT_PATH)); // incorrect result when languages are not specified // or languages were specified in the wrong order NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, JavaCollectionsUtil.SingletonList <String>("eng"), NOTO_SANS_FONT_PATH)); NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file)); NUnit.Framework.Assert.AreNotEqual(expected, GetTextFromPdf(tesseractReader, file, new List <String>(), NOTO_SANS_FONT_PATH )); }
public virtual void CompareMultiLangImage() { String testName = "compareMultiLangImage"; String filename = "multilang"; String expectedPdfPath = TEST_DOCUMENTS_DIRECTORY + filename + "_" + testFileTypeName + ".pdf"; String resultPdfPath = GetTargetDirectory() + filename + "_" + testName + "_" + testFileTypeName + ".pdf"; try { Tesseract4OcrEngineProperties properties = tesseractReader.GetTesseract4OcrEngineProperties(); properties.SetTextPositioning(TextPositioning.BY_WORDS); properties.SetPathToTessData(GetTessDataDirectory()); properties.SetPageSegMode(3); tesseractReader.SetTesseract4OcrEngineProperties(properties); DoOcrAndSavePdfToPath(tesseractReader, TEST_IMAGES_DIRECTORY + filename + ".jpg", resultPdfPath, JavaUtil.ArraysAsList ("eng", "deu", "spa"), DeviceCmyk.BLACK); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultPdfPath, expectedPdfPath, TEST_DOCUMENTS_DIRECTORY , "diff_")); } finally { NUnit.Framework.Assert.AreEqual(TextPositioning.BY_WORDS, tesseractReader.GetTesseract4OcrEngineProperties ().GetTextPositioning()); NUnit.Framework.Assert.AreEqual(3, tesseractReader.GetTesseract4OcrEngineProperties().GetPageSegMode().Value ); } }
/// <summary>Adds an unspecified amount of tabstop elements as properties to the Paragraph.</summary> /// <param name="tabStops"> /// the /// <see cref="TabStop">tabstop(s)</see> /// to be added as properties /// </param> /// <returns>this Paragraph</returns> /// <seealso cref="TabStop"/> public virtual iText.Layout.Element.Paragraph AddTabStops(params TabStop[] tabStops) { AddTabStopsAsProperty(JavaUtil.ArraysAsList(tabStops)); return(this); }
/* (non-Javadoc) * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String) */ public virtual IList <CssDeclaration> Convert(IElementNode element, String value) { return(JavaUtil.ArraysAsList(new CssDeclaration(CssConstants.DIRECTION, value))); }
public UncoloredTilingPattern(PdfColorSpace underlyingColorSpace) : base(new PdfArray(JavaUtil.ArraysAsList(PdfName.Pattern, underlyingColorSpace.GetPdfObject()))) { }
/* (non-Javadoc) * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String) */ public virtual IList <CssDeclaration> Convert(IElementNode element, String value) { return(JavaUtil.ArraysAsList(new CssDeclaration(CssConstants.HEIGHT, "2px"), new CssDeclaration(CssConstants .BORDER_WIDTH, "0"), new CssDeclaration(CssConstants.BACKGROUND_COLOR, "gray"))); }
private static void DoImageToPdfOcr(IOcrEngine tesseractReader, FileInfo imageFile) { OcrPdfCreator ocrPdfCreator = new OcrPdfCreator(tesseractReader); ocrPdfCreator.CreatePdf(JavaUtil.ArraysAsList(imageFile), new PdfWriter(new MemoryStream())); }