本文整理匯總了C#中PdfSharp.Pdf.PdfDocument.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDocument.Close方法的具體用法?C# PdfDocument.Close怎麽用?C# PdfDocument.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PdfSharp.Pdf.PdfDocument
的用法示例。
在下文中一共展示了PdfDocument.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: createPDF
public void createPDF(Bitmap bmp, string saveAsPath)
{
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage(new PdfPage()); //new
//doc.Pages.Add(new PdfPage()); //old
page.Width = bmp.Height;
page.Height = bmp.Width;
page.Orientation = PdfSharp.PageOrientation.Landscape;
XGraphics xgr = XGraphics.FromPdfPage(page);
XImage image = XImage.FromGdiPlusImage(bmp);
xgr.DrawImage(image, 0, 0);
doc.Save(saveAsPath);
doc.Close();
}
示例2: combinaPDF
private static void combinaPDF(List<string> files)
{
string originalFile = files[0];
string destFile = "";
PdfDocument output;
//try
//{
// output = PdfReader.Open(originalFile, PdfDocumentOpenMode.Modify);
//}
//catch (PdfSharp.PdfSharpException)
//{
// destFile = System.IO.Path.GetTempFileName();
// System.IO.File.Copy(originalFile, destFile, true);
// output = new PdfDocument(destFile);
//}
destFile = System.IO.Path.GetTempFileName();
output = new PdfDocument(destFile);
foreach (string file in files)
{
//if (file != originalFile || !string.IsNullOrWhiteSpace(destFile))
//{
PdfDocument input = PdfReader.Open(file, PdfDocumentOpenMode.Import);
int count = input.PageCount;
for (int idx = 0; idx < count; idx++)
{
PdfPage page = input.Pages[idx];
output.AddPage(page);
}
System.IO.File.Delete(file);
//}
}
output.Save(originalFile);
output.Close();
output.Dispose();
if (!string.IsNullOrWhiteSpace(destFile))
{
System.IO.File.Delete(originalFile);
System.IO.File.Copy(destFile, originalFile, true);
System.IO.File.Delete(destFile);
}
}
示例3: button1_Click
private void button1_Click(object sender, EventArgs e)
{
string target = this.tbxInput.Text;
string cat = this.tbxSet.Text;
int size = int.Parse(this.tbxSize.Text);
string pdf = this.tbxOutput.Text;
int labelsize = int.Parse(this.tbxLabelSize.Text);
int lwidth = int.Parse(this.tbxWidth.Text);
int label_h = labelsize;
int size_w = size;
int size_h = size + label_h;
List<string> pdfpages = new List<string>();
IPageLayout3 layout = new PageLayoutClass();
IGraphicsContainer con = layout as IGraphicsContainer;
IPage page = layout.Page;
page.FormID = esriPageFormID.esriPageFormA4;
page.Units = esriUnits.esriPoints;
double width;
double height;
page.QuerySize(out width, out height);
int col = (int)Math.Floor(width / size_w);
int row = (int)Math.Floor(height / size_h);
IStyleGalleryStorage sgs = new StyleGalleryClass();
while (sgs.FileCount > 0)
{
sgs.RemoveFile(sgs.get_File(0));
}
IStyleGallery sg = sgs as IStyleGallery;
sgs.AddFile(target);
sgs.TargetFile = target;
if (cbPoint.Checked)
{
List<string> ps = ExportSymbol(sg, "Marker Symbols", col, row, size, lwidth,labelsize, label_h, size_w, size_h, height, cat, layout);
pdfpages.AddRange(ps);
}
if(cbLine.Checked)
{
List<string> ps = ExportSymbol(sg, "Line Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout);
pdfpages.AddRange(ps);
}
if (cbArea.Checked)
{
List<string> ps = ExportSymbol(sg, "Fill Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout);
pdfpages.AddRange(ps);
}
PdfDocument doc = new PdfDocument();
foreach (string temp in pdfpages)
{
PdfDocument temp_doc = PdfReader.Open(temp, PdfDocumentOpenMode.Import);
doc.AddPage(temp_doc.Pages[0]);
}
if (doc.PageCount > 0)
{
doc.Save(pdf);
}
doc.Close();
MessageBox.Show("成功生成符號圖集");
}
示例4: saveAsPdf
/// <summary>
/// Takes a Bitmap and a file path and saves the bitmap as a pdf
/// </summary>
/// <param name="bitmap"></param>
/// <param name="pathPdf"></param>
private void saveAsPdf(Bitmap bitmap, string pathPdf)
{
var doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
var xgr = XGraphics.FromPdfPage(doc.Pages[0]);
var img = XImage.FromGdiPlusImage(bitmap);
xgr.DrawImage(img, 0, 0, doc.Pages[0].Width, doc.Pages[0].Height);
doc.Save(pathPdf);
doc.Close();
}
示例5: MakePdf
private string MakePdf(IEnumerable<DownloadFile> listPictures)
{
try
{
using (var document = new PdfDocument())
{
document.Info.Creator = "[email protected] 1.3beta (http://unit6.ru/twain-web)";
var dir = Path.GetTempPath();
foreach (var image in listPictures)
{
// Create an empty page
var page = document.AddPage();
// Get an XGraphics object for drawing
var gfx = XGraphics.FromPdfPage(page);
var ximage = XImage.FromFile(dir + image.TempFile);
page.Height = ximage.PointHeight;
page.Width = ximage.PointWidth;
gfx.DrawImage(ximage, 0, 0);
ximage.Dispose();
}
var file = Path.GetTempFileName();
document.Save(file);
document.Close();
var fileId = Path.GetFileName(file);
GlobalDictionaries.Scans.Add(fileId);
return fileId;
}
}
catch (Exception ex) { return null; }
}
示例6: Select2PDF
public void Select2PDF()
{
foreach (ListViewItem Item in listView1.SelectedItems)
{
Debug.Print(Item.Index.ToString());
PdfDocument doc = new PdfDocument();
//int pageCount = listView1.Items.Count;
//for (int i = 0; i <= pageCount - 1; i++)
//{
PdfPage page = new PdfPage();
//Image tiffImg = tiff.getTiffImage(fileName, i);
//Image tiffImg = Image.FromFile(Application.StartupPath + "temp" + i + ".png");
Image tiffImg = Image.FromStream(imgLst[Item.Index].ImageStream);
XImage img = XImage.FromGdiPlusImage(tiffImg);
page.Width = img.PointWidth;
page.Height = img.PointHeight;
doc.Pages.Add(page);
//XGraphics xgr = XGraphics.FromPdfPage(doc.Pages(i));
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
xgr.DrawImage(img, 0, 0);
string filename = "temp" + (Item.Index +1) + ".pdf";
doc.Save(filename);
doc.Close();
}
}
示例7: WriteToPdf
public static bool WriteToPdf(string tifFileName, string pdfFileName, string author = null, string title = null, string isbn = null)
{
if (String.IsNullOrEmpty(tifFileName)) new ArgumentNullException("tifFileName");
if (!System.IO.File.Exists(tifFileName)) throw new ArgumentException(String.Format("Soubor '{0}' neexistuje, nelze vytvořit PDF soubor.", tifFileName));
if (File.Exists(pdfFileName)) File.Delete(pdfFileName);
using (PdfDocument doc = new PdfDocument())
{
doc.Info.Author = author;
doc.Info.Title = title;
doc.Info.Keywords = String.Format("ISBN:{0}", isbn);
doc.Info.Subject = "OBSAH";
doc.Info.Creator = App.Configuration.CompanyName;
doc.Info.CreationDate = DateTime.Now;
Image tiff = System.Drawing.Image.FromFile(tifFileName);
int count = tiff.GetFrameCount(FrameDimension.Page);
for (int pageNum = 0; pageNum < count; pageNum++)
{
tiff.SelectActiveFrame(FrameDimension.Page, pageNum);
XImage ximg = XImage.FromGdiPlusImage(tiff);
PdfPage page = new PdfPage();
page.Width = ximg.PointWidth;
page.Height = ximg.PointHeight;
doc.Pages.Add(page);
XGraphics xgr = XGraphics.FromPdfPage(page);
xgr.DrawImage(ximg, 0, 0);
}
doc.Save(pdfFileName);
doc.Close();
}
return true;
}
示例8: MakePdf
void MakePdf()
{
// Let's torture the garbage collector...
const int fileCount = 1;
const int pageCount = 1;
string lastFilename = "";
for (int fileIdx = 0; fileIdx < fileCount; fileIdx++)
{
string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf";
//PdfSharp.Drawing.XGraphic gfx = new PdfSharp.Drawing.XGraphic();
PdfDocument document = new PdfDocument(filename);
document.Options.ColorMode = XGraphicsLab.properties.General.ColorMode;
#if true_
DateTime now = DateTime.Now;
for (int i = 0; i < 10000000; i++)
document.Info.Title = "Hallö €-δ-α-β-☺♥♦♠♣x";
TimeSpan span = DateTime.Now - now;
Debug.WriteLine("span = " + span.TotalSeconds.ToString());
#endif
for (int pageIdx = 0; pageIdx < pageCount; pageIdx++)
{
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsLab.properties.General.PageDirection);
if (this.renderEvent != null)
this.renderEvent(gfx);
}
//document.WriteToFile(filename);
#if true_
// Check protection
document.SecuritySettings.UserPassword = "x";
document.SecuritySettings.OwnerPassword = "y";
//document.SecuritySettings.PermitModifyDocument = false;
//document.SecuritySettings.PermitPrint = true;
#endif
document.Close();
lastFilename = filename;
}
UpdateStatusBar();
Process.Start(lastFilename);
}
示例9: CreateParcourPDF
//.........這裏部分代碼省略.........
double distX = picBox.GetXDistanceKM() / 2;//1:200 000 in cm
double distY = picBox.GetYDistanceKM() / 2;//1:200 000 in cm
gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter));
double startX = 190;
List<XPoint> points = new List<XPoint>();
points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40)));
points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40)));
points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40 + 9)));
points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40 + 9)));
points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40)));
gfx.DrawLines(XPens.Black, points.ToArray());
for (int i = 0; i < 5; i++)
{
if (i == 1) continue;
points = new List<XPoint>();
points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40)));
points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40 + 9)));
gfx.DrawLines(XPens.Black, points.ToArray());
}
gfx.DrawString("Comp. Nr:",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(40 + 7)));
gfx.DrawString("Track:",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 18 * 3 + 1), Unit.FromMillimeter(40 + 7)));
double startY = 40 + 9 + 5;
double colWidth = 18;
double rowHeight = 9;
for (int i = 0; i < 16; i++)
{
points = new List<XPoint>();
points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(startY + i * rowHeight)));
points.Add(new XPoint(Unit.FromMillimeter(startX + colWidth * 5), Unit.FromMillimeter(startY + i * rowHeight)));
gfx.DrawLines(XPens.Black, points.ToArray());
}
for (int i = 0; i < 6; i++)
{
points = new List<XPoint>();
points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY)));
points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY + 15 * rowHeight)));
gfx.DrawLines(XPens.Black, points.ToArray());
}
gfx.DrawString("Dist.",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + colWidth * 1 + 1), Unit.FromMillimeter(startY + 7)));
gfx.DrawString("TT",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + colWidth * 2 + 1), Unit.FromMillimeter(startY + 7)));
gfx.DrawString("EET",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + colWidth * 3 + 1), Unit.FromMillimeter(startY + 7)));
gfx.DrawString("ETO",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + colWidth * 4 + 1), Unit.FromMillimeter(startY + 7)));
gfx.DrawString("T/O",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 1 + 7)));
gfx.DrawString("SP",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 2 + 7)));
for (int i = 3; i < 13; i++)
{
gfx.DrawString("TP" + (i - 3),
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * i + 7)));
}
gfx.DrawString("FP",
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 13 + 7)));
gfx.DrawImage(XImage.FromFile(@"Resources\Summe.png"),
new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 14 + 2)));
if (overlayText != null && overlayText != "")
{
XRect rect = new XRect(new XPoint(Unit.FromMillimeter(startX - 80 - 2), Unit.FromMillimeter(startY + rowHeight * 14 + 2 - 16)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6)));
gfx.DrawRectangle(XBrushes.White, rect);
XTextFormatter tf = new XTextFormatter(gfx);
tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft);
}
doc.Save(pathToPDF);
doc.Close();
Process.Start(pathToPDF);
}
示例10: MakePdf
/// <summary>
/// Create a new PDF document and start the viewer.
/// </summary>
void MakePdf()
{
string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf";
PdfDocument document = new PdfDocument(filename);
document.Info.Creator = "Preview Sample";
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
if (this.renderEvent != null)
this.renderEvent(gfx);
document.Close();
Process.Start(filename);
}
示例11: CreateResultPDF
public static void CreateResultPDF(VisualisationPictureBox picBox, Client.DataAccess c, QualificationRound competition, List<ComboBoxFlights> competitionTeam, String pathToPDF)
{
int counter = 0;
List<Flight> tempList = new List<Flight>();
foreach (ComboBoxFlights cbct in competitionTeam)
{
GC.Collect();
PdfDocument doc = new PdfDocument();
doc.Info.Author = "[email protected]";
doc.Info.Keywords = "ANRL Results Printout";
doc.Info.Subject = "Results Printout generated from ANRL Client on " + DateTime.Now.ToString();
doc.Info.Title = "Results Printout";
doc.Options.ColorMode = PdfColorMode.Cmyk;
doc.Language = "EN";
doc.PageLayout = PdfPageLayout.SinglePage;
tempList.Clear();
tempList.Add(cbct.flight);
picBox.SetData(tempList);
PdfPage page = doc.AddPage();
page.Orientation = PdfSharp.PageOrientation.Landscape;
page.Size = PdfSharp.PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
AddLogo(gfx, page);
XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage);
double distX = picBox.GetXDistanceKM() / 2;//1:200 000 in cm
double distY = picBox.GetYDistanceKM() / 2;//1:200 000 in cm
gfx.DrawImage(image, XUnit.FromCentimeter(2).Point, XUnit.FromCentimeter(3).Point, page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter));
gfx.DrawString("Competition: " + c.SelectedCompetition.Name,
new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black,
new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(1.5)));
gfx.DrawString("Q-Round: " + competition.Name,
new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black,
new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.1)));
gfx.DrawString("Crew: " + getTeamDsc(c, cbct.flight),
new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black,
new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.7)));
int sum = 0;
int line = 0;
int offsetLine = 20;
//gfx.DrawString("ID", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3)));
gfx.DrawString("Points ", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3)));
gfx.DrawString("Reason ", new XFont("Verdana", 11, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3)));
foreach (Penalty penalty in cbct.flight.Penalty)
{
sum += penalty.Points;
line++;
//gfx.DrawString(penalty.ID.ToString(), new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3 + line * 0.4)));
gfx.DrawString(penalty.Points.ToString(), new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)));
List<String> reason = getWrapped(penalty.Reason);
bool loop = false;
foreach (String s in reason)
{
gfx.DrawString(s, new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4)));
line++;
loop = true;
}
if (loop)
{
line--;
}
}
line++;
//gfx.DrawString("-", new XFont("Verdana", 9, XFontStyle.Regular), XBrushes.Black, new XPoint(XUnit.FromCentimeter(18), XUnit.FromCentimeter(3 + line * 0.4)));
gfx.DrawString(sum.ToString(), new XFont("Verdana", 10, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)));
gfx.DrawString("Total Points", new XFont("Verdana", 10, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4)));
String path = pathToPDF.Replace(".pdf", (counter++ + "_" + getTeamDsc(c, cbct.flight) + ".pdf"));
doc.Save(path);
doc.Close();
Process.Start(path);
}
}
示例12: CreateParcourPDF100k
public static void CreateParcourPDF100k(ParcourPictureBox picBox, Client.DataAccess c, String parcourName, String pathToPDF, String overlayText)
{
PdfDocument doc = new PdfDocument();
doc.Info.Author = "[email protected]";
doc.Info.Keywords = "ANRL Parcour Printout";
doc.Info.Subject = "Parcour Printout generated from ANRL Client on " + DateTime.Now.ToString();
doc.Info.Title = "Parcour Printout";
doc.Options.ColorMode = PdfColorMode.Cmyk;
doc.Language = "EN";
doc.PageLayout = PdfPageLayout.SinglePage;
PdfPage page = doc.AddPage();
page.Orientation = PdfSharp.PageOrientation.Landscape;
page.Size = PdfSharp.PageSize.A3;
XGraphics gfx = XGraphics.FromPdfPage(page);
AddLogo(gfx, page);
gfx.DrawString("Competition: " + c.SelectedCompetition.Name,
new XFont("Verdana", 16, XFontStyle.Bold), XBrushes.Black,
new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2)));
gfx.DrawString("Parcour: " + parcourName,
new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black,
new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(3)));
XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage);
double distX = picBox.GetXDistanceKM();//1:100 000 in cm
double distY = picBox.GetYDistanceKM();//1:100 000 in cm
gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter));
if (overlayText != null && overlayText != "")
{
XRect rect = new XRect(new XPoint(Unit.FromCentimeter(page.Width.Centimeter - 8), Unit.FromCentimeter(page.Height.Centimeter-4)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6)));
gfx.DrawRectangle(XBrushes.White, rect);
XTextFormatter tf = new XTextFormatter(gfx);
tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft);
}
doc.Save(pathToPDF);
doc.Close();
Process.Start(pathToPDF);
}
示例13: btnScan_Click
//Scanner Click Event
private void btnScan_Click(object sender, EventArgs e)
{
try
{
// Select the scanner from list
var device = lbDevices.SelectedItem as Scanner;
this.txtProgress.Text="You selected "+device+" as your Scanner";
if (device == null)
{
System.Windows.MessageBox.Show("Please select a device.", "Warning");
return;
}
// Scan
var image = device.Scan();
//List to hold images
List<WIA.ImageFile> wiaImagesList = new List<WIA.ImageFile>();
//Add to list
wiaImagesList.Add(image);
if (wiaImagesList.Count() == 0)
{ return; }
this.txtProgress.Text = "Scanning in Progress...........";
//creat pdf
PdfDocument doc = new PdfDocument();
string destination = @"C:\ScannerFolder\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
string tempDestination = @"C:\TempScannerFolder" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
//create folder to store image
System.IO.Directory.CreateDirectory(folderName);
System.IO.Directory.CreateDirectory(tempFolderName);
foreach (WIA.ImageFile img in wiaImagesList)
{
//For each image to be scanned
string tempFilename = @"C:\ScannerFolder\" + rtbResult.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".tiff";
string filename = @"C:\TempScannerFolder\" + rtbResult.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".tiff";// can get barcode from rtbResult.Text to save image as barcode
//save the tiff
image.SaveFile(filename);
//add image to the pdf and Custom user control and save
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage imgX = XImage.FromFile(filename);
xgr.DrawImage(imgX, 0, 0);
//save to destinatin folder
doc.Save(destination);
//doc.Save(tempFilename);
showPath.Text += destination;
tempList.Add(destination);
doc.Close();
this.txtProgress.Text = "Scanning complete, converting to PDF";
// User control to display pdf
var uc = new UserControl1(destination);
this.windowsFormsHost1.Child = uc;
}
//Convert Wia imageFile to a bitmap
Bitmap bmp = ConvertImageToBitmap(image);
DateTime dtStart = DateTime.Now;
//read barcode form Bitmap
string[] barcode = ReadBarcodeFromBitmap(bmp);
// Show the results in a message box
string result = string.Empty;
if (barcode != null)
{
foreach (String code in barcode){
result += code;
}
}
else{
result += "Failed to find a barcode.";
}
//Show barcode
rtbResult.Text = result;
GetDocumentType();
}
catch (Exception)
{
System.Windows.MessageBox.Show("A scanner error occoured, check feeder");
}
}
示例14: btnPdf_Click
private void btnPdf_Click(object sender, System.EventArgs e)
{
string filename = Guid.NewGuid().ToString().ToUpper() + ".pdf";
PdfDocument document = new PdfDocument(filename);
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
XGraphics gfx = XGraphics.FromPdfPage(page);
this.chartFrame.Draw(gfx);
document.Close();
Process.Start(filename);
}
示例15: MakePDF
public void MakePDF(List<int[,]> cards)
{
string imgName = @"BingoPlader.png";
string imgSource = Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\", @"Resources\", imgName);
if (_outputDirectory != null)
{
imgSource = _outputDirectory;
}
string saveLoc = imgSource.Replace("png", "pdf");
PdfDocument doc = new PdfDocument();
XImage img = XImage.FromFile(imgSource);
XFont numberFont = new XFont("Verdana", 125, XFontStyle.Italic);
XFont plateNumFont = new XFont("Verdana", 30, XFontStyle.Regular);
XImage pdfSize = XImage.FromFile(imgSource);
#region PixelStuff
int startPlateY = 834;
int startX = 356;
int jumpX = 222;
int jumpY = 240;
int jumpYPlate = 796;
int plateNumX = 45;
int plateNumY = 3300;
#endregion
for (int i = 0; i < cards.Count; i++)
{
if (cards[i][0,0] != -1)
{
PdfPage page = new PdfPage(); //Template for page
//XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4);
page.Width = pdfSize.PixelWidth;
page.Height = pdfSize.PixelHeight;
page.TrimMargins.Top = 0;
page.TrimMargins.Right = 0;
page.TrimMargins.Bottom = 0;
page.TrimMargins.Left = -30;
doc.Pages.Add(page);
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[doc.PageCount-1]);
xgr.DrawImage(img, 0, 0, page.Width, page.Height);
int plateChooser = startPlateY;
int rowChooser = plateChooser;
int columnChooser = startX;
for (int j = 0; j < 3; j++) //Pladenummer. Styrer y-akses startpunkt
{
rowChooser = plateChooser;
for (int row = 0; row < 3; row++) //rækkenummer. Placerer y-akseværdi
{
for (int column = 0; column < 9; column++)
{
if (cards[i][column, row] != 0)
{
if (cards[i][column, row] < 10)
{
xgr.DrawString(" " + Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft);
}
else
xgr.DrawString(Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft);
}
columnChooser += jumpX; //Hopper med en kolonne per iteration
}
columnChooser = startX;
rowChooser += jumpY; //Hopper en række per iteration
}
plateChooser += jumpYPlate; // hopper en plade per iteration
}
xgr.DrawString("Pladenummer: " + Convert.ToString(i), plateNumFont, XBrushes.Black, new XRect(plateNumX, plateNumY, 10, 0), XStringFormats.TopLeft);
}
}
doc.Save(saveLoc);
doc.Close();
}