Hi,
Hi Joel,
public static void ConvertImageToPdf(string inputFileName, string outputFileName)<o:p></o:p>
{<o:p></o:p>
// Create Aspose.Words.Document and DocumentBuilder.<o:p></o:p>
// The builder makes it simple to add content to the document.<o:p></o:p>
Document doc = new Document();<o:p></o:p>
DocumentBuilder builder = new DocumentBuilder(doc);<o:p></o:p>
// Read the image from file, ensure it is disposed.<o:p></o:p>
using (Image image = Image.FromFile(inputFileName))<o:p></o:p>
{<o:p></o:p>
// Get the number of frames in the image.<o:p></o:p>
int framesCount = image.GetFrameCount(FrameDimension.Page);<o:p></o:p>
// Loop through all frames.<o:p></o:p>
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)<o:p></o:p>
{<o:p></o:p>
// Insert a section break before each new page, in case of a multi-frame TIFF.<o:p></o:p>
if (frameIdx != 0)<o:p></o:p>
builder.InsertBreak(BreakType.SectionBreakNewPage);<o:p></o:p>
// Select active frame.<o:p></o:p>
image.SelectActiveFrame(FrameDimension.Page, frameIdx);<o:p></o:p>
// Max page size<o:p></o:p>
const double maxPageHeight = 1584;<o:p></o:p>
const double maxPageWidth = 1584;<o:p></o:p>
double currentImageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);<o:p></o:p>
double currentImageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);<o:p></o:p>
if (currentImageWidth >= maxPageWidth || currentImageHeight >= maxPageHeight)<o:p></o:p>
{<o:p></o:p>
// Get max image size.<o:p></o:p>
CalculateImageSize(image, maxPageHeight, maxPageWidth, outcurrentImageHeight, out currentImageWidth);<o:p></o:p>
}<o:p></o:p>
// We want the size of the page to be the same as the size of the image.<o:p></o:p>
// Convert pixels to points to size the page to the actual image size.<o:p></o:p>
PageSetup ps = builder.PageSetup;<o:p></o:p>
ps.PageWidth = currentImageWidth;<o:p></o:p>
ps.PageHeight = currentImageHeight;<o:p></o:p>
// Insert the image into the document and position it at the top left corner of the page.<o:p></o:p>
builder.InsertImage(<o:p></o:p>
image,<o:p></o:p>
RelativeHorizontalPosition.Page,<o:p></o:p>
0,<o:p></o:p>
RelativeVerticalPosition.Page,<o:p></o:p>
0,<o:p></o:p>
ps.PageWidth,<o:p></o:p>
ps.PageHeight,<o:p></o:p>
WrapType.None);<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
// Save the document to PDF.<o:p></o:p>
doc.Save(outputFileName);<o:p></o:p>
}<o:p></o:p>
/// Calculates size of Image<o:p></o:p>
/// <o:p></o:p>
/// Original image<o:p></o:p>
/// Height of container where image should be inserted.<o:p></o:p>
/// Width of container where image should be inserted.<o:p></o:p>
/// Height of the image<o:p></o:p>
/// Width of the image<o:p></o:p>
public static void CalculateImageSize(Image img, double containerHeight, doublecontainerWidth, out double targetHeight, out double targetWidth)<o:p></o:p>
{<o:p></o:p>
//Calculate width and height<o:p></o:p>
targetHeight = containerHeight;<o:p></o:p>
targetWidth = containerWidth;<o:p></o:p>
//Get size of an image<o:p></o:p>
double imgHeight = ConvertUtil.PixelToPoint(img.Height);<o:p></o:p>
double imgWidth = ConvertUtil.PixelToPoint(img.Width);<o:p></o:p>
if (imgHeight < targetHeight && imgWidth < targetWidth)<o:p></o:p>
{<o:p></o:p>
targetHeight = imgHeight;<o:p></o:p>
targetWidth = imgWidth;<o:p></o:p>
}<o:p></o:p>
else<o:p></o:p>
{<o:p></o:p>
//Calculate size of an image in the document<o:p></o:p>
double ratioWidth = imgWidth / targetWidth;<o:p></o:p>
double ratioHeight = imgHeight / targetHeight;<o:p></o:p>
if (ratioWidth > ratioHeight)<o:p></o:p>
targetHeight = (targetHeight * (ratioHeight / ratioWidth));<o:p></o:p>
else<o:p></o:p>
targetWidth = (targetWidth * (ratioWidth / ratioHeight));<o:p></o:p>
}<o:p></o:p>
}
Hi Joel,
the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-35738. We
will investigate this issue in details and will keep you updated on the status
of a correction.
We apologize for your inconvenience.
The issues you have found earlier (filed as PDFNEWNET-35738) have been fixed in Aspose.Pdf for .NET 9.4.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Joel,
SvgLoadOptions options = new SvgLoadOptions();<o:p></o:p>
options.ConversionEngine = SvgLoadOptions.ConversionEngines.NewEngine;
options.PageInfo.Margin.Top = 0;
options.PageInfo.Margin.Left = 0;
options.PageInfo.Margin.Bottom = 0;
options.PageInfo.Margin.Right = 0;
string inFile = @"35738.svg";
string outFile = @"35738.pdf";
Document pdfDocument = new Document(inFile, options);
pdfDocument.Save(outFile);