Edit Metadata of PDF File with C# [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
i searching for methods or libarys to edit metadata of a pdf file like the programm becypdfmetaedit.
I want to write a program and i need this opton in this program.
Perhaps you have some samples for c#.
Thanks

Using PDF Sharp works like this:
using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main (string[] args)
{
Program p = new Program();
p.Test();
}
public void Test ()
{
PdfDocument document = PdfReader.Open ("Test.pdf");
document.Info.Author = "ME";
document.Save ("Result");
}
}
}

For PDFSharp:
If you would like to change/add the metadata on the Custom Properties of a PDF you can use the PdfDocument.Info.Elements object.
String filename = #"d:\temp\Hugo-input.pdf";
String outputfile = #"d:\temp\Hugo-output.pdf";
PdfDocument document = PdfReader.Open(filename);
document.Info.Elements.Add(new KeyValuePair<String,PdfItem>("/MyKey",new PdfString("MyValue")));
document.Save(outputfile);
Always start a custom key with a slash!
You can find the key and value when you open this document in Adobe Acrobat Reader -> File -> Properties -> Custom.
This works with PDFSharp 1.32

I suppose you can do it with iTextSharp.

Does the PdfDocumentInformation class from PDF Sharp fulfill your requirements.

Pimping here - my company, Atalasoft, makes .NET components for working with images. Part of the suite includes the ability to read/write PDF document metadata. It's not free, but it is run-time royalty free for desktop applications.
The code for reading is simple:
PdfDocumentMetadata metadata = PdfDocumentMetadata.FromStream(sourceStream);
to edit it and write it back to the same stream:
meta.Title = "Knicholas Knickleby";
meta.Author = "Edmund Wells";
sourceStream.Seek(0, SeekOrigin.Begin);
meta.Append(sourceStream, false); // false means don't merge - overwrite
Custom fields are supported through a hashtable.

Aspose.PDF or Aspose.PDF.Kit can do this for you.

Related

C# ASP.NET MVC Create PDF from view Rotativa or iTextSharp? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am very unfamiliar with generating PDF from multiple forms.
In fact, I've never generated a PDF using any kind of programming language. Now I have been trying 2 different methods for what I want to do. Unfortunately after a few days I still haven't found out how to do this.
I have multiple forms with data pre-filled in those using 3 different lists, now I want to generate a PDF of this form and I have been using Rotativa for this. Unfortunately, once I call the method to generate the PDF, it generates a PDF of the view, but the data is missing. With iTextSharp I could have the data of 1 single list, not all of them, also I dont know if it is possible to save this PDF on the server using iTextSharp.
Q1: What method should I use? What do you suggest? using Rotativa or iTextSharp?
Q2: Is this doable for someone without much experience in programming or should I try to find another way? I
Q3: Am I still missing a way to do this? I would prefer a method without using 3rd party software.
public byte[] GetPDF(string pHTML) {
byte[] bPDF = null;
MemoryStream ms = new MemoryStream();
TextReader txtReader = new StringReader(pHTML);
// 1: create object of a itextsharp document class
Document doc = new Document(PageSize.A4, 25, 25, 25, 25);
// 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file
PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);
// 3: we create a worker parse the document
HTMLWorker htmlWorker = new HTMLWorker(doc);
// 4: we open document and start the worker on the document
doc.Open();
htmlWorker.StartDocument();
// 5: parse the html into the document
htmlWorker.Parse(txtReader);
// 6: close the document and the worker
htmlWorker.EndDocument();
htmlWorker.Close();
doc.Close();
bPDF = ms.ToArray();
return bPDF;
}
Use ITextSharp its a .NET PDF library which allows you to generate PDF (Portable Document Format).
So first of all need to add reference of iTextSharp in your project.
You can get iTextSharp reference using package manager, you just need to execute following command to download and add reference.
PM> Install-Package iTextSharp
Now you need to create a method which will give you byte array of PDF content, so our code will be

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...

C# - Extract one *.jar file into another one [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to do my own Minecraft Launcher for Moded Minecraft. And I have a issue: I need to extract content of one *.jar file to another. I tried a lot of things and I am totally desperate.
Basicly, I need to do this in code.
As Andrew briefly mentioned, there are some good .NET libraries for manipulating zip files. I've found DotNetZip to be very useful, and there are lots of helpful worked examples here.
In answer to your question, if you just want to copy the contents of one *.jar file to another, keeping original content in the target file, please try the following. I'm using the .NET zip mentioned above (which also has a NuGet package!):
using (ZipFile sourceZipFile = ZipFile.Read("zip1.jar"))
using (ZipFile targetZipFile = ZipFile.Read("zip2.jar"))
{
foreach (var zipItem in sourceZipFile)
{
if (!targetZipFile.ContainsEntry(zipItem.FileName))
{
using (Stream stream = new MemoryStream())
{
// Write the contents of this zip item to a stream
zipItem.Extract(stream);
stream.Position = 0;
// Now use the contents of this stream to write to the target file
targetZipFile.AddEntry(zipItem.FileName, stream);
// Save the target file. We need to do this each time before we close
// the stream
targetZipFile.Save();
}
}
}
}
Hope this helps!

