本文整理汇总了C#中PdfDocument类的典型用法代码示例。如果您正苦于以下问题:C# PdfDocument类的具体用法?C# PdfDocument怎么用?C# PdfDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PdfDocument类属于命名空间,在下文中一共展示了PdfDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PdfTrueTypeFont
/// <summary>
/// Initializes a new instance of PdfTrueTypeFont from an XFont.
/// </summary>
public PdfTrueTypeFont(PdfDocument document, XFont font)
: base(document)
{
Elements.SetName(Keys.Type, "/Font");
Elements.SetName(Keys.Subtype, "/TrueType");
// TrueType with WinAnsiEncoding only.
OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
_fontOptions = font.PdfOptions;
Debug.Assert(_fontOptions != null);
//cmapInfo = new CMapInfo(null/*ttDescriptor*/);
_cmapInfo = new CMapInfo(ttDescriptor);
BaseFont = font.GlyphTypeface.GetBaseName();
if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always)
BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
FontDescriptor.FontName = BaseFont;
Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
if (!IsSymbolFont)
Encoding = "/WinAnsiEncoding";
Owner._irefTable.Add(FontDescriptor);
Elements[Keys.FontDescriptor] = FontDescriptor.Reference;
FontEncoding = font.PdfOptions.FontEncoding;
}
示例2: Main
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
//Use the default printer to print all the pages
//doc.PrintDocument.Print();
//Set the printer and select the pages you want to print
PrintDialog dialogPrint = new PrintDialog();
dialogPrint.AllowPrintToFile = true;
dialogPrint.AllowSomePages = true;
dialogPrint.PrinterSettings.MinimumPage = 1;
dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
dialogPrint.PrinterSettings.FromPage = 1;
dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;
if (dialogPrint.ShowDialog() == DialogResult.OK)
{
//Set the pagenumber which you choose as the start page to print
doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
//Set the pagenumber which you choose as the final page to print
doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
//Set the name of the printer which is to print the PDF
doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;
PrintDocument printDoc = doc.PrintDocument;
dialogPrint.Document = printDoc;
printDoc.Print();
}
}
示例3: PdfExtGState
/// <summary>
/// Initializes a new instance of the <see cref="PdfExtGState"/> class.
/// </summary>
/// <param name="document">The document.</param>
public PdfExtGState(PdfDocument document)
: base(document)
{
Elements.SetName(Keys.Type, "/ExtGState");
#if true_
//AIS false
//BM /Normal
//ca 1
//CA 1
//op false
//OP false
//OPM 1
//SA true
//SMask /None
//Type /ExtGState
Elements.SetValue(Keys.AIS, new PdfBoolean(false)); // The alpha source
Elements.SetName("/BM", "Normal");
Elements.SetValue(Keys.op, new PdfBoolean(false));
Elements.SetValue(Keys.OP, new PdfBoolean(false));
Elements.SetValue(Keys.OPM, new PdfInteger(1));
Elements.SetValue("/SA", new PdfBoolean(true));
Elements.SetName("/SMask", "None");
#endif
}
示例4: PdfType0Font
public PdfType0Font(PdfDocument document, XFont font, bool vertical)
: base(document)
{
Elements.SetName(Keys.Type, "/Font");
Elements.SetName(Keys.Subtype, "/Type0");
Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");
OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
_fontOptions = font.PdfOptions;
Debug.Assert(_fontOptions != null);
_cmapInfo = new CMapInfo(ttDescriptor);
_descendantFont = new PdfCIDFont(document, FontDescriptor, font);
_descendantFont.CMapInfo = _cmapInfo;
// Create ToUnicode map
_toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
document.Internals.AddObject(_toUnicode);
Elements.Add(Keys.ToUnicode, _toUnicode);
BaseFont = font.GlyphTypeface.GetBaseName();
// CID fonts are always embedded
BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
FontDescriptor.FontName = BaseFont;
_descendantFont.BaseFont = BaseFont;
PdfArray descendantFonts = new PdfArray(document);
Owner._irefTable.Add(_descendantFont);
descendantFonts.Elements.Add(_descendantFont.Reference);
Elements[Keys.DescendantFonts] = descendantFonts;
}
示例5: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
//Draw the page
DrawPage(page);
//set view reference
doc.ViewerPreferences.CenterWindow = true;
doc.ViewerPreferences.DisplayTitle = false;
doc.ViewerPreferences.FitWindow = false;
doc.ViewerPreferences.HideMenubar = true;
doc.ViewerPreferences.HideToolbar = true;
doc.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage;
//Save pdf file.
doc.SaveToFile("ViewerPreference.pdf");
doc.Close();
//Launching the Pdf file.
PDFDocumentViewer("ViewerPreference.pdf");
}
示例6: PdfCatalog
/// <summary>
/// Initializes a new instance of the <see cref="PdfCatalog"/> class.
/// </summary>
public PdfCatalog(PdfDocument document)
: base(document)
{
Elements.SetName(Keys.Type, "/Catalog");
_version = "1.4"; // HACK in PdfCatalog
}
示例7: ParsePdf
private void ParsePdf(DateTime curDate, byte[] pdfData)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromBytes(pdfData);
Menus.Add(new Menu(curDate, doc.Pages[0].ExtractText()));
}
示例8: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//load two document
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromFile(@"..\..\..\..\..\..\Data\Sample1.pdf");
PdfDocument doc2 = new PdfDocument();
doc2.LoadFromFile(@"..\..\..\..\..\..\Data\Sample3.pdf");
//Create page template
PdfTemplate template = doc1.Pages[0].CreateTemplate();
foreach (PdfPageBase page in doc2.Pages)
{
page.Canvas.SetTransparency(0.25f, 0.25f, PdfBlendMode.Overlay);
page.Canvas.DrawTemplate(template, PointF.Empty);
}
//Save pdf file.
doc2.SaveToFile("Overlay.pdf");
doc1.Close();
doc2.Close();
//Launching the Pdf file.
PDFDocumentViewer("Overlay.pdf");
}
示例9: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
//margin
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;
// Create one page
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
Image img = Image.FromFile(@"..\..\..\..\..\..\Data\Background.png");
page.BackgroundImage = img;
//Draw table
DrawPage(page);
//Save pdf file.
doc.SaveToFile("ImageWaterMark.pdf");
doc.Close();
//Launching the Pdf file.
PDFDocumentViewer("ImageWaterMark.pdf");
}
示例10: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
//Draw the text
page.Canvas.DrawString("Hello, World!",
new PdfFont(PdfFontFamily.Helvetica, 30f),
new PdfSolidBrush(Color.Black),
10, 10);
//Draw the image
PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
float width = image.Width * 0.75f;
float height = image.Height * 0.75f;
float x = (page.Canvas.ClientSize.Width - width) / 2;
page.Canvas.DrawImage(image, x, 60, width, height);
//Save pdf file.
doc.SaveToFile("Image.pdf");
doc.Close();
//Launching the Pdf file.
PDFDocumentViewer("Image.pdf");
}
示例11: AttatchDocument
public void AttatchDocument(PdfDocument.DocumentHandle handle)
{
lo ck (_documentHandles)
{
_documentHandles.Add(handle);
}
}
示例12: CreateRekenPyramide
public PdfDocument CreateRekenPyramide(string filename)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
int basislengte = 8;
int maxbasisgetal = 14;
Random rnd = new Random();
for (int pyramide = 1; pyramide <= 3; pyramide++)
{
GeneratePyramid(basislengte, rnd, maxbasisgetal);
int papierhoogte = ((int)page.Canvas.Size.Height / 3 - 40) * pyramide;
TekenHelePyramideOpPapier(page, pyrArray, basislengte, papierhoogte);
}
//Save pdf file.
doc.SaveToFile(filename);
doc.Close();
return doc;
}
示例13: EnsureColorMode
/// <summary>
/// Checks whether the color mode of a document and a color match.
/// </summary>
public static XColor EnsureColorMode(PdfDocument document, XColor color)
{
if (document == null)
throw new ArgumentNullException("document");
return EnsureColorMode(document.Options.ColorMode, color);
}
示例14: GeneratePdfStream
public Stream GeneratePdfStream(string url)
{
var document = new PdfDocument { Url = url };
var output = new PdfOutput {OutputStream = new MemoryStream()};
PdfConvert.ConvertHtmlToPdf(document, output);
output.OutputStream.Position = 0;
return output.OutputStream;
}
示例15: PdfFormXObject
internal PdfFormXObject(PdfDocument thisDocument, XForm form)
: base(thisDocument)
{
Elements.SetName(Keys.Type, "/XObject");
Elements.SetName(Keys.Subtype, "/Form");
//if (form.IsTemplate)
//{ }
}