コード例 #1
0
 /// <summary>Add temporary font from @font-face.</summary>
 /// <param name="fontProgram">the font program</param>
 /// <param name="encoding">the encoding</param>
 /// <param name="alias">the alias</param>
 /// <param name="unicodeRange">the unicode range</param>
 public virtual void AddTemporaryFont(FontProgram fontProgram, String encoding, String alias, Range unicodeRange
                                      )
 {
     if (tempFonts == null)
     {
         tempFonts = new FontSet();
     }
     tempFonts.AddFont(fontProgram, encoding, alias, unicodeRange);
 }
コード例 #2
0
        /// <summary>
        /// Creates the PDF file.
        /// </summary>
        /// <param name="src">the path to the source HTML file</param>
        /// <param name="font">the path to an extra font</param>
        /// <param name="dest">the path to the resulting PDF</param>
        public void CreatePdf(String src, String font, String dest)
        {
            ConverterProperties properties   = new ConverterProperties();
            FontProvider        fontProvider = new DefaultFontProvider();
            FontProgram         fontProgram  = FontProgramFactory.CreateFont(font);

            fontProvider.AddFont(fontProgram);
            properties.SetFontProvider(fontProvider);
            HtmlConverter.ConvertToPdf(new FileInfo(src), new FileInfo(dest), properties);
        }
コード例 #3
0
 internal static void ApplyKerning(FontProgram fontProgram, GlyphLine text)
 {
     if (!TYPOGRAPHY_MODULE_INITIALIZED)
     {
         logger.Warn(typographyNotFoundException);
     }
     else
     {
         CallMethod(TYPOGRAPHY_PACKAGE + SHAPER, APPLY_KERNING, new Type[] { typeof(FontProgram), typeof(GlyphLine) }, fontProgram, text);
     }
 }
コード例 #4
0
 public virtual String GetDefaultEncoding(FontProgram fontProgram)
 {
     if (fontProgram is Type1Font)
     {
         return(PdfEncodings.WINANSI);
     }
     else
     {
         return(PdfEncodings.IDENTITY_H);
     }
 }
コード例 #5
0
 internal static void ApplyOtfScript(FontProgram fontProgram, GlyphLine text, UnicodeScript?script)
 {
     if (!TYPOGRAPHY_MODULE_INITIALIZED)
     {
         logger.Warn(typographyNotFoundException);
     }
     else
     {
         CallMethod(TYPOGRAPHY_PACKAGE + SHAPER, APPLY_OTF_SCRIPT, new Type[] { typeof(TrueTypeFont), typeof(GlyphLine
                                                                                                             ), typeof(UnicodeScript?) }, fontProgram, text, script);
     }
 }
コード例 #6
0
 /// <summary>
 /// Get from cache or create a new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </summary>
 /// <param name="fontInfo">
 /// font info, to create
 /// <see cref="iText.IO.Font.FontProgram"/>
 /// and
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </param>
 /// <param name="tempFonts">Set of temporary fonts.</param>
 /// <returns>
 /// cached or new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </returns>
 public virtual PdfFont GetPdfFont(FontInfo fontInfo, FontSet tempFonts)
 {
     if (pdfFonts.ContainsKey(fontInfo))
     {
         return(pdfFonts.Get(fontInfo));
     }
     else
     {
         FontProgram fontProgram = null;
         if (tempFonts != null)
         {
             fontProgram = tempFonts.GetFontProgram(fontInfo);
         }
         if (fontProgram == null)
         {
             fontProgram = fontSet.GetFontProgram(fontInfo);
         }
         PdfFont pdfFont;
         try {
             if (fontProgram == null)
             {
                 if (fontInfo.GetFontData() != null)
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontData(), GetDefaultCacheFlag());
                 }
                 else
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontName(), GetDefaultCacheFlag());
                 }
             }
             String encoding = fontInfo.GetEncoding();
             if (encoding == null || encoding.Length == 0)
             {
                 encoding = GetDefaultEncoding(fontProgram);
             }
             pdfFont = PdfFontFactory.CreateFont(fontProgram, encoding, GetDefaultEmbeddingFlag());
         }
         catch (System.IO.IOException e) {
             // Converting checked exceptions to unchecked RuntimeException (java-specific comment).
             //
             // FontProvider is usually used in highlevel API, which requests fonts in deep underlying logic.
             // IOException would mean that font is chosen and it is supposed to exist, however it cannot be read.
             // Using fallbacks in such situations would make FontProvider less intuitive.
             //
             // Even though softening of checked exceptions can be handled at higher levels in order to let
             // the caller of this method know that font creation failed, we prefer to avoid bloating highlevel API
             // and avoid making higher level code depend on low-level code because of the exceptions handling.
             throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
         }
         pdfFonts.Put(fontInfo, pdfFont);
         return(pdfFont);
     }
 }
