what is the reference for "Document" in this code? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have this code for opening a PDF file and editing it's content but I don't know what the reference of "Document" in this code is . Here is my code :
//Open document
Document pdfDocument = new Document("input.pdf");
//Get particular page
Page pdfPage = (Page)pdfDocument.Pages[1];
//Create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.Position = new Position(100, 600);
//Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment.TextState.BackgroundColor=Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
textFragment.TextState.ForegroundColor=Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
//Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
//Append the text fragment to the PDF page
textBuilder.AppendText(textFragment);
//Save document
pdfDocument.Save("output.pdf");

This code works with a library called Aspose.Pdf for .NET which is a commercial product. You need to buy that library or download a trial, then add the dll that you will download as reference to your project.
I'm sure the code sample was taken from a website. Look on the products from their page if you are interesting in buying. There are also free solutions for PDF. I only used ITextSharp.

Related

How would I extract an image link from a webpage using c#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
The community is reviewing whether to reopen this question as of 7 months ago.
Improve this question
I have some code already, but let's say I have a picture box in a windows forms app which updates to a random image whenever you click it.
How do I extract an image from a website (e.g. https://prnt.sc/hello1)
The image link is located under in the src=
<img class="no-click screenshot-image" src="https://image.prntscr.com/image/HENolz07Ty_AA4RwYdZVGg.png" crossorigin="anonymous" alt="Lightshot screenshot" id="screenshot-image" image-id="hello1">
The code I have already is:
var image = "";
pictureBox1.ImageLocation = image;
pictureBox1.Update();
How could I (with only the page page url) find the image on the page and define it to 'image' (preferably using c#)
use AngleSharp to get the page HTML and then select the desired element using various selectors. Then you can use the HttpClient to download the file
using AngleSharp;
using System.Net;
var config = Configuration.Default.WithDefaultLoader();
var address = "https://prnt.sc/hello1";
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(address);
var imgSelector = "#screenshot-image";
var cells = document.QuerySelectorAll(imgSelector);
var imageAddress = cells.First().GetAttribute("src");
var client = new HttpClient();
var stream = await client.GetStreamAsync(imageAddress);
using (var fileStream = File.Create(AppDomain.CurrentDomain.BaseDirectory + #"\img.png"))
{
stream.CopyTo(fileStream);
}

Programmatically tag an untagged pdf with iTextSharp [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to parse a PDF file with iTextSharp. With tagged PDFs I used TaggedPdfReaderTool and the .ConvertToXml() method which returned me an acceptable XML for further parsing. Now I have to parse untagged PDFs which I need to parse! In Adobe Acrobat you can add tags to a PDF using their accessibility tool. After that I'm able to parse it with iTextSharp. Now I'm looking for a free solution to add tags to my PDF programmatically (with iTextSharp). In the book "iText in Action" I've read that you can create a tagged PDF (from an XML file) but i need to convert an existing one!
My code for parsing tagged PDFs:
var path = #"C:\Users\xxx\Desktop\xxx.pdf";
var fs = new FileStream(#"C:\Users\xxx\Desktop\xxx_tagged.xml", FileMode.Create);
PdfReader reader = new PdfReader(path);
TaggedPdfReaderTool tool = new TaggedPdfReaderTool();
tool.ConvertToXml(reader, fs);
fs.Close();
This is not an easy problem. Since you are essentially asking for a solution to do structure recognition.
Think about it. You want to know where paragraphs begin and end, you'd need a solution for figuring out tables and lists. Not to mention nested tables and lists and combinations thereof.
This is the topic of research. One popular approach is to use neural networks (treating the pdf as an image and tackling it as an image recognition task), or alternatively tackle it in a rule-based fashion.

Excel to HTML Table using C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is it possible to convert an excel spreadsheet to html code, and if so what would be the best way to do so (basic code to give an idea of how to handle things)? I'm creating a web app that allows a user to upload a spread sheet and output the html code to be copied into a CMS using clean code.
Note: I'm not looking for a full code example or anything, just something to give me the right idea of how to approach this problem.
UPDATE: The answer below accurately sums up what I'm looking for. Pretty much open the file in memorystream and then format everything into a table.
In my opinion the most clean and robust solution would be processing an xlsx file in your own method and then returning string with HTML. There's very pleasant package called EPPlus, which allows you to easily manage xlsx files. You can easily iterate through columns and rows and generate HTML in any shape you want.
It could look something like that:
public string XlsxToHTML(byte[] file)
{
MemoryStream stream = new MemoryStream(file);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("<table>");
using(ExcelPackage excelPackage = new ExcelPackage(stream))
{
ExcelWorkbook workbook = excelPackage.Workbook;
if(workbook!=null)
{
ExcelWorksheet worksheet = workbook.Worksheets.FirstOrDefault();
if(worksheet!=null)
{
var firstCell = worksheet.Cells[1,1].Value;
var secondCell = worksheet.Cells[1,2].Value;
stringBuilder.Append("<tr><td>"+firstCell+"</td></tr>");
stringBuilder.Append("<tr><td>"+firstCell+"</td></tr>");
}
}
}
stringBuilder.Append("</table>");
return stringBuilder.ToString();
}
Of course it's merely an example. It's dirty because it appends tags and so on, but it's a quick example of the idea...

How to implement pdf in asp.net using C# or JavaScript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am creating a project on online movie ticket booking. Now I want to create a pdf file of ticket. How to create or generate a pdf file.
To generate pdf go for below code
Document document = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter writer = PdfWriter.GetInstance(document , new FileStream(#"C:\YourPdf.pdf", FileMode.Create));
document .Open();
Paragraph paragraph = new Paragraph("Hi, \n This is my pdf file");
document .Add(paragraph);
document .Close();
For more information :-
http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in
http://www.dotnetfox.com/articles/how-to-create-pdf-document-in-Asp-Net-with-C-Sharp-using-itextsharp-1023.aspx
I've used PDF4Net in the past, it's very easy to use.
In addition I have used PDFSharp and it's very simple and intuitive!
Cheers

open pdf file C# and asp.net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have some customers in a gridview. When I click on the customers I can get their names in a textbox. There is also a corresponding pdf document which should also be available if the user desires.
My problem is that I need to know who to open a pdf document using C# and asp.net. I have to use a variable name as the name of pdf document, for example when the click on a button "open variable CustomerName.pdf".
I need to open a pdf file in a new window for viewing
thanks
this works
asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/customerUnit/Customer.pdf" Target="_blank">HyperLink
But I want to pass the pdf file as a variable "Customer.pdf" should be "VaribleCustmer.pdf"
I agree with #Ahmed from the comments, you shouldn't over-think this:
Simply link to the CustomerName.pdf if your using a hyperlink.
Simply redirect to the CustomerName.pdf if your using a button
But I want to pass the pdf file as a variable "Customer.pdf" should be "VaribleCustmer.pdf"
Asp Markup:
<asp:HyperLink ID="HyperLink1"
runat="server" Target="_blank">
Code behind:
var pdfFile = "Customer.pdf"; //or VaribleCustmer.pdf
HyperLink1.NavigateUrl= String.Format("~/customerUnit/{0}", pdfFile);

Categories