ExcelTechnology

How to Convert Image to PDF and the Program with C#

In PDF, we can insert image to make the contents be colorful and attractive. And it is possible that one image is one PDF document, especially in PDF form. Therefore, we may need to convert image to PDF sometimes.
Except Adobe Acrobat, which is the professional tool to manipulate PDF, there are lots of converters which specialize in converting image to PDF online. The tools are easy to use and the developers will show the guide about how to use the converters. Choose the image you want to convert and then follow the guide. You can get the PDF documents soon.
For programmers, they may pay much attention on how to develop a good tool to convert image to PDF. It is wonderful that some programmers share their methods on forum, blog or article websites. Also, readers can give their suggestions, which can make the program be better.
After reading many articles in this aspect and suggestions by others, I want to share my own program.
The following code shows how to convert image to PDF by using C#.

In this method, I use one third party add-in, Spire.PDF.

PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = doc.Pages.Add();
PdfImage image = PdfImage.FromFile("test.png");

float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;

page.Canvas.DrawImage(image, 0, 0, fitWidth, fitHeight);
doc.SaveToFile("test.pdf");

In addition, I find that the developers of Spire.PDF release a small tool, Spire PDF Converter, which can be used to convert various format documents to PDF. During converting, we can encrypt and add watermark during converting. It is great that the beta version is free. If you want to convert documents to PDF, you can try to use it.

19.05.2011. u 05:58 | 0 Komentara | Print | # | ^

Header and Footer in Word and How to Set with VB.NET

There may be header or footer in a Word document. Header and footer are not necessary but they can show the additional information for the document. Usually, the contents of header and footer include time, date, page or some symbols.
It is common that header and footer are about pages. If the document has over ten pages, the owner will add header or footer to show the pages for that it is convenient for readers to read contents of one page. Sometimes, the footer may be are symbols, for example, company name or author signature. These symbols show the owner of the document.
Although it is not essential to add header and footer, they are very useful in some documents. Open a Word document, click View menu, and we can find header and footer. Select it and the header and footer box appears. Write text or using the default format to set the header and footer. If we just want to set Word footer, we can leave the header box blank and enter text or use default format in footer box.
Besides using Microsoft Word to set header and footer directly, programmers may use C# or VB.NET to set Word header and footer. Now, I want to show a method to set word header and footer with VB.NET.

Code:

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
'Create word document
Dim document_Renamed As New Document()
InsertHeaderFooter(document_Renamed)
'Save doc file.
document_Renamed.SaveToFile("Sample.doc",FileFormat.Doc)
'Launching the MS Word file.
WordDocViewer("Sample.doc")
End Sub
Private Sub InsertHeaderFooter(ByVal document_Renamed As Document)
Dim section_Renamed As Section = document_Renamed.AddSection()
Dim paragraph_Renamed As Paragraph = section_Renamed.AddParagraph()
paragraph_Renamed.AppendText("The sample demonstrates how to insert a header and footer into a document.")
paragraph_Renamed.ApplyStyle(BuiltinStyle.Heading2)
section_Renamed.PageSetup.DifferentFirstPageHeaderFooter = True
paragraph_Renamed = New Paragraph(document_Renamed)
paragraph_Renamed.AppendText("Spire.Doc for .NET").CharacterFormat.FontSize = 15
paragraph_Renamed.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center
section_Renamed.HeadersFooters.FirstPageHeader.Paragraphs.Add(paragraph_Renamed)
paragraph_Renamed = New Paragraph(document_Renamed)
paragraph_Renamed.AppendText("e-iceblue company Ltd. 2002-2010 All rights reserverd").CharacterFormat.FontSize = 15
paragraph_Renamed.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center
section_Renamed.HeadersFooters.FirstPageFooter.Paragraphs.Add(paragraph_Renamed)
End Sub
Private Sub WordDocViewer(ByVal fileName As String)
Try
Process.Start(fileName)
Catch
End Try
End Sub

05.05.2011. u 05:55 | 0 Komentara | Print | # | ^

<< Prethodni mjesec | Sljedeći mjesec >>

Creative Commons License
Ovaj blog je ustupljen pod Creative Commons licencom Imenovanje-Dijeli pod istim uvjetima.

< svibanj, 2011 >
P U S Č P S N
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Kolovoz 2011 (2)
Srpanj 2011 (2)
Lipanj 2011 (2)
Svibanj 2011 (2)
Travanj 2011 (3)
Ožujak 2011 (2)
Veljača 2011 (2)
Siječanj 2011 (5)
Prosinac 2010 (5)

Dnevnik.hr
Gol.hr
Zadovoljna.hr
Novaplus.hr
NovaTV.hr
DomaTV.hr
Mojamini.tv

Opis bloga

something about Excel Technology in VB.Net and C#

Linkovi

Dnevnik.hr
Video news portal Nove TV

Blog.hr
Blog servis

Igre.hr
Najbolje igre i igrice

Forum.hr
Monitor.hr