internal static PDDocument AddTrialStampIfNecessary(PDDocument pdfFile, bool addJavaScript) { if (PDFHelper.AddStamp) { PDFont pDFont = PDTrueTypeFont.load(pdfFile, new java.io.File("C:\\Windows\\Fonts\\Arial.ttf"), new WinAnsiEncoding()); foreach (PDPage page in pdfFile.getPages()) { PDPageContentStream pDPageContentStream = new PDPageContentStream(pdfFile, page, PDPageContentStream.AppendMode.APPEND, true); pDPageContentStream.setFont(pDFont, 14f); pDPageContentStream.beginText(); pDPageContentStream.newLineAtOffset(100f, page.getMediaBox().getHeight() - 100f); pDPageContentStream.showText("Created with a trial copy of Aquaforest PDF Toolkit"); pDPageContentStream.endText(); pDPageContentStream.close(); } } return(pdfFile); }
private void EmbedFonts(bool doType1) { bool flag = false; PDTrueTypeFont pDTrueTypeFont = null; List <PDFAFontsEmbedded> pDFAFontsEmbeddeds = new List <PDFAFontsEmbedded>(); foreach (PDPage page in this.doc.getPages()) { PDResources resources = page.getResources(); Iterator iterator = resources.getFontNames().iterator(); while (iterator.hasNext()) { PDFont font = null; try { font = resources.getFont((COSName)iterator.next()); PDFontDescriptor fontDescriptor = font.getFontDescriptor(); if (font.isEmbedded()) { continue; } else if (font.getSubType().ToLower().Contains("type1") & doType1) { string fontFile = this.GetFontFile(font.getName()); if (fontFile != null) { if (( from t in pDFAFontsEmbeddeds where t.FontName == fontFile select t).Count <PDFAFontsEmbedded>() > 0) { ( from t in pDFAFontsEmbeddeds where t.FontName == fontFile select t.fontDecriptor).SingleOrDefault <PDFont>(); font.getCOSObject().setName(COSName.SUBTYPE, "TrueType"); } else { InputStream fileInputStream = new FileInputStream(string.Concat("C:\\Windows\\Fonts\\", fontFile)); fontDescriptor.setFontFile(new PDStream(this.doc, fileInputStream)); PDFAFontsEmbedded pDFAFontsEmbedded = new PDFAFontsEmbedded() { FontName = fontFile }; font.getCOSObject().setName(COSName.SUBTYPE, "TrueType"); pDFAFontsEmbedded.fontDecriptor = pDTrueTypeFont; pDFAFontsEmbeddeds.Add(pDFAFontsEmbedded); flag = true; } } } else if (font.getSubType().ToLower().Contains("true")) { string readableFontName = this.GetReadableFontName(font.getName()); string str = this.GetFontFile(readableFontName); string str1 = string.Concat("C:\\Windows\\Fonts\\", str); if (System.IO.File.Exists(str1)) { if (( from t in pDFAFontsEmbeddeds where t.FontName == str select t).Count <PDFAFontsEmbedded>() <= 0) { InputStream inputStream = new FileInputStream(str1); fontDescriptor.setFontFile2(new PDStream(this.doc, inputStream)); PDFAFontsEmbedded pDFAFontsEmbedded1 = new PDFAFontsEmbedded() { FontName = str, fontDecriptor = pDTrueTypeFont }; pDFAFontsEmbeddeds.Add(pDFAFontsEmbedded1); flag = true; } } } } catch (Exception exception) { } } } }
private PDFTrueTypeFont(PDFDocument document, string font) { PDFTrueTypeFont.stringName = font; PDFTrueTypeFont.trueTypeFont = PDTrueTypeFont.loadTTF(document.PDFBoxDocument, new File(font)); }