Cannot display Tamil correctly in generated PDF [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 months ago.
Improve this question
Currently we are using Aspose.NET library to generate excel and export to PDF.
The pdf consists of multiple language such as English, Chinese and Tamil.
For English and Chinese it work fine but for Tamil is having spelling issue.
For example the first and second letter for "போல்" will flipped.
We have tried "Latha" font and "Arial Unicode MS" font, the text is showing but the letter is flipped.
We have tried "InaiMathi" font as well but the text is not showing.
I have also try to use different pdf generator such as ITextSharp as suggested in this page: How to Create PDF file with Tamil Font by using itextsharp in C#?
But the text still flipped. From the page, they said that ITextSharp does not fully support indic language.
Are there any pdf generator that support indic langauge?
Hi Have you looked at Google wkhtmltopdf.exe. I have used this without any issue
wkhtmltopdf.exe System.Security.SecurityException on cloud web server. How can i override server security policy
Only problem with this is that you need full trust level. If it is for intranet then this is the good option. if you are looking for I have tried this for arabic as well so tamil is not an issue.
Regards
Please refer related answer here. Try Quest PDF which supports Tamil text as well.
Create a console application and install the Quest PDF library and use the sample (in .NET 6) to see POC.
dotnet add package QuestPDF
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.PageColor(Colors.White);
page.DefaultTextStyle(x => x.FontSize(20));
page.DefaultTextStyle(x => x.FontFamily("Vijaya"));
page.Header()
.Text("தமிழ் PDF!")
.SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
page.Content()
.PaddingVertical(1, Unit.Centimetre)
.Column(x =>
{
x.Spacing(20);
x.Item().Text("தமிழ் (Tamil language) தமிழர்களினதும் தமிழ் பேசும் பலரின் தாய்மொழி ஆகும். தமிழ், உலகின் உள்ள முதன்மையான மொழிகளில் ஒன்றும் செம்மொழியும் ஆகும்.");
});
page.Footer()
.AlignCenter()
.Text(x =>
{
x.Span("பக்கம் ");
x.CurrentPageNumber();
});
});
})
.GeneratePdf("தமிழ்.pdf");

Convert Group 3 compressed TIFF to png or pdf in .net [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I search a way to convert a Group 3 compressed TIFF to png or for best in pdf with c#.net.
Try LibTiff.Net library for this.
The library comes with tiff2pdf utility (you would need to build it yourselves) that probably does exactly what you need. You may even incorporate the code of the utility in your application.
The library and utility are free and open-source. License (New BSD License) allows any modifications. You can use the library and utility in commercial applications.
Disclaimer: I am one of the maintainers of the library.
TIFF to PNG:
System.Drawing.Image will allow you to open a Group3 TIFF and save it as PNG simply by loading the TIFF as a normal image (e.g. Image.FromFile, Image.FromStream, etc.) and then saving it using the Image.Save method with the ImageFormat.Png argument. As TIFFs vary widely, on occasion I have encountered an obscure TIFF that System.Drawing won't open, but that is unusual. If it happens, you'll need to seek out a third party library from opensource (e.g. iText has a sophisticated image library) or there are commercial options such as Lead Tools or Atalasoft.
TIFF to PDF:
iTextSharp is a great library for doing this. I even found some articles on this specific topic with a google search. This one seems to be a good one to start with for your needs.
(disclaimer - I work for Atalasoft)
If you use dotImage for this, both conversions are trivial.
for tiff to pdf:
using (outputStream = new FileStream(pathToPdf, FileMode.Create)) {
PdfEncoder encoder = new PdfEncoder();
encoder.Save(outputStream, new FileSystemImageSource(pathToTiff, true), null); // true = do all pages
}
for tiff to png:
FileSystemImageSource source = new FileSystemImageSource(pathToTiff, true);
int page = 0;
while (source.HasMoreImages()) {
AtalaImage image = source[page];
using (FileStream stm = new FileStream("output_page_" + page + ".png", FileMode.Create)) {
PngEncoder encoder = new PngEncoder();
encoder.Save(stm, image, null);
}
source.Release(image);
}
Use ghostscript, i used to extract images from a PDF and create thumbnails, the lib also convert from images to PDF and it's open source.
A guy create a wrapper for the ghostscript API:
http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/

Categories