本文整理汇总了C#中PdfDocument.LoadFromFile方法的典型用法代码示例。如果您正苦于以下问题:C# PdfDocument.LoadFromFile方法的具体用法?C# PdfDocument.LoadFromFile怎么用?C# PdfDocument.LoadFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PdfDocument
的用法示例。
在下文中一共展示了PdfDocument.LoadFromFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例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: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"..\..\..\..\..\..\Data\Sample2.pdf");
StringBuilder buffer = new StringBuilder();
IList<Image> images = new List<Image>();
foreach (PdfPageBase page in doc.Pages)
{
buffer.Append(page.ExtractText());
foreach (Image image in page.ExtractImages())
{
images.Add(image);
}
}
doc.Close();
//save text
String fileName = "TextInPdf.txt";
File.WriteAllText(fileName, buffer.ToString());
//save image
int index = 0;
foreach (Image image in images)
{
String imageFileName
= String.Format("Image-{0}.png", index++);
image.Save(imageFileName, ImageFormat.Png);
}
//Launching the Pdf file.
PDFDocumentViewer(fileName);
}
示例4: dicret_download_Click
private void dicret_download_Click(object sender, EventArgs e)
{
try
{
//MessageBox.Show("打印出错");
string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString();
foreach (var item in jsonlist)
{
if (current_id == item.id)
{
string filename = "";
filename = path + "\\" + item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name;
if (File.Exists(@filename))
{
filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name;
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(path + "/" + filename);
PrintDialog dialogprint = new PrintDialog();
List<string> printerlist = new List<string>();
List<string> printers_only_canduplex = new List<string>();
List<string> printers_only_supportcolor = new List<string>();
List<string> printers_canduplex_supportcolor = new List<string>();
List<string> printers_no_cando = new List<string>();
string defaultprinter = dialogprint.PrinterSettings.PrinterName;
foreach (string printname in PrinterSettings.InstalledPrinters)
{
if (!printerlist.Contains(printname))
{
printerlist.Add(printname);
}
}
printerlist.Remove("Microsoft XPS Document Writer");
printerlist.Remove("Fax");
foreach (string printername in printerlist)
{
if (!printers_only_canduplex.Contains(printername))
{
dialogprint.PrinterSettings.PrinterName = printername;
if ((dialogprint.PrinterSettings.CanDuplex) && (!dialogprint.PrinterSettings.SupportsColor))
{
printers_only_canduplex.Add(printername);
}
}
}
foreach (string printername in printerlist)
{
if (!printers_only_supportcolor.Contains(printername))
{
dialogprint.PrinterSettings.PrinterName = printername;
if ((dialogprint.PrinterSettings.SupportsColor) && (!dialogprint.PrinterSettings.CanDuplex))
{
printers_only_supportcolor.Add(printername);
}
}
}
foreach (string printername in printerlist)
{
if (!printers_canduplex_supportcolor.Contains(printername))
{
dialogprint.PrinterSettings.PrinterName = printername;
if ((dialogprint.PrinterSettings.SupportsColor) && (dialogprint.PrinterSettings.CanDuplex))
{
printers_canduplex_supportcolor.Add(printername);
}
}
}
foreach (string printername in printerlist)
{
if (!printers_no_cando.Contains(printername))
{
dialogprint.PrinterSettings.PrinterName = printername;
if ((!dialogprint.PrinterSettings.CanDuplex) && (!dialogprint.PrinterSettings.SupportsColor))
{
printers_no_cando.Add(printername);
}
}
}
if (printerlist.Count == 0)
{
throw new Exception("该电脑并未安装打印机");
}
dialogprint.PrinterSettings.PrinterName = defaultprinter;
if ((item.color == "0") && (item.double_side == "单面"))
{
if (dialogprint.PrinterSettings.SupportsColor)
{
if (printers_no_cando.Count == 0)
{
if (printers_only_canduplex.Count == 0)
{
if (printers_only_supportcolor.Count == 0)
{
dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0];
}
//.........这里部分代码省略.........
示例5: GetImages
public List<Image> GetImages(string filePath)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(filePath);
return GetImages(doc);
}
示例6: set_before_print_Click
private void set_before_print_Click(object sender, EventArgs e)
{
try
{
//MessageBox.Show("打印出错");
string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString();
foreach (var item in jsonlist)
{
if (current_id == item.id)
{
string filename = "";
filename = path + "\\" + item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name;
if (File.Exists(@filename))
{
filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name;
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(path + "/" + filename);
PrintDialog dialogprint = new PrintDialog();
dialogprint.UseEXDialog = true;
dialogprint.AllowPrintToFile = true;
dialogprint.AllowSomePages = true;
dialogprint.PrinterSettings.MinimumPage = 1;
dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count;
dialogprint.PrinterSettings.FromPage = 1;
dialogprint.PrinterSettings.Collate = true;
//dialogprint.PrinterSettings.CanDuplex = true;
//dialogprint.PrinterSettings.
dialogprint.PrinterSettings.ToPage = doc.Pages.Count;
string copy = item.copies.Substring(0, 1);
dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy);
//dialogprint.ShowDialog();
if (dialogprint.ShowDialog() == DialogResult.OK)
{
doc.PrintFromPage = dialogprint.PrinterSettings.FromPage;
doc.PrintToPage = dialogprint.PrinterSettings.ToPage;
doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings;
PrintDocument printdoc = doc.PrintDocument;
dialogprint.Document = printdoc;
printdoc.Print();
}
break;
}
else
{
filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name;
//get 文件详细信息 URI操作示意: GET /File/1234
string jsonUrl = API.GetMethod("/File/" + item.id);
JObject jo = JObject.Parse(jsonUrl);
ToJsonMy thisOne = new ToJsonMy();
thisOne.url = (jo)["url"].ToString();
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
WebClient webClient = new WebClient();
String pathDoc = path + "/" + filename;
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted);
webClient.DownloadFileAsync(new Uri(thisOne.url), pathDoc, id);
//fileDownload(thisOne.url, filename, item.id);
MessageBox.Show("正在下载该文件!\n请等待,稍后请再次点击打印按钮");
}
break;
}
}
}
catch (Exception excep)
{
MessageBox.Show(excep.Message, "无法打印");
}
}
示例7: Main
static void Main(string[] args)
{
// Check if path was provided
if (args.Length == 0)
{
Console.WriteLine("Please enter a path to read for image/PDF files! Exiting..");
return;
}
var path = args[0];
if (!System.IO.Directory.Exists(path))
{
Console.WriteLine("Invalid path, does not exist! Exiting..");
return;
}
var outputPath = Path.Combine(path, "output");
if (!System.IO.Directory.Exists(outputPath))
System.IO.Directory.CreateDirectory(outputPath);
var files = System.IO.Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly)
.Where(
f => f.ToLower().EndsWith(".jpg") ||
f.ToLower().EndsWith(".jpeg") ||
f.ToLower().EndsWith(".png") ||
f.ToLower().EndsWith(".pdf"));
foreach (var file in files)
{
var lowerFile = file.ToLower();
if (lowerFile.EndsWith(".pdf"))
{
Console.WriteLine($"Current file: {file}");
var pdf = new PdfDocument();
pdf.LoadFromFile(file);
// Save first page of PDF
using (var bmp = pdf.SaveAsImage(0))
{
var outputFilename = Path.Combine(outputPath, $"{Path.GetFileNameWithoutExtension(file)}.jpg");
Console.WriteLine($"Saving jpg to {outputFilename}");
bmp.Save(outputFilename, ImageFormat.Jpeg);
}
}
else if (lowerFile.EndsWith(".png"))
{
Console.WriteLine($"Current file: {file}");
RotateImageIfNeeded(file, outputPath);
}
else if (lowerFile.EndsWith(".jpg") || lowerFile.EndsWith(".jpeg"))
{
Console.WriteLine($"Current file: {file}");
try
{
var dirs = ImageMetadataReader.ReadMetadata(file);
if (dirs.Any())
{
Console.WriteLine("meta data to read");
}
var dir = dirs.Where(d => d.Name.Equals("Exif IFD0")).SingleOrDefault();
if (dir != null)
{
var orientation = dir.Tags.Where(t => t.TagName.Equals("Orientation")).SingleOrDefault();
if (orientation != null)
{
Console.WriteLine($"-- orientation = {orientation.Description}, dir name = {dir.Name}");
ExifRotateImageIfNeeded(file, outputPath);
}
else
{
Console.WriteLine("-- orientation not found!");
RotateImageIfNeeded(file, outputPath);
}
}
else
{
Console.WriteLine("-- orientation not found!");
RotateImageIfNeeded(file, outputPath);
}
//foreach (var dir in dirs)
//{
// {
// }
//}
//foreach (var tag in dir.Tags)
// Console.WriteLine($"{dir.Name} - {tag.TagName} = {tag.Description}");
}
catch (Exception ex)
{
Console.WriteLine("UNABLE TO READ");
//.........这里部分代码省略.........
示例8: GetMenu
/// <summary>
/// Gets this weeks menu from admin.ordbogen.com
/// </summary>
public void GetMenu()
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
Calendar cal = dfi.Calendar;
int weekNo = cal.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
string path = "https://admin.ordbogen.com";
string pathMenu = "https://admin.ordbogen.com";
string localPdfFile = Controller.dir + "menu.pdf";
string thisWeeksMenu = Controller.dir + "menu " + weekNo + ".png";
string LastWeekMenu = Controller.dir + "menu " + (weekNo - 1) + ".png";
if (File.Exists(LastWeekMenu) || !File.Exists(thisWeeksMenu))
{
try
{
HtmlDocument doc = new HtmlWeb().Load(path, "GET", new System.Net.WebProxy(), new System.Net.NetworkCredential(Authentication.getAuthorization(true), Authentication.getAuthorization(false)));
if (doc != null)
{
var aNodes = doc.DocumentNode.SelectNodes("//a");
var element = new HtmlNode(HtmlNodeType.Element, doc, 0);
foreach (var item in aNodes)
{
if (item.InnerText.ToLower().Contains("menu"))
if (item.InnerText.Contains(weekNo.ToString()))
element = item;
}
var attributes = element.Attributes;
foreach (var item in attributes)
{
if (item.Name == "href")
{
pathMenu += item.Value;
}
}
WebClient wb = new WebClient();
wb.Credentials = new NetworkCredential(Authentication.getAuthorization(true), Authentication.getAuthorization(false));
wb.DownloadFile(pathMenu, localPdfFile);
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(localPdfFile);
Image bmp = pdf.SaveAsImage(0);
bmp.Save(thisWeeksMenu, ImageFormat.Png);
File.Delete(localPdfFile);
if (File.Exists(LastWeekMenu))
File.Delete(LastWeekMenu);
}
else
{
if (CheckInternetConnection())
{
System.Windows.MessageBox.Show(@"Der kan være opstået et problem med brugeren til i AdminUsers.txt. Opdater den her: C:\Users\[User]\(SKJULT)AppData\Local\ATIS", "MainStorage Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}
}
}
catch (Exception e) { System.Windows.MessageBox.Show(e.Message); }
}
}