I was wondering if it is possible to integrate a Quicktime movie into a PDF with iTextSharp or other PDF tools. I have been able integrate images without a problem. Thanks.
Is it this you are looking for?
Edit
In short
First you have to create a movie annotation by using the CreateScreen method of the PdfAnnotation class
You can create an movie annotation using this media types .aiff, .au, .avi, .mid, .mov, .mp4, .mp4, .mpeg, .smil, .swf
Then you need to add the movie annotation to the PDF by using the AddAnnotation method of the PdfWriter
/create a document object
var doc = new Document();
//output file path
String outfile = "d:/pdfdoc.pdf";
//get PdfWriter object
PdfWriter writer=PdfWriter.GetInstance(doc, new FileStream(outfile, FileMode.Create));
//open the document for writing
doc.Open();
//Create an instance of PdfFileSpecification
PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(writer, "d:/bailey.mpg", "bailey.mpg", null);
//create and add a movie annotation to PDF document
writer.AddAnnotation(PdfAnnotation.CreateScreen(writer, new Rectangle(200f, 700f, 400f, 800f), "Bailey", fs,"video/mpeg", true));
//close the document
doc.Close();
//view the result pdf file
System.Diagnostics.Process.Start(outfile);
Note
I'm not the owner of this content, it's only a brief summary of the tutorial from the website worldbestlearningcenter.com (link above)
Related
I use the itextsharp library to remove unwanted bookmarks from PDF files.
I developed the following code:
private static void RemovePDFbookmarks(string filein, string fileout)
{
PdfReader pdfReader = new PdfReader(filein);
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileStream(fileout, FileMode.Create));
document.Open();
copy.AddDocument(pdfReader);
document.Close();
pdfReader.Close();
copy.Close();
}
This method creates a copy of the original file. During the following process, I need to delete the original file and rename the new file back to the original file's name.
How can I remove the bookmarks in the original PDF without the copy-delete-rename detour?
In vb.net I need to print the contents showing in a browser control to printer.
I have used Gecko web-browser control in winform application and there is no direct way to print the page's contents.
Either way to print direct using InnerHtml or converting that html to pdf and then printing the pdf document.
currently I am using a third party library `ItextSharpe' but it gives errors.
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;
}
Byte[] bytes;
bytes = GetPDF(browse.Document.Body.InnerHtml);
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.pdf");
System.IO.File.WriteAllBytes(testFile, bytes);
but throws errors while parsing.
Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'.
I have seen different examples over web but this is totally different, the examples or duplicate answer is about to export panels or grids but this is dynamic HTML and i need to convert it to PDF or print directly the client area.
I want to convert HTML into PDF in windows form. I have come across many fabulous articles online such as these:
http://www.aspsnippets.com/Categories/iTextSharp.aspx
http://www.aspsnippets.com/Articles/Export-HTML-DIV-contents-to-PDF-using-iTextSharp-in-ASPNet.aspx
http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF-with-Custom-Columns-Widths-using-iTextSharp.aspx
But they do not quite address my problem.
Is it possible that I can just pass a string of HTML and convert it into PDF in Winform?
For example :
string html = "<table><tr><td>Arbaaz</td><tr></table>"
Can I just pass this string to some iText method to create PDF?
Got the answer I was looking for here ..
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf", FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.HTMLWorker hw =
new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(htmlText));
document.Close();
https://stackoverflow.com/a/18378661/2064292
How can I generate a pdf in winRT apps? I'm using iTextSharp to generate pdfs in windows store apps, but winRT does not have filestream, filemode or filedirectory. help
Here is my code:
iTextSharp.text.pdf.PdfWriter writer =
iTextSharp.text.pdf.PdfWriter.GetInstance(
doc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() +
"\\ScienceReport.pdf", System.IO.FileMode.Create
)
);
I can generate a PDF file in winrt
string path = #"ExportPDF.pdf";
var storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
// Create empty PDF file.
var file = await storageFolder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
if (file != null)
{
await FileIO.WriteTextAsync(file, string.Empty);
}
// Open to PDF file for read/write.
StorageFile sampleFile = await storageFolder.GetFileAsync(path);
var stream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
// Create an instance of the document class which represents the PDF document itself.
Document document = new Document(PageSize.A4, 25, 25, 30, 30);
// Create an instance to the PDF file by creating an instance of the PDF
// Writer class using the document and the filestrem in the constructor.
PdfWriter writer = PdfWriter.GetInstance(document, stream.AsStream());
// Add meta information to the document
document.AddAuthor("Jigs");
document.AddCreator("Sample application");
document.AddKeywords("PDF App");
document.AddSubject("Document subject - Describing the steps creating a PDF document");
document.AddTitle("The document title - PDF creation");
// Open the document to enable you to write to the document
document.Open();
// Add a simple and wellknown phrase to the document in a flow layout manner
document.Add(new Paragraph("Hello!"));
// Close the document
document.Close();
// Close the writer instance
writer.Close();
I'm trying to convert HTML to PDF with iTextSharp.
Here's my code:
Document doc = new Document(PageSize.A4);
StringReader reader = new StringReader(responseHtml);
FileStream pdfStream = new FileStream("C:\\temp\\foo.pdf", FileMode.OpenOrCreate);
PdfWriter writer = PdfWriter.GetInstance(doc, pdfStream);
doc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, reader);
doc.Close();
The issue is that the PDF file stops after 2 pages.
The rest of the content just doesn't make it to the PDF file.
When I change the PageSize to A1, I get the whole content, 'cause it fits on two A1 pages.
How do I get it to create more than two pages?