public void Create(string platformname, string key, string connectionstring)
        {
            // ライセンスキー設定
            //GcPdfDocument.SetLicenseKey(key);

            // PDFドキュメントを作成します。
            GcPdfDocument doc = new GcPdfDocument();

            // ページを追加し、そのグラフィックスを取得します。
            GcPdfGraphics g = doc.NewPage().Graphics;

            // ページに文字列を描画します。
            g.DrawString("Hello, DioDocs!" + Environment.NewLine + "from " + platformname,
                         new TextFormat()
            {
                Font = StandardFonts.Helvetica, FontSize = 12
            },
                         new PointF(72, 72));

            // メモリストリームに保存
            MemoryStream ms = new MemoryStream();

            doc.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin);

            // BLOBストレージにアップロード
            AzStorage storage = new AzStorage(connectionstring);

            storage.UploadPdfAsync(ms);
        }
Exemplo n.º 2
0
        public void CreatePDF(Stream stream)
        {
            Font gabriola = Font.FromFile(Path.Combine("Resources", "Fonts", "Gabriola.ttf"));

            if (gabriola == null)
            {
                throw new Exception("Could not load font Gabriola");
            }

            // Now that we have our font, use it to render some text:
            TextFormat tf = new TextFormat()
            {
                Font = gabriola, FontSize = 16
            };
            GcPdfDocument doc = new GcPdfDocument();
            GcPdfGraphics g   = doc.NewPage().Graphics;

            g.DrawString($"Sample text drawn with font {gabriola.FontFamilyName}.", tf, new PointF(72, 72));
            // We can change the font size:
            tf.FontSize += 4;
            g.DrawString("The quick brown fox jumps over the lazy dog.", tf, new PointF(72, 72 * 2));
            // We can force GcPdf to emulate bold or italic style with a non-bold (non-italic) font, e.g.:
            tf.FontStyle = FontStyle.Bold;
            g.DrawString("This line prints with the same font, using emulated bold style.", tf, new PointF(72, 72 * 3));
            // But of course rather than emulated, it is much better to use real bold/italic fonts.
            // So finally, get a real bold italic font and print a line with it:
            Font timesbi = Font.FromFile(Path.Combine("Resources", "Fonts", "timesbi.ttf"));

            tf.Font      = timesbi ?? throw new Exception("Could not load font timesbi");
            tf.FontStyle = FontStyle.Regular;
            g.DrawString($"This line prints with {timesbi.FullFontName}.", tf, new PointF(72, 72 * 4));
            // Done:
            doc.Save(stream);
        }
Exemplo n.º 3
0
 public void TextTagEnd(GcPdfGraphics graphics, TextLayout textLayout, object tag)
 {
     if (_currentparagraphElement != null)
     {
         graphics.EndMarkedContent();
     }
 }
Exemplo n.º 4
0
        public static void Create(string platformname)
        {
            // トライアル用
            string key = Resources.ResourceManager.GetString("DdPdfLicenseString");

            GcPdfDocument.SetLicenseKey(key);

            // PDFドキュメントを作成します。
            GcPdfDocument doc = new GcPdfDocument();

            // ページを追加し、そのグラフィックスを取得します。
            GcPdfGraphics g = doc.NewPage().Graphics;

            // ページに文字列を描画します。
            g.DrawString("Hello, de:code 2019!" + Environment.NewLine + "from " + platformname,
                         new TextFormat()
            {
                Font = StandardFonts.Helvetica, FontSize = 12
            },
                         new PointF(72, 72));

            // メモリストリームに保存
            MemoryStream ms = new MemoryStream();

            doc.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin);

            // BLOBストレージにアップロード
            AzStorage.UploadPdfAsync(ms);
        }
Exemplo n.º 5
0
            public void TextTagBegin(GcPdfGraphics graphics, TextLayout textLayout, object tag)
            {
                int paragraphIndex;

                if (tag is int)
                {
                    paragraphIndex = (int)tag;
                }
                else
                {
                    paragraphIndex = -1;
                }

                StructElement paragraphElement;

                if (_currentParagraphIndex == paragraphIndex)
                {
                    paragraphElement = _currentparagraphElement;
                }
                else
                {
                    if (paragraphIndex >= 0)
                    {
                        paragraphElement = new StructElement("P");
                        ParentElement.Children.Add(paragraphElement);
                        _currentparagraphElement = paragraphElement;
                        _currentParagraphIndex   = paragraphIndex;
                    }
                    else
                    {
                        paragraphElement         = null;
                        _currentparagraphElement = paragraphElement;
                        _currentParagraphIndex   = paragraphIndex;
                    }
                }

                //
                if (paragraphElement != null)
                {
                    graphics.BeginMarkedContent(new TagMcid("P", _tagIndex));
                    McrContentItemLink mcil = new McrContentItemLink();
                    mcil.MCID = _tagIndex;
                    mcil.Page = Page;
                    paragraphElement.ContentItems.Add(mcil);
                    _tagIndex++;
                }
            }
