Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
이 문서에서는 C#을 사용하여 다양한 이미지 형식을 PDF로 변환하는 방법을 설명합니다. 다음 주제를 다룹니다.
다음 코드 스니펫은 Aspose.PDF.Drawing 라이브러리와 함께 작동합니다.
Aspose.PDF for .NET는 다양한 형식의 이미지를 PDF 파일로 변환할 수 있게 해줍니다. 우리의 라이브러리는 BMP, CGM, DICOM, EMF, JPG, PNG, SVG, CDR, HEIC 및 TIFF 형식과 같은 가장 인기 있는 이미지 형식을 변환하는 코드 스니펫을 보여줍니다.
Aspose.PDF for .NET 라이브러리를 사용하여 BMP 파일을 PDF 문서로 변환합니다.
BMP 이미지는 확장자를 가진 파일입니다. BMP는 비트맵 디지털 이미지를 저장하는 데 사용되는 비트맵 이미지 파일을 나타냅니다. 이러한 이미지는 그래픽 어댑터와 독립적이며 장치 독립 비트맵(DIB) 파일 형식이라고도 합니다. Aspose.PDF for .NET API를 사용하여 BMP를 PDF 파일로 변환할 수 있습니다. 따라서 BMP 이미지를 변환하기 위해 다음 단계를 따를 수 있습니다:
따라서 다음 코드 스니펫은 이러한 단계를 따르며 C#을 사용하여 BMP를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertBMPtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load BMP file
image.File = dataDir + "BMPtoPDF.bmp";
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "BMPtoPDF_out.pdf");
}
}
CGM은 CAD(컴퓨터 지원 설계) 및 프레젠테이션 그래픽 애플리케이션에서 일반적으로 사용되는 컴퓨터 그래픽 메타파일 형식의 파일 확장자입니다. CGM은 세 가지 다른 인코딩 방법을 지원하는 벡터 그래픽 형식입니다: 이진(프로그램 읽기 속도에 가장 적합), 문자 기반(가장 작은 파일 크기를 생성하고 더 빠른 데이터 전송을 허용) 또는 명확한 텍스트 인코딩(사용자가 텍스트 편집기로 파일을 읽고 수정할 수 있도록 함).
CGM 파일을 PDF 형식으로 변환하는 다음 코드 스니펫을 확인하십시오.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertCGMtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
var option = new Aspose.Pdf.CgmLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "CGMtoPDF.cgm", option))
{
// Save PDF document
document.Save(dataDir + "CGMtoPDF_out.pdf");
}
}
DICOM 형식은 디지털 의료 이미지 및 검사된 환자의 문서 생성, 저장, 전송 및 시각화에 대한 의료 산업 표준입니다.
Aspose.PDF for .NET은 DICOM 및 SVG 이미지를 변환할 수 있지만, 기술적인 이유로 PDF에 추가할 이미지를 추가하려면 추가할 파일의 유형을 지정해야 합니다:
다음 코드 스니펫은 Aspose.PDF를 사용하여 DICOM 파일을 PDF 형식으로 변환하는 방법을 보여줍니다. DICOM 이미지를 로드하고, PDF 파일의 페이지에 이미지를 배치하고, 출력을 PDF로 저장해야 합니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertDICOMtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image
{
FileType = ImageFileType.Dicom,
File = dataDir + "DICOMtoPDF.dcm"
};
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "DICOMtoPDF_out.pdf");
}
}
EMF는 그래픽 이미지를 장치 독립적으로 저장합니다. EMF의 메타파일은 저장된 이미지를 어떤 출력 장치에서든 렌더링할 수 있는 가변 길이 레코드로 구성되어 있습니다. 또한, 아래 단계를 사용하여 EMF를 PDF 이미지로 변환할 수 있습니다:
또한, 다음 코드 스니펫은 C#을 사용하여 .NET 코드 스니펫에서 EMF를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertEMFtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load EMF file
image.File = dataDir + "EMFtoPDF.emf";
// Specify page dimension properties
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Width = image.BitmapSize.Width;
page.PageInfo.Height = image.BitmapSize.Height;
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "EMFtoPDF_out.pdf");
}
}
Aspose.PDF for .NET 라이브러리를 사용하여 GIF 파일을 PDF 문서로 변환합니다.
GIF는 품질 손실 없이 최대 256색의 형식으로 압축된 데이터를 저장할 수 있습니다. 하드웨어 독립적인 GIF 형식은 1987년( GIF87a) CompuServe에 의해 비트맵 이미지를 네트워크를 통해 전송하기 위해 개발되었습니다. Aspose.PDF for .NET API를 사용하여 GIF를 PDF 파일로 변환할 수 있습니다. 따라서 GIF 이미지를 변환하기 위해 다음 단계를 따를 수 있습니다:
따라서 다음 코드 스니펫은 이러한 단계를 따르며 C#을 사용하여 BMP를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertGIFtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load sample GIF image file
image.File = dataDir + "GIFtoPDF.gif";
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "GIFtoPDF_out.pdf");
}
}
JPG를 PDF로 변환하는 방법에 대해 고민할 필요가 없습니다. Aspose.PDF for .NET 라이브러리가 최고의 해결책을 제공합니다.
다음 단계를 따르면 JPG 이미지를 PDF로 쉽게 변환할 수 있습니다:
아래 코드 스니펫은 C#을 사용하여 JPG 이미지를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertJPGtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load input JPG file
image.File = dataDir + "JPGtoPDF.jpg";
// Add image on a page
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "JPGtoPDF_out.pdf");
}
}
그런 다음 페이지의 높이와 너비가 동일한 이미지로 PDF로 변환하는 방법을 볼 수 있습니다. 이미지 치수를 가져오고 이에 따라 PDF 문서의 페이지 치수를 설정하는 아래 단계를 따릅니다:
다음 코드 스니펫은 C#을 사용하여 페이지 높이와 너비가 동일한 이미지로 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertJPGtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load JPEG file
image.File = dataDir + "JPGtoPDF.jpg";
// Read Height of input image
page.PageInfo.Height = image.BitmapSize.Height;
// Read Width of input image
page.PageInfo.Width = image.BitmapSize.Width;
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Margin.Left = 0;
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "JPGtoPDF_out.pdf");
}
}
Aspose.PDF for .NET는 PNG 이미지를 PDF 형식으로 변환하는 기능을 지원합니다. 다음 코드 스니펫을 확인하여 작업을 수행하십시오.
PNG는 무손실 압축을 사용하는 래스터 이미지 파일 형식의 일종으로, 사용자들 사이에서 인기가 높습니다.
아래 단계를 사용하여 PNG를 PDF 이미지로 변환할 수 있습니다:
또한, 아래 코드 스니펫은 .NET 애플리케이션에서 C#을 사용하여 PNG를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPNGtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load PNG file
image.File = dataDir + "PNGtoPDF.png";
// Read Height of input image
page.PageInfo.Height = image.BitmapSize.Height;
// Read Width of input image
page.PageInfo.Width = image.BitmapSize.Width;
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Margin.Left = 0;
page.Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "PNGtoPDF_out.pdf");
}
}
Aspose.PDF for .NET는 SVG 이미지를 PDF 형식으로 변환하는 방법과 소스 SVG 파일의 치수를 얻는 방법을 설명합니다.
확장 가능한 벡터 그래픽(SVG)은 정적 및 동적(인터랙티브 또는 애니메이션) 2차원 벡터 그래픽을 위한 XML 기반 파일 형식의 사양 모음입니다. SVG 사양은 1999년부터 W3C(월드 와이드 웹 컨소시엄)에 의해 개발되고 있는 개방형 표준입니다.
SVG 이미지는 XML 텍스트 파일로 정의되며, 이는 검색, 색인화, 스크립팅 및 필요에 따라 압축할 수 있음을 의미합니다. XML 파일로서 SVG 이미지는 모든 텍스트 편집기로 생성 및 편집할 수 있지만, Inkscape와 같은 드로잉 프로그램을 사용하여 생성하는 것이 더 편리합니다.
온라인에서 SVG 형식을 PDF로 변환해 보세요
Aspose.PDF for .NET는 “SVG to PDF”라는 온라인 무료 애플리케이션을 제공하여 기능과 품질을 확인할 수 있습니다.
SVG 파일을 PDF로 변환하려면 SvgLoadOptions라는 클래스를 사용하여 LoadOptions
객체를 초기화합니다. 이후 이 객체는 Document 객체 초기화 시 인수로 전달되어 PDF 렌더링 엔진이 소스 문서의 입력 형식을 결정하는 데 도움을 줍니다.
SvgLoadOptions
클래스의 인스턴스를 생성합니다.Document
클래스의 인스턴스를 생성합니다.다음 코드 스니펫은 Aspose.PDF for .NET을 사용하여 SVG 파일을 PDF 형식으로 변환하는 과정을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertSVGtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
var option = new Aspose.Pdf.SvgLoadOptions();
// Open SVG file
using (var document = new Aspose.Pdf.Document(dataDir + "SVGtoPDF.svg", option))
{
// Save PDF document
document.Save(dataDir + "SVGtoPDF_out.pdf");
}
}
소스 SVG 파일의 치수를 가져오는 것도 가능합니다. 이 정보는 SVG가 출력 PDF의 전체 페이지를 차지하도록 하려는 경우 유용할 수 있습니다. SvgLoadOption 클래스의 AdjustPageSize 속성이 이 요구 사항을 충족합니다. 이 속성의 기본값은 false입니다. 값이 true로 설정되면 출력 PDF는 소스 SVG와 동일한 크기(치수)를 갖게 됩니다.
다음 코드 스니펫은 소스 SVG 파일의 치수를 가져오고 PDF 파일을 생성하는 과정을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertSVGtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
var loadopt = new Aspose.Pdf.SvgLoadOptions();
loadopt.AdjustPageSize = true;
// Open SVG file
using (var document = new Aspose.Pdf.Document(dataDir + "SVGtoPDF.svg", loadopt))
{
document.Pages[1].PageInfo.Margin.Top = 0;
document.Pages[1].PageInfo.Margin.Left = 0;
document.Pages[1].PageInfo.Margin.Bottom = 0;
document.Pages[1].PageInfo.Margin.Right = 0;
// Save PDF document
document.Save(dataDir + "SVGtoPDF_out.pdf");
}
}
SVG 태그 |
샘플 사용 |
---|---|
circle |
|
defs |
<defs>
|
tref |
<defs> |
use |
<defs> |
ellipse |
<ellipse cx="2.5" cy="1.5" rx="2" ry="1" fill="red" /> |
g |
<g fill="none" stroke="dimgray" stroke-width="1.5" > |
image |
<image id="ShadedRelief" x="24" y="4" width="64" height="82" xlink:href="relief.jpg" /> |
line |
<line style="stroke:#eea;stroke-width:8" x1="10" y1="30" x2="260" y2="100"/> |
path |
<path style="fill:#daa;fill-rule:evenodd;stroke:red" d="M 230,150 C 290,30 10,255 110,140 z "/> |
style |
<path style="fill:#daa;fill-rule:evenodd;stroke:red" d="M 230,150 C 290,30 10,255 110,140 z "/> |
polygon |
<polygon style="stroke:#24a;stroke-width:1.5;fill:#eefefe" points="10,10 180,10 10,250 10,10" /> |
polyline |
<polyline fill="none" stroke="dimgray" stroke-width="1" points="-3,-6 3,-6 3,1 5,1 0,7 -5,1 -3,1 -3,-5"/> |
rect |
<rect x="0" y="0" width="400" height="600" stroke="none" fill="aliceblue" /> |
svg |
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="10cm" height="5cm" > |
text |
<text font-family="sans-serif" fill="dimgray" font-size="22px" font-weight="bold" x="58" y="30" pointer-events="none">지도 제목</text> |
font |
<text x="10" y="100" font-size="15" fill="red" > |
tspan |
<tspan dy="25" x="25">여섯 잉크 색상 입력 값. 여기서 그것은 </tspan> |
Aspose.PDF 파일 형식은 단일 프레임 또는 다중 프레임 TIFF 이미지를 지원합니다. 즉, .NET 애플리케이션에서 TIFF 이미지를 PDF로 변환할 수 있습니다.
TIFF 또는 TIF, 태그 이미지 파일 형식은 이 파일 형식 표준을 준수하는 다양한 장치에서 사용하기 위한 래스터 이미지를 나타냅니다. TIFF 이미지는 서로 다른 이미지를 포함하는 여러 프레임을 포함할 수 있습니다. Aspose.PDF 파일 형식도 지원되며, 단일 프레임 또는 다중 프레임 TIFF 이미지 모두 지원됩니다.
다른 래스터 파일 형식 그래픽과 동일한 방식으로 TIFF를 PDF로 변환할 수 있습니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertTIFFtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
document.Pages.Add();
var image = new Aspose.Pdf.Image();
// Load sample Tiff image file
image.File = dataDir + "TIFFtoPDF.tiff";
document.Pages[1].Paragraphs.Add(image);
// Save PDF document
document.Save(dataDir + "TIFFtoPDF_out.pdf");
}
}
다중 페이지 TIFF 이미지를 다중 페이지 PDF 문서로 변환하고 일부 매개변수를 제어해야 하는 경우, 예를 들어 너비나 종횡비를 제어하려면 다음 단계를 따르십시오:
다음 코드 스니펫은 C#을 사용하여 다중 페이지 또는 다중 프레임 TIFF 이미지를 PDF로 변환하는 방법을 보여줍니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertTIFFtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
using (var bitmap = new System.Drawing.Bitmap(File.OpenRead(dataDir + "TIFFtoPDF.tif")))
{
// Convert multi page or multi frame TIFF to PDF
var dimension = new FrameDimension(bitmap.FrameDimensionsList[0]);
var frameCount = bitmap.GetFrameCount(dimension);
// Iterate through each frame
for (int frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++)
{
var page = document.Pages.Add();
bitmap.SelectActiveFrame(dimension, frameIdx);
using (var currentImage = new MemoryStream())
{
bitmap.Save(currentImage, ImageFormat.Tiff);
var imageht = new Aspose.Pdf.Image
{
ImageStream = currentImage,
//Apply some other options
//ImageScale = 0.5
};
page.Paragraphs.Add(imageht);
}
}
}
// Save PDF document
document.Save(dataDir + "TIFFtoPDF_out.pdf");
}
}
CDR은 Corel Corporation에서 개발한 파일 형식으로, 주로 벡터 그래픽 이미지 및 도면에 사용됩니다. CDR 파일 형식은 대부분의 이미지 편집 프로그램에서 인식됩니다. CDR 형식은 Corel Draw 애플리케이션의 기본 형식입니다.
CDR 파일을 PDF 형식으로 변환하는 다음 코드 스니펫을 확인하십시오.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertCDRtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open CDR file
using (var document = new Aspose.Pdf.Document(dataDir + "CDRtoPDF.cdr", new CdrLoadOptions()))
{
// Save PDF document
document.Save(dataDir + "CDRtoPDF_out.pdf");
}
}
DjVu는 LizardTech에서 개발한 압축 이미지 형식입니다. 이 파일 형식은 주로 텍스트, 그림, 색인된 컬러 이미지 및 선 그림의 조합을 포함하는 다양한 종류의 스캔된 문서를 저장하기 위해 설계되었습니다.
DJVU 파일을 PDF 형식으로 변환하는 다음 코드 스니펫을 확인하십시오.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertDJVUtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open DJVU file
using (var document = new Aspose.Pdf.Document(dataDir + "CDRtoPDF.djvu", new DjvuLoadOptions()))
{
// Save PDF document
document.Save(dataDir + "CDRtoPDF_out.pdf");
}
}
HEIC 파일은 여러 이미지를 단일 파일에 컬렉션으로 저장할 수 있는 고효율 컨테이너 이미지 파일 형식입니다. HEIC 이미지를 로드하려면 https://www.nuget.org/packages/FileFormat.Heic/ nuget 패키지에 대한 참조를 추가해야 합니다. Aspose.PDF를 사용하여 HEIC 이미지를 PDF로 변환합니다:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertHEICtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open HEIC file
using (var fs = new FileStream(dataDir + "HEICtoPDF.heic", FileMode.Open))
{
var image = FileFormat.Heic.Decoder.HeicImage.Load(fs);
var pixels = image.GetByteArray(PixelFormat.Rgb24);
var width = (int)image.Width;
var height = (int)image.Height;
using (var document = new Aspose.Pdf.Document())
{
var page = document.Pages.Add();
var asposeImage = new Aspose.Pdf.Image();
asposeImage.BitmapInfo = new Aspose.Pdf.BitmapInfo(pixels, width, height, Aspose.Pdf.BitmapInfo.PixelFormat.Rgb24);
page.PageInfo.Height = height;
page.PageInfo.Width = width;
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Margin.Left = 0;
page.Paragraphs.Add(asposeImage);
// Save PDF document
document.Save(dataDir + "HEICtoPDF_out.pdf");
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.