コード例 #7
0
 //            Shaper.applyOtfScript((TrueTypeFont)fontProgram, text, script);
 internal static void ApplyKerning(FontProgram fontProgram, GlyphLine text)
 {
     if (!TYPOGRAPHY_MODULE_INITIALIZED)
     {
         logger.Warn("Cannot find advanced typography module, which was implicitly required by one of the layout properties"
                     );
     }
     else
     {
         CallMethod(TYPOGRAPHY_PACKAGE + SHAPER, APPLY_KERNING, new Type[] { typeof(FontProgram), typeof(GlyphLine) }, fontProgram, text);
     }
 }
コード例 #8
0
 internal static void ApplyOtfScript(FontProgram fontProgram, GlyphLine text, UnicodeScript?script)
 {
     if (!TYPOGRAPHY_MODULE_INITIALIZED)
     {
         logger.Warn("Cannot find advanced typography module, which was implicitly required by one of the layout properties"
                     );
     }
     else
     {
         CallMethod(TYPOGRAPHY_PACKAGE + SHAPER, APPLY_OTF_SCRIPT, new Type[] { typeof(TrueTypeFont), typeof(GlyphLine
                                                                                                             ), typeof(UnicodeScript?) }, fontProgram, text, script);
     }
 }
コード例 #9
0
 /// <exception cref="System.IO.IOException"/>
 public static PdfFont CreateFont(FontProgram fontProgram, String encoding, bool embedded)
 {
     if (fontProgram == null)
     {
         return(null);
     }
     else
     {
         if (fontProgram is Type1Font)
         {
             return(new PdfType1Font((Type1Font)fontProgram, encoding, embedded));
         }
         else
         {
             if (fontProgram is TrueTypeFont)
             {
                 if (PdfEncodings.IDENTITY_H.Equals(encoding) || PdfEncodings.IDENTITY_V.Equals(encoding))
                 {
                     return(new PdfType0Font((TrueTypeFont)fontProgram, encoding));
                 }
                 else
                 {
                     return(new PdfTrueTypeFont((TrueTypeFont)fontProgram, encoding, embedded));
                 }
             }
             else
             {
                 if (fontProgram is CidFont)
                 {
                     if (((CidFont)fontProgram).CompatibleWith(encoding))
                     {
                         return(new PdfType0Font((CidFont)fontProgram, encoding));
                     }
                     else
                     {
                         return(null);
                     }
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
コード例 #10
0
 /// <summary>Creates a font and adds it to the context.</summary>
 /// <param name="fontFamily">the font family</param>
 /// <param name="src">the source of the font</param>
 /// <returns>true, if successful</returns>
 private bool CreateFont(String fontFamily, FontFace.FontFaceSrc src)
 {
     if (!SupportedFontFormat(src.format))
     {
         return(false);
     }
     else
     {
         if (src.isLocal)
         {
             // to method with lazy initialization
             ICollection <FontInfo> fonts = context.GetFontProvider().GetFontSet().Get(src.src);
             if (fonts.Count > 0)
             {
                 foreach (FontInfo fi in fonts)
                 {
                     context.AddTemporaryFont(fi, fontFamily);
                 }
                 //
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             try {
                 // Cache at resource resolver level only, at font level we will create font in any case.
                 // The instance of fontProgram will be collected by GC if the is no need in it.
                 byte[] bytes = context.GetResourceResolver().RetrieveBytesFromResource(src.src);
                 if (bytes != null)
                 {
                     FontProgram fp = FontProgramFactory.CreateFont(bytes, false);
                     context.AddTemporaryFont(fp, PdfEncodings.IDENTITY_H, fontFamily);
                     return(true);
                 }
             }
             catch (Exception) {
             }
             return(false);
         }
     }
 }
コード例 #11
0
 /// <summary>
 /// Get from cache or create a new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </summary>
 /// <param name="fontInfo">
 /// font info, to create
 /// <see cref="iText.IO.Font.FontProgram"/>
 /// and
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </param>
 /// <param name="tempFonts">Set of temporary fonts.</param>
 /// <returns>
 /// cached or new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </returns>
 public virtual PdfFont GetPdfFont(FontInfo fontInfo, FontSet tempFonts)
 {
     if (pdfFonts.ContainsKey(fontInfo))
     {
         return(pdfFonts.Get(fontInfo));
     }
     else
     {
         FontProgram fontProgram = null;
         if (tempFonts != null)
         {
             fontProgram = tempFonts.GetFontProgram(fontInfo);
         }
         if (fontProgram == null)
         {
             fontProgram = fontSet.GetFontProgram(fontInfo);
         }
         PdfFont pdfFont;
         try {
             if (fontProgram == null)
             {
                 if (fontInfo.GetFontData() != null)
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontData(), GetDefaultCacheFlag());
                 }
                 else
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontName(), GetDefaultCacheFlag());
                 }
             }
             String encoding = fontInfo.GetEncoding();
             if (encoding == null || encoding.Length == 0)
             {
                 encoding = GetDefaultEncoding(fontProgram);
             }
             pdfFont = PdfFontFactory.CreateFont(fontProgram, encoding, GetDefaultEmbeddingFlag());
         }
         catch (System.IO.IOException e) {
             throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
         }
         pdfFonts.Put(fontInfo, pdfFont);
         return(pdfFont);
     }
 }
コード例 #12
0
        public static void generatePDF()
        {
            // Base URI is required to resolve the path to source files
            ConverterProperties converterProperties = new ConverterProperties();

            using (var htmlStream = File.OpenRead(SRC))
            {
                if (File.Exists(DEST))
                {
                    File.Delete(DEST);
                }
                using (var pdfStream = File.OpenWrite(DEST))
                {
                    FontProvider fontProvider = new DefaultFontProvider();
                    FontProgram  fontProgram  = FontProgramFactory.CreateFont(FONT);
                    fontProvider.AddFont(fontProgram);
                    converterProperties.SetFontProvider(fontProvider);
                    HtmlConverter.ConvertToPdf(htmlStream, pdfStream, converterProperties);
                }
            }
        }
コード例 #13
0
        public void ProcessRequest(HttpContext context)
        {
            string[] FONTS =
            {
                // msjh.ttc[0], the first one ttf in msjh.ttc.
                @"C:\Windows\Fonts\msjh.ttc,0",
            };
            // If the POST body has uncoded symbols,such as "<" and ">",
            // it will be judged as potentially dangerous. And put the POST
            // body to Request.Unvalidated.Form.
            String HTML = context.Request.Unvalidated.Form["content"] == null ? context.Request.Form["content"]: context.Request.Unvalidated.Form["content"];

            // Check whether the HTML has content.
            if (HTML != null && HTML != "")
            {
                // Define the date as the pdf file name.
                String strDate  = DateTime.Now.ToString("yyyyMMddHHmmss");
                String filename = "D:\\" + strDate + ".pdf";

                ConverterProperties properties = new ConverterProperties();
                // Deal with font provider.
                FontProvider fontProvider = new DefaultFontProvider(false, false, false);
                foreach (string font in FONTS)
                {
                    FontProgram fontProgram = FontProgramFactory.CreateFont(font);
                    fontProvider.AddFont(fontProgram);
                }
                // Set font type
                properties.SetFontProvider(fontProvider);
                // Set the base uri (that is, the root) of the website.
                // HttpContext.Current.Server.MapPath("~") : the root of website.
                properties.SetBaseUri(HttpContext.Current.Server.MapPath("~"));

                // Convert html to pdf.
                HtmlConverter.ConvertToPdf(WebUtility.HtmlDecode(HTML), new FileStream(filename, FileMode.Create), properties);
                Download(filename, strDate + ".pdf");
            }
        }
コード例 #14
0
        /// <summary>Add not supported for auto creating FontPrograms.</summary>
        /// <remarks>
        /// Add not supported for auto creating FontPrograms.
        /// <p>
        /// Note,
        /// <see cref="FontInfo.GetAlias()"/>
        /// do not taken into account in
        /// <see cref="FontInfo.Equals(System.Object)"/>
        /// .
        /// The same font with different alias will not be replaced.
        /// Alias will replace original font family in font selector algorithm.
        /// </remarks>
        /// <param name="fontProgram">
        ///
        /// <see cref="iText.IO.Font.FontProgram"/>
        /// </param>
        /// <param name="encoding">
        /// FontEncoding for creating
        /// <see cref="iText.Kernel.Font.PdfFont"/>
        /// </param>
        /// <param name="alias">font alias.</param>
        /// <param name="unicodeRange">sets the specific range of characters to be used from the font</param>
        /// <returns>true, if font was successfully added, otherwise false.</returns>
        public bool AddFont(FontProgram fontProgram, String encoding, String alias, Range unicodeRange)
        {
            if (fontProgram == null)
            {
                return(false);
            }
            if (fontProgram is Type3Font)
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Layout.Font.FontSet));
                logger.Error(iText.IO.LogMessageConstant.TYPE3_FONT_CANNOT_BE_ADDED);
                return(false);
            }
            FontInfo fi = FontInfo.Create(fontProgram, encoding, alias, unicodeRange);

            if (AddFont(fi))
            {
                fontPrograms.Put(fi, fontProgram);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #15
0
 /// <exception cref="System.IO.IOException"/>
 public static PdfFont CreateFont(FontProgram fontProgram, String encoding)
 {
     return(CreateFont(fontProgram, encoding, DEFAULT_EMBEDDING));
 }
コード例 #16
0
        public static iText.Layout.Font.FontInfo Create(FontProgram fontProgram, String encoding, String alias)
        {
            FontProgramDescriptor descriptor = FontProgramDescriptorFactory.FetchDescriptor(fontProgram);

            return(new iText.Layout.Font.FontInfo(descriptor.GetFontName(), null, encoding, descriptor, alias));
        }
コード例 #17
0
        /// <exception cref="System.IO.IOException"/>
        public static PdfFont CreateFont(String path, String encoding, bool embedded, bool cached)
        {
            FontProgram fontProgram = FontProgramFactory.CreateFont(path, cached);

            return(CreateFont(fontProgram, encoding, embedded));
        }
コード例 #18
0
        /// <exception cref="System.IO.IOException"/>
        public static PdfFont CreateTtcFont(byte[] ttc, int ttcIndex, String encoding, bool embedded, bool cached)
        {
            FontProgram fontProgram = FontProgramFactory.CreateFont(ttc, ttcIndex, cached);

            return(CreateFont(fontProgram, encoding, embedded));
        }
コード例 #19
0
 /// <summary>Add not supported for auto creating FontPrograms.</summary>
 /// <param name="fontProgram">
 ///
 /// <see cref="iText.IO.Font.FontProgram"/>
 /// </param>
 /// <param name="encoding">
 /// FontEncoding for creating
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </param>
 /// <returns>true, if font was successfully added, otherwise false.</returns>
 public bool AddFont(FontProgram fontProgram, String encoding)
 {
     return(AddFont(fontProgram, encoding, null));
 }
コード例 #20
0
 public static iText.Layout.Font.FontInfo Create(FontProgram fontProgram, String encoding, String alias)
 {
     return(Create(fontProgram, encoding, alias, null));
 }
コード例 #21
0
 public virtual bool AddFont(FontProgram fontProgram)
 {
     return(AddFont(fontProgram, GetDefaultEncoding(fontProgram)));
 }
コード例 #22
0
ファイル: FontProvider.cs プロジェクト: wjzhwht/itext7-dotnet
 public virtual bool AddFont(FontProgram fontProgram, String encoding)
 {
     return(fontSet.AddFont(fontProgram, encoding));
 }
コード例 #23
0
 public virtual bool AddFont(FontProgram fontProgram, String encoding, Range unicodeRange)
 {
     return(fontSet.AddFont(fontProgram, encoding, null, unicodeRange));
 }
コード例 #24
0
        /// <summary>Returns the Font.</summary>
        /// <returns>the font</returns>
        /// <exception cref="System.IO.IOException"/>
        public virtual FontProgram GetFont()
        {
            if (font != null)
            {
                return(font);
            }
            FontProgram ff2 = FontProgramFactory.CreateRegisteredFont(faceName, ((italic != 0) ? FontConstants.ITALIC :
                                                                                 0) | ((bold != 0) ? FontConstants.BOLD : 0));

            encoding = FontEncoding.CreateFontEncoding(PdfEncodings.WINANSI);
            font     = ff2;
            if (font != null)
            {
                return(font);
            }
            String fontName;

            if (faceName.Contains("courier") || faceName.Contains("terminal") || faceName.Contains("fixedsys"))
            {
                fontName = fontNames[MARKER_COURIER + italic + bold];
            }
            else
            {
                if (faceName.Contains("ms sans serif") || faceName.Contains("arial") || faceName.Contains("system"))
                {
                    fontName = fontNames[MARKER_HELVETICA + italic + bold];
                }
                else
                {
                    if (faceName.Contains("arial black"))
                    {
                        fontName = fontNames[MARKER_HELVETICA + italic + MARKER_BOLD];
                    }
                    else
                    {
                        if (faceName.Contains("times") || faceName.Contains("ms serif") || faceName.Contains("roman"))
                        {
                            fontName = fontNames[MARKER_TIMES + italic + bold];
                        }
                        else
                        {
                            if (faceName.Contains("symbol"))
                            {
                                fontName = fontNames[MARKER_SYMBOL];
                            }
                            else
                            {
                                int pitch  = pitchAndFamily & 3;
                                int family = (pitchAndFamily >> 4) & 7;
                                switch (family)
                                {
                                case FF_MODERN: {
                                    fontName = fontNames[MARKER_COURIER + italic + bold];
                                    break;
                                }

                                case FF_ROMAN: {
                                    fontName = fontNames[MARKER_TIMES + italic + bold];
                                    break;
                                }

                                case FF_SWISS:
                                case FF_SCRIPT:
                                case FF_DECORATIVE: {
                                    fontName = fontNames[MARKER_HELVETICA + italic + bold];
                                    break;
                                }

                                default: {
                                    switch (pitch)
                                    {
                                    case FIXED_PITCH: {
                                        fontName = fontNames[MARKER_COURIER + italic + bold];
                                        break;
                                    }

                                    default: {
                                        fontName = fontNames[MARKER_HELVETICA + italic + bold];
                                        break;
                                    }
                                    }
                                    break;
                                }
                                }
                            }
                        }
                    }
                }
            }
            try {
                font     = FontProgramFactory.CreateFont(fontName);
                encoding = FontEncoding.CreateFontEncoding(PdfEncodings.WINANSI);
            }
            catch (System.IO.IOException e) {
                throw new Exception(e.Message, e);
            }
            return(font);
        }
コード例 #25
0
        /// <summary>Output Text at a certain x and y coordinate.</summary>
        /// <remarks>Output Text at a certain x and y coordinate. Clipped or opaque text isn't supported as of yet.</remarks>
        /// <param name="x">x-coordinate</param>
        /// <param name="y">y-coordinate</param>
        /// <param name="flag">flag indicating clipped or opaque</param>
        /// <param name="x1">x1-coordinate of the rectangle if clipped or opaque</param>
        /// <param name="y1">y1-coordinate of the rectangle if clipped or opaque</param>
        /// <param name="x2">x2-coordinate of the rectangle if clipped or opaque</param>
        /// <param name="y2">y1-coordinate of the rectangle if clipped or opaque</param>
        /// <param name="text">text to output</param>
        /// <exception cref="System.IO.IOException"/>
        public virtual void OutputText(int x, int y, int flag, int x1, int y1, int x2, int y2, String text)
        {
            MetaFont    font     = state.GetCurrentFont();
            float       refX     = state.TransformX(x);
            float       refY     = state.TransformY(y);
            float       angle    = state.TransformAngle(font.GetAngle());
            float       sin      = (float)Math.Sin(angle);
            float       cos      = (float)Math.Cos(angle);
            float       fontSize = font.GetFontSize(state);
            FontProgram fp       = font.GetFont();
            int         align    = state.GetTextAlign();
            // NOTE, MetaFont always creates with CP1252 encoding.
            int normalizedWidth = 0;

            byte[] bytes = font.encoding.ConvertToBytes(text);
            foreach (byte b in bytes)
            {
                normalizedWidth += fp.GetWidth(0xff & b);
            }
            float textWidth = fontSize / FontProgram.UNITS_NORMALIZATION * normalizedWidth;
            float tx        = 0;
            float ty        = 0;
            float descender = fp.GetFontMetrics().GetTypoDescender();
            float ury       = fp.GetFontMetrics().GetBbox()[3];

            cb.SaveState();
            cb.ConcatMatrix(cos, sin, -sin, cos, refX, refY);
            if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER)
            {
                tx = -textWidth / 2;
            }
            else
            {
                if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT)
                {
                    tx = -textWidth;
                }
            }
            if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE)
            {
                ty = 0;
            }
            else
            {
                if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM)
                {
                    ty = -descender;
                }
                else
                {
                    ty = -ury;
                }
            }
            Color textColor;

            if (state.GetBackgroundMode() == MetaState.OPAQUE)
            {
                textColor = state.GetCurrentBackgroundColor();
                cb.SetFillColor(textColor);
                cb.Rectangle(tx, ty + descender, textWidth, ury - descender);
                cb.Fill();
            }
            textColor = state.GetCurrentTextColor();
            cb.SetFillColor(textColor);
            cb.BeginText();
            cb.SetFontAndSize(PdfFontFactory.CreateFont(state.GetCurrentFont().GetFont(), PdfEncodings.CP1252, true),
                              fontSize);
            cb.SetTextMatrix(tx, ty);
            cb.ShowText(text);
            cb.EndText();
            if (font.IsUnderline())
            {
                cb.Rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15);
                cb.Fill();
            }
            if (font.IsStrikeout())
            {
                cb.Rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15);
                cb.Fill();
            }
            cb.RestoreState();
        }
