本文整理匯總了C#中PdfSharp.Pdf.PdfDocument.AddPage方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDocument.AddPage方法的具體用法?C# PdfDocument.AddPage怎麽用?C# PdfDocument.AddPage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PdfSharp.Pdf.PdfDocument
的用法示例。
在下文中一共展示了PdfDocument.AddPage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create an empty page
PdfPage page = document.AddPage();
//page.Contents.CreateSingleContent().Stream.UnfilteredValue;
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
// Create a font
XFont font = new XFont("Arial", 20, XFontStyle.Bold, options);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
// Save the document...
string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
示例2: Genereer
public static bool Genereer(Deelnemer deelnemer, DeelnemerVerhuisd deelnemerVerhuisd)
{
_deelnemer = deelnemer;
_event = deelnemerVerhuisd;
// start pdf document
_document = new PdfDocument();
_document.Info.Title = "Verhuisbrief " + _deelnemer.Naam;
_document.Info.Author = "Verhuisbrief Generator";
// voeg pagina toe
_page = _document.AddPage();
_gfx = XGraphics.FromPdfPage(_page);
// vul pagina
PlaatsLogo();
PlaatsTitel();
PlaatsNAWGegevens();
PlaatsInhoud();
// sla document op
SlaPdfOp();
return true;
}
示例3: Main
static void Main()
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create a font
XFont font = new XFont("Verdana", 16);
// Create first page
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("Page 1", font, XBrushes.Black, 20, 50, XStringFormats.Default);
// Create the root bookmark. You can set the style and the color.
PdfOutline outline = document.Outlines.Add("Root", page, true, PdfOutlineStyle.Bold, XColors.Red);
// Create some more pages
for (int idx = 2; idx <= 5; idx++)
{
page = document.AddPage();
gfx = XGraphics.FromPdfPage(page);
string text = "Page " + idx;
gfx.DrawString(text, font, XBrushes.Black, 20, 50, XStringFormats.Default);
// Create a sub bookmark
outline.Outlines.Add(text, page, true);
}
// Save the document...
const string filename = "Bookmarks_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
示例4: Print
public static void Print(SongData song, string filename)
{
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
LogPages pages = SongPrinter.FormatSongForPrinting(song, PageSizeConverter.ToSize(page.Size).Width, PdfPrintTarget.InfoContext, PageSizeConverter.ToSize(page.Size).Height, PdfPrintTarget.getmmky());
foreach (LogPage lp in pages.Pages)
{
lp.DrawPage(XGraphics.FromPdfPage(page), new PointF(0, 0), null);
if (pages.LastPage != lp) page = doc.AddPage();
}
doc.Save(filename);
}
示例5: GenerateApplicationPdf
internal static byte[] GenerateApplicationPdf(Application application)
{
//Create pdf document
PdfDocument pdf = new PdfDocument();
PdfPage page = pdf.AddPage();
//Create pdf content
Document doc = CreateDocument("Application", string.Format("{1}, {0}",application.Person.Name, application.Person.Surname));
PopulateDocument(ref doc, application);
//Create renderer for content
DocumentRenderer renderer = new DocumentRenderer(doc);
renderer.PrepareDocument();
XRect A4 = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point);
XGraphics gfx = XGraphics.FromPdfPage(page);
int pages = renderer.FormattedDocument.PageCount;
for(int i = 0; i < pages; i++)
{
var container = gfx.BeginContainer(A4, A4, XGraphicsUnit.Point);
gfx.DrawRectangle(XPens.LightGray, A4);
renderer.RenderPage(gfx, (i + 1));
gfx.EndContainer(container);
}
using (MemoryStream ms = new MemoryStream())
{
pdf.Save(ms, true);
return ms.ToArray();
}
}
示例6: CreatePDF
public Stream CreatePDF()
{
using (PdfDocument doc = new PdfDocument())
{
ScanImages((image) =>
{
using (XImage ximage = XImage.FromGdiPlusImage(image))
{
PdfPage page = doc.AddPage();
page.Width = XUnit.FromInch(this.settings.PageSize.Width);
page.Height = XUnit.FromInch(this.settings.PageSize.Height);
using (XGraphics xgraphics = XGraphics.FromPdfPage(page))
{
xgraphics.DrawImage(ximage, 0, 0);
}
}
});
if (doc.PageCount > 0)
{
var response = new MemoryStream();
doc.Save(response, false);
return response;
}
else
{
throw new ScanException("Nothing was scanned.");
}
}
}
示例7: Convert
public bool Convert(string inputFileName, string outputFileName)
{
try
{
using (PdfDocument doc = new PdfDocument())
{
PdfPage page = doc.AddPage();
using (XGraphics gfx = XGraphics.FromPdfPage(page))
using (var image = XImage.FromFile(inputFileName))
{
var border = 10;
var widthRatio = (gfx.PageSize.Width - border * 2) / image.PixelWidth;
var heightRatio = (gfx.PageSize.Height - border) / image.PixelHeight;
var scaling = Math.Min(widthRatio, heightRatio);
gfx.DrawImage(image, border, border, image.PixelWidth * scaling, image.PixelHeight * scaling);
doc.Save(outputFileName);
}
}
return true;
}
catch (Exception ex)
{
Logger.WarnFormat(ex, "Error converting file {0} to Pdf.", inputFileName);
return false;
}
}
示例8: Main
static void Main(string[] args)
{
foreach (string arg in args)
{
DirectoryInfo directory = new DirectoryInfo(arg);
string SavePath = string.Format("{0}.pdf",directory.Name);
var files = directory.GetFiles("*.bmp");
using (PdfDocument Document = new PdfDocument())
{
foreach (var file in files)
{
var filename = file.FullName;
Console.WriteLine(filename);
PdfPage page = Document.AddPage();
using (XImage image = XImage.FromFile(filename))
{
page.Width = image.PointWidth;
page.Height = image.PointHeight;
using (XGraphics gfx = XGraphics.FromPdfPage(page))
{
gfx.DrawImage(image, 0, 0);
}
}
}
Document.Save(SavePath);
}
}
}
示例9: Merge
public PdfDocument Merge( string[] filePaths, Action afterEachAddedFileAction )
{
PdfDocument mergedDocument = new PdfDocument();
foreach ( var filePath in filePaths )
{
try
{
using ( PdfDocument documentToAdd = _pdfReader.ReadFile( filePath ) )
{
for ( int i = 0; i < documentToAdd.PageCount; i++ )
{
PdfPage page = documentToAdd.Pages[ i ];
mergedDocument.AddPage( page );
}
}
}
catch ( Exception ex )
{
string errorMessage = string.Format( "An error occurred processing the following file: {0}\n\nError Message: {1}\n\nFull Error: {2}", filePath, ex.Message, ex );
MessageBox.Show( errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error );
}
if ( afterEachAddedFileAction != null )
{
afterEachAddedFileAction();
}
}
return mergedDocument;
}
示例10: MergePdfs
public byte[] MergePdfs(IEnumerable<FileToMerge> files)
{
byte[] mergedPdfContents;
using (var mergedPdfDocument = new PdfDocument())
{
foreach (var file in files)
{
using (var memoryStream = new MemoryStream(file.Contents))
{
var inputPdfDocument = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Import);
var pageCount = inputPdfDocument.PageCount;
for (var pageNumber = 0; pageNumber < pageCount; pageNumber++)
{
var page = inputPdfDocument.Pages[pageNumber];
mergedPdfDocument.AddPage(page);
}
}
}
using (var mergedPdfStream = new MemoryStream())
{
mergedPdfDocument.Save(mergedPdfStream);
mergedPdfContents = mergedPdfStream.ToArray();
}
}
return mergedPdfContents;
}
示例11: Main
static void Main()
{
// Create new document
PdfDocument document = new PdfDocument();
// Set font encoding to unicode
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);
// Draw text in different languages
for (int idx = 0; idx < texts.Length; idx++)
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XTextFormatter tf = new XTextFormatter(gfx);
tf.Alignment = XParagraphAlignment.Left;
tf.DrawString(texts[idx], font, XBrushes.Black,
new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft);
}
const string filename = "Unicode_tempfile.pdf";
// Save the document...
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
示例12: GetCookBook
public Uri GetCookBook(string name)
{
var document = new PdfDocument();
document.Info.Title = name + "'s personalized cookbook";
document.Info.Author = "Pancake Prowler";
var page = document.AddPage();
var graphics = XGraphics.FromPdfPage(page);
var font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
graphics.DrawString(name + "'s personalized cookbook",
font,
XBrushes.Red,
new System.Drawing.PointF((float)page.Width / 2, (float)page.Height / 2),
XStringFormats.Center);
var saveStream = new MemoryStream();
document.Save(saveStream);
var memoryStream = new MemoryStream(saveStream.ToArray());
memoryStream.Seek(0, SeekOrigin.Begin);
var imageStore = new BlobImageRepository();
return imageStore.Save("application/pdf", memoryStream, "cookbooks");
}
示例13: Export_to_Pdf
public Export_to_Pdf()
{
InitializeComponent();
//Create object for pdf.
document = new PdfDocument();
page = document.AddPage();
gfx = XGraphics.FromPdfPage(page);
//Set by default values.
font = new XFont("Arial", 12, XFontStyle.Regular);
header_font = new XFont("Arial", 12, XFontStyle.Regular);
page.Size = PageSize.A4;
page.Orientation = PageOrientation.Portrait;
//////////////////////////////////////////////////////////////////////
//Create a fake questionanire to test the print process to pdf.
if (questionaire != null)
{
List<Question> question_list = new List<Question>();
List<Answer> answer_list = new List<Answer>();
Answer ans = new Answer();
ans.Answer_descr = "einai to dsfgdsfgsd";
answer_list.Add(ans);
answer_list.Add(ans);
answer_list.Add(ans);
Question quest = new Question() { AnswerList = answer_list };
quest.Question_descr = "H ekfoonisi tis erotisis aytis einai blablbalbablbalblab";
for (int i = 0; i < 10; i++)
{
question_list.Add(quest);
}
questionaire = new Quastionnaire.Model.Questionaire() { Questionaire_descr = "sdfsakdfjdflshsadflkjashflasdfkh", QuestionList = question_list };
}
//////////////////////////////////////////////////////////////////////
}
示例14: Page_Load
void Page_Load(object sender, EventArgs e)
{
// Create new PDF document
PdfDocument document = new PdfDocument();
this.time = document.Info.CreationDate;
document.Info.Title = "PDFsharp Clock Demo";
document.Info.Author = "Stefan Lange";
document.Info.Subject = "Server time: " +
this.time.ToString("F", CultureInfo.InvariantCulture);
// Create new page
PdfPage page = document.AddPage();
page.Width = XUnit.FromMillimeter(200);
page.Height = XUnit.FromMillimeter(200);
// Create graphics object and draw clock
XGraphics gfx = XGraphics.FromPdfPage(page);
RenderClock(gfx);
// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();
}
示例15: CreatePdf
public static void CreatePdf(Sheet sheet,string fullFileName)
{
PdfDocument document=new PdfDocument();
PdfPage page=document.AddPage();
CreatePdfPage(sheet,page);
document.Save(fullFileName);
}