http://homepage2.nifty.com/nonnon/SoftSample/CS.NET/SamplePdfSplit.html
http://jp.techerald.com/page/imagen-itextsharp-mantener-las-dimensiones-en-pixeles.html
http://stackoverflow.com/questions/4932187/itextsharp-scaling-image-to-be-full-page
http://yonaizumi.dip.jp/weblog/cappe/2010/11/ctiffpdf.html
http://sourceforge.net/projects/itextsharp/
参照の設定は、dllをどっかに保存しといて、参照の追加→参照→dllを指定
コンパイルすると、なんか自動的に/Debug、/Release に配置される???
なんか、AbsolutePositionって左下が(0,0)なのかな。直さなきゃ
コード(適当)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
//iTextSharp
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace jpg2pdf
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//jpgファイルを開く
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "default.jpg";
ofd.InitialDirectory = "";
ofd.Filter = "jpgファイル(*.jpg)|*.jpg|すべてのファイル(*.*)|*.*";
ofd.FilterIndex = 1;
ofd.Title = "開くファイルを選択してください";
ofd.RestoreDirectory = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
textBox1.Text = ofd.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog();
sfd.FileName = "無題.pdf";
sfd.InitialDirectory = "";
sfd.Filter = "pdfファイル(*.pdf)|*.pdf|すべてのファイル(*.*)|*.*";
sfd.FilterIndex = 1;
sfd.Title = "保存先を指定してください";
sfd.RestoreDirectory = true;
sfd.OverwritePrompt = true;
sfd.CheckPathExists = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
textBox2.Text = sfd.FileName;
}
}
private void button3_Click(object sender, EventArgs e)
{
var doc = new Document();
//pdf保存先
PdfWriter.GetInstance(doc, new FileStream(textBox2.Text, FileMode.Create));
//pdfを開く
doc.Open();
//画像データを取得
var image = iTextSharp.text.Image.GetInstance(textBox1.Text);
doc.SetPageSize(PageSize.A4);
//サイズのフィット
image.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
//画像の配置箇所設定
image.SetAbsolutePosition(0f, 0f);
//用紙サイズの設定
//doc.SetPageSize(new iTextSharp.text.Rectangle(image.PlainWidth, image.PlainHeight));
//書き込み
doc.Add(image);
//pdfを閉じる
doc.Close();
//完了のダイアログ(無いと終わったかわからない)
MessageBox.Show("変換が完了しました");
}
}
}