コード例 #26
0
 public virtual void SetFontProgram(FontProgram fontProgram)
 {
     this.fontProgram = fontProgram;
 }
コード例 #27
0
 /// <exception cref="System.IO.IOException"/>
 public static PdfFont CreateFont(FontProgram fontProgram)
 {
     return(CreateFont(fontProgram, DEFAULT_ENCODING));
 }
コード例 #28
0
        /// <exception cref="System.IO.IOException"/>
        public static PdfFont CreateFont(byte[] font, String encoding, bool embedded, bool cached)
        {
            FontProgram fontProgram = FontProgramFactory.CreateFont(null, font, cached);

            return(CreateFont(fontProgram, encoding, embedded));
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: Venci756/IText7Example
        public static void Main(string[] args)
        {
            // string path = @"C:\Users\Intern03.ELIKOSOFT\Desktop\MyProjects\IText7\TextExamples\demo.pdf";
            // string dirPath =@"C:\Users\Intern03.ELIKOSOFT\Desktop\MyProjects\IText7\TextExamples";
            //
            //
            //
            // if(File.Exists(path))
            //     File.Delete(path);
            //
            //
            // var directory= Directory.GetFiles(dirPath);
            // foreach (var file in directory)
            // {
            //     File.Delete(file);
            // }

            // Must have write permissions to the path folder
            PdfWriter   writer = new PdfWriter(@"C:\Users\Intern03.ELIKOSOFT\Desktop\MyProjects\IText7\TextExamples\demo.pdf");
            PdfDocument pdf    = new PdfDocument(writer);

            Document document = new Document(pdf, PageSize.A4, true);


            //var font = PdfFontFactory.CreateFont(FontConstants.TIMES_ROMAN);

            #region Creating Cyrillic Font
            //the path to the physical font file TTF on the drive
            string fontPath =
                $@"C:\Users\Intern03.ELIKOSOFT\Desktop\MyProjects\IText7\TextExamples\MAC_C_Times\MCTIME.TTF";

            FontProgram fontProgram = FontProgramFactory.CreateFont(fontPath);
            PdfFont     font        = PdfFontFactory.CreateFont(
                fontProgram, PdfEncodings.WINANSI, true);

            #endregion

            // var header = new Paragraph("Edine~ni Merki").SetTextAlignment(TextAlignment.CENTER)
            //     .SetFontSize(20).SetFont(font);

            var header = new Paragraph("Magacini").SetTextAlignment(TextAlignment.CENTER)
                         .SetFontSize(20).SetFont(font);

            Image img = new Image(ImageDataFactory
                                  .Create(@"C:\Users\Intern03.ELIKOSOFT\Desktop\MyProjects\IText7\logo.jpg"))
                        .SetTextAlignment(TextAlignment.CENTER);
            img.Scale(4, 4);
            document.Add(img);


            document.Add(header);
            // Table
            Table table = new Table(2, false);

            table.SetWidth(400).SetHorizontalAlignment(HorizontalAlignment.CENTER);


            Cell cell11 = new Cell(1, 1)
                          .SetBackgroundColor(ColorConstants.GRAY)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("Broj na magacin")).SetFont(font);
            Cell cell12 = new Cell(1, 1)
                          .SetBackgroundColor(ColorConstants.GRAY)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("Naziv na magacin")).SetFont(font);

            ////Uncomment for Measure Units Example
            // Cell cell11 = new Cell(1, 1)
            //     .SetBackgroundColor(ColorConstants.YELLOW)
            //     .SetTextAlignment(TextAlignment.CENTER)
            //     .Add(new Paragraph("Edine~na merka")).SetFont(font);
            // Cell cell12 = new Cell(1, 1)
            //     .SetBackgroundColor(ColorConstants.YELLOW)
            //     .SetTextAlignment(TextAlignment.CENTER)
            //     .Add(new Paragraph("Naziv na edine~na merka")).SetFont(font);



            Cell cell21 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("New York"));



            Cell cell22 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("Albany"));

            Cell cell31 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("New Jersey"));
            Cell cell32 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("Trenton"));

            Cell cell41 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("California"));
            Cell cell42 = new Cell(1, 1)
                          .SetTextAlignment(TextAlignment.CENTER)
                          .Add(new Paragraph("Sacramento"));


            table.AddCell(cell11);
            table.AddCell(cell12);
            ////Uncomment for Measure Units Example
            // foreach (KeyValuePair<string, string> item in Entities.SampleCollection)
            // {
            //     Cell cellKey = new Cell(1, 1)
            //         .SetTextAlignment(TextAlignment.CENTER)
            //         .Add(new Paragraph(item.Key)).SetFont(font);
            //
            //     Cell cellValue = new Cell(1, 1)
            //         .SetTextAlignment(TextAlignment.CENTER)
            //         .Add(new Paragraph(item.Value)).SetFont(font);
            //
            //     table.AddCell(cellKey);
            //     table.AddCell(cellValue);
            // }

            foreach (KeyValuePair <string, string> item in Entities.ReadyWarehouses())
            {
                Cell cellKey = new Cell(1, 1)
                               .SetTextAlignment(TextAlignment.CENTER)
                               .Add(new Paragraph(item.Key)).SetFont(font);

                Cell cellValue = new Cell(1, 1)
                                 .SetTextAlignment(TextAlignment.CENTER)
                                 .Add(new Paragraph(item.Value)).SetFont(font);

                table.AddCell(cellKey);
                table.AddCell(cellValue);
            }
            // for (int i = 0; i < Coll.words.Count(); i++)
            // {
            //     Cell cell = new Cell(1, 1)
            //         .SetTextAlignment(TextAlignment.CENTER)
            //         .Add(new Paragraph(Coll.words.ElementAt(i)));
            //
            //     table.AddCell(cell);
            // }
            document.Add(table);
            document.Close();
        }