// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
namespace DsPdfWeb.Demos
{
// This sample demonstrates that as of version 4.1,
// DsPdf supports rendering PDFs that include text
// that uses Adobe Type 1 Font specification fonts.
// Compare images generated by this sample (e.g. TIFF)
// with images generated by the same code but using
// and older version of DsPdf (v4 or earlier) to see
// the difference.
public class Type1FontsDemo
{
public int CreatePDF(Stream stream)
{
var doc = new GcPdfDocument();
// We load a PDF that uses PDF Type 1 fonts, add some text to it,
// and save it to PDF and images (JPEG and TIFF) as in all other samples.
// The original text in the loaded PDF is rendered using Adobe Type 1 fonts,
// so if using DsPdf v4.0 or earlier, the generated images would contain
// garbled text. Starting with v4.1, Type 1 fonts are rendered correctly.
using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Type1FontSample.pdf"));
doc.Load(fs);
// Add note to the (only) page in the doc:
var page = doc.Pages.Last;
Common.Util.AddNote(
"This sample demonstrates rendering Adobe Type 1 fonts when a PDF is saved as image by DsPdf. " +
"This is supported starting with DsPdf v4.1. To see the result, open the generated PDF " +
"saved as image (e.g. TIFF). Using the same code with an earlier version of DsPdf produces " +
"garbled text in the saved image.",
page,
new RectangleF(12, 12, 72 * 5, 0));
// 完毕:
doc.Save(stream);
return doc.Pages.Count;
}
}
}