I am using Silverlight BING Map Api to show the location (by providing the address) on my website..
And I want to show this Map location in the PDF file programmatically, I tried alot using 'wkhtmltopdf' but all in-vain, It shows empty space instead of BING MAP...
Please guide me in this case, I am open in using any other open source PDF generation tool.
Thanks
Xtremist
If you want insert image to PDF use iText library. It is very easy to start using it:
string pdfFilename = #"c:\temp\test.pdf";
string imageFilename = #"C:\map.jpg";
// Create PDF writer, document and image to put
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageFilename);
Document doc = new Document();
PdfWriter pdfW = PdfWriter.GetInstance(doc, new FileStream(pdfFilename, FileMode.Create));
// Open created PDF and insert image to it
doc.Open();
doc.Add(image);
doc.Close();
Or do you want to save Bing map as image?
I don't think that there's an easy way to do it through the Silverlight SDK. Instead, I think Microsoft prefers that you use the Bing Maps SOAP Services. Specifically you'll want to look at the Imagery Service where you can send a ImageryMetadataRequest with location/zoom info set in the ImageryMetadataOptions. Some basic sample code can be found here.
Once you get the images you can pretty easily add them to a PDF.
Related
My windows form contains a textbox in which we need to enter html tags,One button to generate PDF.
And we need to load the textbox content into XML Reader and process each element of XML recursively then we need to generate a PDF file.
The PDF file must contain the data i.e;
for example if I entered tag in the text box in the pdf file it must display a table.
I am very new to Windows forms and XML also can any one help me to complete this task
You would need to use a library to create PDF files. iTextSharp is a common library which can help. Take a look at this library and samples, you would be able to create PDF files easily from your application
https://sourceforge.net/projects/itextsharp/
iText is a PDF library that allows you to CREATE, ADAPT, INSPECT and MAINTAIN documents in the Portable Document Format (PDF):
iTextSharp is the .NET port.
Got Answer with this simple code
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();
but my problem is the path I want to select the path dynamically.Can any one help me how to set the path dynamically in the above code.
PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf", FileMode.Create));
Changed this code by using a savefile dialog box
SaveFileDialog svg = new SaveFileDialog();
svg.ShowDialog();
PdfWriter.GetInstance(document, new FileStream(svg.FileName + ".pdf", FileMode.Create));
We are currently using SoftArtisans to generate Excel and Word files.
We need to extend this to also create PDF files.
Does OfficeWriter currently support this?
If not, any plans to add this feature? Or any opensource library that can be used to convert Excel/Word files to PDF format?
PdfSharp and Migradoc as far as I know are the best and the most popular. Migradoc is the higher-level cover for PdfSharp.
Note: I work for SoftArtisans, makers of OfficeWriter.
OfficeWriter does not currently support converting Excel/Word files to PDF. We generally recommend a 3rd party component to convert to PDF. However, many of these components require having Office installed on the server, which Microsoft does not advise. Therefore, it is important that you choose a converter that either does not require having Office on the server, or manages it carefully
Here are a few solutions for converting Word to PDF that we’ve recommended to our users in the past:
• Word Services for Sharepoint – If you are using SharePoint Server 2010, then you can use Word Services to perform the format conversion. More information about this solution can be found at: http://msdn.microsoft.com/en-us/library/office/ff181518.aspx
• Rainbow PDF - rainbowpdf.com
• EasyPDF - pdfonline.com/easypdf/
For more information, please see our blog post: http://blog.softartisans.com/2011/08/05/kb-tools-to-convert-word-documents-to-pdf/
PfgSharp is quite popular. Here is an example from CodeProject on how to create a simple PDF to get some feeling on how to use it:
class Program
{
static void Main(string[] args)
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
// Save the document...
const string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
}
I'm writing a piece of software for visualization of measurement data. For this I use System.Windows.Forms.DataVisualization.Charting.Chart and I do know that I can get the shown image by chartObj.SaveImage to store it to a file.
My software shall have a PDF export in which the picture should be included. For this, I'm using iTextSharp. Again, I do know how to put a picture which I have stored in a file into the PDF by iTextSharp.text.Image.GetInstance.
So by now I am able to take the picture of the chart, put it to a file (e.g. a .jpg file) and load this file again to put it in my PDF. Now I'm looking for a nice solution to get the picture into the PDF without storing it into a file, maybe through a Stream or something like that. I've tried quite some time, but until now I didn't succeed. I've thought of something like
Stream imageStream = image of chartObj;
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageStream);
As far as I understand, I fail in putting the picture from the chartObj into a Stream instead of a file. If I had this, I guess I could load the Stream via iTextSharp.text.Image.GetInstance.
Has anyone some help you could offer? Guess it's not that difficult, but I'm new to C# and also to iText, so I'm just a bit stucked here.
Thanks in advance for every thought you have about this!
Anna
SaveImage to a MemoryStream:
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
From:
Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC
hi
how do we rotate PDF using itext library.
Thanks
If you writing to a new PDF document, the following line will create a new A4 page rotated (into landscape)
Document doc = new Document(PageSize.A4.Rotate());
This is a very simple example:
Document pdf = new Document(PageSize.A4);
PdfWriter.GetInstance(pdf, new FileStream("file.pdf", System.IO.FileMode.Create));
pdf.Open();
pdf.Add(new Paragraph("This is a pdf document!"));
pdf.Close();
Edit: My mistake, I read "how to create pdf ...". That is what the example above does. I am sorry.
I am using iTextSharp to create a PDF document in C#. I would like to attach another file to the PDF. I'm having just loads of trouble trying to do so. The examples here show some annotations, which apparently attachments are.
This is what I've tried:
writer.AddAnnotation(its.pdf.PdfAnnotation.CreateFileAttachment(writer, new iTextSharp.text.Rectangle(100,100,100,100), "File Attachment", its.pdf.PdfFileSpecification.FileExtern(writer, "C:\\test.xml")));
Well, what happens is it does add an annotation on the PDF (appears as a little comment voice balloon), which i don't want. test.xml is shown in the attachments pane in Adobe Reader, but it can't be read or saved, and its file size is unknown so it's likely that it's never being properly attached.
Any suggestions?
Well, I got some code working to attach it:
its.Document PDFD = new its.Document(its.PageSize.LETTER);
its.pdf.PdfWriter writer;
writer = its.pdf.PdfWriter.GetInstance(PDFD, new FileStream(targetpath, FileMode.Create));
its.pdf.PdfFileSpecification pfs = its.pdf.PdfFileSpecification.FileEmbedded(writer, "C:\\test.xml", "New.xml", null);
writer.AddFileAttachment(pfs);
where "its"="iTextSharp.text"
Now to read the attachment!