コード例 #1
0
        public virtual void RunTest()
        {
            //TODO(DEVSIX-2978): Produces non-conforming PDF/A document
            String file     = "pdfALongString.pdf";
            String filename = destinationFolder + file;

            using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
                                               )) {
                using (PdfADocument pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel
                                                           .PDF_A_3U, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", icm))) {
                    using (Document document = new Document(pdf)) {
                        StringBuilder stringBuilder = new StringBuilder(LOREM_IPSUM);
                        while (stringBuilder.Length < STRING_LENGTH_LIMIT)
                        {
                            stringBuilder.Append(stringBuilder.ToString());
                        }
                        PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
                        PdfFont   font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
                        Paragraph p    = new Paragraph(stringBuilder.ToString());
                        p.SetMinWidth(1e6f);
                        p.SetFont(font);
                        document.Add(p);
                    }
                }
            }
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
コード例 #2
0
 public virtual void RunTest()
 {
     NUnit.Framework.Assert.That(() => {
         String file     = "pdfALongString.pdf";
         String filename = destinationFolder + file;
         using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
                                            )) {
             using (Document document = new Document(new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create
                                                                                                   )), PdfAConformanceLevel.PDF_A_3U, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference"
                                                                                                                                                          , icm)))) {
                 StringBuilder stringBuilder = new StringBuilder(LOREM_IPSUM);
                 while (stringBuilder.Length < STRING_LENGTH_LIMIT)
                 {
                     stringBuilder.Append(stringBuilder.ToString());
                 }
                 PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
                 PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
                 Paragraph p  = new Paragraph(stringBuilder.ToString());
                 p.SetMinWidth(1e6f);
                 p.SetFont(font);
                 document.Add(p);
             }
         }
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.PDF_STRING_IS_TOO_LONG))
     ;
 }
コード例 #3
0
        /// <summary>
        /// Attempts to retrieve the specified font from the System's Fonts folder
        /// and registers the font with WPF.
        /// </summary>
        /// <param name="fontName">Name of the font.</param>
        /// <returns></returns>
        private static PdfFont GetFont(string fontName)
        {
            if (!PdfFontFactory.IsRegistered(fontName))
            {
                var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\" + fontName.Replace(" ", "") + ".ttf";
                PdfFontFactory.Register(fontPath);
            }

            return(PdfFontFactory.CreateRegisteredFont(fontName));
        }
コード例 #4
0
        // during closing of pdfa object exception will be thrown as new document will contain
        // 12 indirect objects and limit per "mock specification" conformance will be exceeded
        private Paragraph BuildContent()
        {
            PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
            PdfFont   font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
            Paragraph p    = new Paragraph(Guid.NewGuid().ToString());

            p.SetMinWidth(1e6f);
            p.SetFont(font);
            return(p);
        }
コード例 #5
0
 /// <summary>
 /// 文档初始
 /// </summary>
 /// <exception cref="Exception"></exception>
 protected override void DocumentInitialize()
 {
     lock (_loadSync)
     {
         FontFiles.ForEach(p =>
         {
             if (File.Exists(p) && !RegisterFontFiles.Contains(p))
             {
                 PdfFontFactory.Register(p);
                 RegisterFontFiles.Add(p);
             }
         });
     }
 }
コード例 #6
0
        public virtual void PdfAButtonFieldTest()
        {
            PdfDocument pdf;
            Stream      @is      = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            String      file     = "pdfAButtonField.pdf";
            String      filename = destinationFolder + file;

            pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel.PDF_A_1B
                                   , new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", @is));
            PageSize pageSize = PageSize.LETTER;
            Document doc      = new Document(pdf, pageSize);

            PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
            PdfFont            font  = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdf, "group", "", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Paragraph p = new Paragraph();
            Text      t = new Text("supported");

            t.SetFont(font);
            p.Add(t);
            Image     ph = new Image(new PdfFormXObject(new Rectangle(10, 10)));
            Paragraph pc = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                , "v1");
            pc.SetNextRenderer(r);
            p.Add(pc);
            Paragraph pc1 = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r1 = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                 , "v2");
            pc1.SetNextRenderer(r1);
            Paragraph p2 = new Paragraph();
            Text      t2 = new Text("supported 2");

            t2.SetFont(font);
            p2.Add(t2).Add(pc1);
            doc.Add(p);
            doc.Add(p2);
            //set generateAppearance param to false to retain custom appearance
            group.SetValue("v1", false);
            PdfAcroForm.GetAcroForm(pdf, true).AddField(group);
            pdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp/PdfAFormFieldTest/cmp_"
                                                                             + file, destinationFolder, "diff_"));
        }
コード例 #7
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            String fontName = "Greek-Regular";

            PdfFontFactory.Register(FONT, fontName);
            PdfFont f = PdfFontFactory.CreateRegisteredFont(fontName, PdfEncodings.CP1253, true);

            // "Νύφες"
            Paragraph p = new Paragraph("\u039d\u03cd\u03c6\u03b5\u03c2").SetFont(f);

            doc.Add(p);

            doc.Close();
        }
コード例 #8
0
ファイル: PdfBuilder.cs プロジェクト: myuzhang/PdfHandy.Net
 public void RegisterCustomFonts(string fontFolder)
 {
     if (Directory.Exists(fontFolder))
     {
         DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(fontFolder);
         FileInfo[]    files = hdDirectoryInWhichToSearch.GetFiles();
         foreach (var fileInfo in files)
         {
             try
             {
                 PdfFontFactory.Register(fileInfo.FullName);
             }
             catch (Exception e)
             {
                 Debug.WriteLine(e);
             }
         }
     }
 }
コード例 #9
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);

            foreach (String font in FONTS)
            {
                PdfFontFactory.Register(font);
            }

            PdfFont defaultFont = doc.GetDefaultProperty<PdfFont>(Property.FONT);
            
            HashSet<String> fonts = new HashSet<String>(FontProgramFactory.GetRegisteredFonts());
            foreach (String fontname in fonts)
            {
                Console.WriteLine(fontname);
                PdfFont font;
                try
                {
                    font = PdfFontFactory.CreateRegisteredFont(fontname, PdfEncodings.IDENTITY_H);
                }
                catch (ArgumentException e)
                {
                    doc.Add(new Paragraph(String.Format("The font {0} doesn't have unicode support: {1}",
                        fontname, e.Message)));
                    continue;
                }

                doc.Add(new Paragraph(String.Format("Postscript name for {0}: {1}", fontname,
                    font.GetFontProgram().GetFontNames().GetFontName())));
                doc.SetFont(font);
                ShowFontInfo(doc);
                
                // Restore the default document font
                doc.SetFont(defaultFont);
            }

            doc.Close();
        }
コード例 #10
0
        public void InitializeLayout()
        {
            if (string.IsNullOrEmpty(RegularFontName))
            {
                RegularFontName = Common.FontTitleRegular;
            }

            if (string.IsNullOrEmpty(BoldFontName))
            {
                BoldFontName = Common.FontTitleBold;
            }

            if (!PdfFontFactory.IsRegistered(RegularFontName))
            {
                PdfFontFactory.Register(RegularFontName);
            }
            if (!PdfFontFactory.IsRegistered(BoldFontName))
            {
                PdfFontFactory.Register(BoldFontName);
            }

            regularFont = PdfFontFactory.CreateFont(RegularFontName, true);
            boldFont    = PdfFontFactory.CreateFont(BoldFontName, true);
        }
コード例 #11
0
ファイル: PdfBuilder.cs プロジェクト: myuzhang/PdfHandy.Net
 public void RegisterCustomFont(string fontFile) => PdfFontFactory.Register(fontFile);