Exemplo n.º 6
0
        public static void Generate()
        {
            GcPdfDocument doc = new GcPdfDocument();
            // Add a page, get its graphics:
            GcPdfGraphics g = doc.NewPage().Graphics;

            // Render a string into the page:
            g.DrawString("Hello, World!",
                         // Use a standard font (the 14 standard PDF fonts are built into GcPdf
                         // and are always available):
                         new TextFormat()
            {
                Font = StandardFonts.Times, FontSize = 12
            },
                         // GcPdf page coordinates start at top left corner, using 72 dpi by default:
                         new PointF(72, 72));
            // Save the PDF:
            doc.Save("HelloWorld.pdf");
        }
Exemplo n.º 7
0
        public void CreatePDF(Stream stream)
        {
            // Create a new PDF document:
            GcPdfDocument doc = new GcPdfDocument();
            // Add a page, get its graphics:
            GcPdfGraphics g = doc.NewPage().Graphics;

            // Draw a string on the page.
            // Notes:
            // - For simplicity, here we are using a standard PDF font
            //   (the 14 standard fonts' metrics are built into GcPdf and are always available);
            // - GcPdf coordinates start at top left corner of a page, using 72 dpi by default:
            g.DrawString("Hello, World!",
                         new TextFormat()
            {
                Font = StandardFonts.Times, FontSize = 12
            },
                         new PointF(72, 72));
            // Save the PDF:
            doc.Save(stream);
        }
Exemplo n.º 8
0
        public void Create(string input)
        {
            //// トライアル用
            //string key = Environment.GetEnvironmentVariable("DdPdfLicenseString");
            //GcPdfDocument.SetLicenseKey(key);

            // PDFドキュメントを作成します。
            GcPdfDocument doc = new GcPdfDocument();

            // ページを追加し、そのグラフィックスを取得します。
            GcPdfGraphics g = doc.NewPage().Graphics;

            // ページに文字列を描画します。
            g.DrawString("Hello DioDocs!" + Environment.NewLine + "from " + input,
                         new TextFormat()
            {
                Font = StandardFonts.Helvetica, FontSize = 12
            },
                         new PointF(72, 72));

            // メモリストリームに保存
            MemoryStream ms = new MemoryStream();

            doc.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin);

            // S3にアップロード
            AmazonS3Client client = new AmazonS3Client(RegionEndpoint.APNortheast1);

            var request = new PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = uploadPdfName,
                InputStream = ms
            };

            client.PutObjectAsync(request);
        }
Exemplo n.º 9
0
        public void CreatePDF(Stream stream)
        {
            // Set up GcPdfDocument:
            GcPdfDocument doc = new GcPdfDocument();
            GcPdfGraphics g   = doc.NewPage().Graphics;

            // Set up some helper vars for rendering lines of text:
            const float margin = 36;
            // Insertion point (GcPdf's default resolution is 72dpi, use 1/2" margins all around):
            PointF ip = new PointF(margin, margin);
            // Init a text format with one of the standard fonts. Standard fonts are minimal
            // and contain very few glyphs for non-Latin characters.
            TextFormat tf = new TextFormat()
            {
                Font = StandardFonts.Courier, FontSize = 14
            };

            // Get the list of fallback font families:
            string[] fallbacks = FontCollection.SystemFonts.GetFallbackFontFamilies();

            // Clear global fallbacks list:
            FontCollection.SystemFonts.ClearFallbackFontFamilies();
            FontCollection.SystemFonts.ClearFallbackFonts();

            // Now there are no global fallback fonts, so Japanese text rendered using
            // a standard font will produce 'blank boxes' instead of real Japanese characters:
            g.DrawString("A Japanese text that won't render: あなたは日本語を話せますか?", tf, ip);
            ip.Y += 36;

            // Re-add the original list of fallback font families to global SystemFonts:
            FontCollection.SystemFonts.AppendFallbackFontFamilies(fallbacks);
            // On some systems, default system fallbacks might not provide Japanese glyphs,
            // so we add our own fallback just in case:
            Font arialuni = Font.FromFile(Path.Combine("Resources", "Fonts", "arialuni.ttf"));

            FontCollection.SystemFonts.AppendFallbackFonts(arialuni);

            // Now that fallback fonts are available again, the same Japanese text will render
            // correctly as an appropriate fallback will have been found:
            g.DrawString("Same text with fallbacks available: あなたは日本語を話せますか?", tf, ip);
            ip.Y += 36;

            // Finally, we list all fallbacks and print a test line using each:
            Action <string> drawTestLine = (fnt_) =>
            {
                var tf1 = new TextFormat()
                {
                    FontName = fnt_
                };
                string tstr = $"{fnt_}: The quick brown fox jumps over the lazy dog.";
                var    s    = g.MeasureString(tstr, tf1, doc.PageSize.Width - margin * 2);
                g.DrawString(tstr, tf1, new RectangleF(ip, s));
                ip.Y += s.Height * 1.5f;
                if (ip.Y > doc.Pages.Last.Size.Height - margin * 2)
                {
                    g    = doc.NewPage().Graphics;
                    ip.Y = 36;
                }
            };

            foreach (var fnt in fallbacks)
            {
                drawTestLine(fnt);
            }

            // Done:
            doc.Save(stream);
        }