Hi,
Hi Dinesh,
string outFile = myDir + “ImagetoPDFDOM.pdf”;<o:p></o:p>
string inFile = myDir + "img20140822_18405542.tif";
Document doc = new Document();
Page page = doc.Pages.Add();
// Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
page.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
//Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
//Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
//Set the ImageStream to a MemoryStream object
image1.File = inFile;
MemoryStream ms = new MemoryStream();
doc.Save(ms);
doc = new Document(ms);
foreach (Page page1 in doc.Pages)
{
int idx = 1;
foreach (Aspose.Pdf.XImage image in page1.Resources.Images)
{
using (var imageStream = new MemoryStream())
{
// To compress images change the image type and resolution
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png, 72);
imageStream.Seek(0, SeekOrigin.Begin);
// Control image quality for better compression
page1.Resources.Images.Replace(idx, imageStream, 80);
}
idx = idx + 1;
}
}
doc.OptimizeResources();
doc.Save(outFile);
Please feel free to contact us for any further assistance.
Best Regards,
Thanks for your reply. Sorry for the late reply from my side.
Hi Dinesh,
I have tested the scenario with latest release of Aspose.Pdf for .NET 9.5.0 and all the methods/properties are working fine in latest release. I am afraid we might not be able to fix the issues in older release and we always encourage our customers to try using the latest release. Please download the latest release and try using it.
You may also consider requesting a 30 days temporary license to test the API without any limitations. For more information, please visit Get a temporary license
Hi ,
Dim m_Stream As MemoryStream = Nothing
Dim pdfDocumentGenerator = New Aspose.Pdf.Generator.Pdf()
Dim modifiedFilePath As String = destPath + “\ResultMultiPageFile” + “.PDF”
Try<span style="color:blue;">If</span> <span style="color:blue;">Not</span> System.IO.<span style="color:#2b91af;">Directory</span>.Exists(destPath) <span style="color:blue;">Then</span> System.IO.<span style="color:#2b91af;">Directory</span>.CreateDirectory(destPath) <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:blue;">If</span> System.IO.<span style="color:#2b91af;">File</span>.Exists(modifiedFilePath) <span style="color:blue;">Then</span> System.IO.<span style="color:#2b91af;">File</span>.Delete(modifiedFilePath) <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:blue;">For</span> <span style="color:blue;">Each</span> FilePath <span style="color:blue;">As</span> <span style="color:blue;">String</span> <span style="color:blue;">In</span> FileNames <span style="color:blue;">Dim</span> m_BinaryData <span style="color:blue;">As</span> <span style="color:blue;">Byte</span>() = System.IO.<span style="color:#2b91af;">File</span>.ReadAllBytes(FilePath) m_Stream = <span style="color:blue;">New</span> <span style="color:#2b91af;">MemoryStream</span>(m_BinaryData) <span style="color:blue;">Dim</span> inBitmap <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Bitmap</span>(m_Stream) <span style="color:blue;">Dim</span> pdfGeneratorSection <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Section</span>(pdfDocumentGenerator) <span style="color:green;">'Set margins so image will fit, etc.</span> pdfGeneratorSection.PageInfo.Margin.Top = 0 pdfGeneratorSection.PageInfo.Margin.Bottom = 0 pdfGeneratorSection.PageInfo.Margin.Left = 0 pdfGeneratorSection.PageInfo.Margin.Right = 0 <span style="color:green;">'pdfGeneratorSection.PageInfo.PageWidth = Aspose.Pdf.PageSize.A4.Width</span> <span style="color:green;">'pdfGeneratorSection.PageInfo.PageHeight = Aspose.Pdf.PageSize.A4.Height</span> pdfDocumentGenerator.Sections.Add(pdfGeneratorSection) <span style="color:blue;">Dim</span> pdfImage <span style="color:blue;">As</span> <span style="color:blue;">New</span> Aspose.Pdf.Generator.<span style="color:#2b91af;">Image</span>(pdfGeneratorSection) <span style="color:blue;">Dim</span> refWidth <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = <span style="color:blue;">CInt</span>(pdfGeneratorSection.PageInfo.PageWidth) <span style="color:blue;">If</span> inBitmap.Width > refWidth <span style="color:blue;">Then</span> pdfImage.ImageInfo.FixWidth = refWidth pdfImage.ImageInfo.FixHeight = (inBitmap.Height * refWidth) / pdfImage.ImageInfo.FixWidth <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:blue;">Dim</span> nPercent <span style="color:blue;">As</span> <span style="color:blue;">Single</span> = 0 nPercent = (<span style="color:blue;">CSng</span>(pdfImage.ImageInfo.FixWidth) / <span style="color:blue;">CSng</span>(inBitmap.Width)) pdfImage.ImageInfo.FixWidth = <span style="color:blue;">CInt</span>(inBitmap.Width * nPercent) pdfImage.ImageInfo.FixHeight = <span style="color:blue;">CInt</span>(inBitmap.Height * nPercent) <span style="color:blue;">If</span> pdfImage.ImageInfo.FixWidth > pdfGeneratorSection.PageInfo.PageWidth <span style="color:blue;">Then</span> pdfImage.ImageInfo.FixWidth = pdfGeneratorSection.PageInfo.PageWidth <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:green;">'Add the image into paragraphs collection of the section</span> pdfGeneratorSection.Paragraphs.Add(pdfImage) pdfImage.ImageInfo.ImageFileType = Aspose.Pdf.Generator.<span style="color:#2b91af;">ImageFileType</span>.Tiff pdfImage.ImageInfo.ImageStream = m_Stream pdfImage.ImageInfo.IsBlackWhite = <span style="color:blue;">False</span> <span style="color:blue;">Next</span> <span style="color:green;">'Save the PDF Generator Object to the PDF Object</span> pdfDocumentGenerator.Save(modifiedFilePath) <span style="color:blue;">Catch</span> ex <span style="color:blue;">As</span> <span style="color:#2b91af;">Exception</span> <span style="color:blue;">Throw</span> ex <span style="color:blue;">Finally</span> m_Stream.Dispose() <span style="color:blue;">End</span> <span style="color:blue;">Try</span></pre></div>
Hi Dinesh,
Hi Dinesh,
Hi Dinesh,
Any Updates ??
Hi Dinesh,
Any updates regarding all issues logged as a part of this thread.
Hi Dinesh,
Hi Dinesh,
string outFile = “37458.pdf”;<o:p></o:p>
string inFile = "Generator 37458.tif";
Document doc = new Document();
Page page = doc.Pages.Add();
MarginInfo margin = new MarginInfo();
margin.Top = 0;
margin.Bottom = 0;
margin.Left = 0;
margin.Right = 0;
page.PageInfo.Margin = margin;
//Create an image object in the section
Image image1 = new Image();
//Add image object into the Paragraphs collection of the section
for (int i = 0; i < 55; i++)
page.Paragraphs.Add(image1);
//Set the path of image file
image1.File = inFile;
doc.Save(outFile);
The issues you have found earlier (filed as PDFNEWNET-37458) have been fixed in Aspose.Pdf for .NET 10.0.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Thanks for your support.
dineshpr@cybage.com:Thanks for your support.What about below problems logged as a part of this thread ? Are they resolved with 10.0 as well.1. PDFNEWNET-374592. PDFNEWNET-37460Hi Dinesh,Thanks for your patience.The above stated issues are under investigation but I am afraid they are not yet resolved. Nevertheless, I have requested the development team to share the possible ETA. As soon as we have some further updates regarding their resolution, we will let you know.
dineshpr@cybage.com:Thanks for your support.What about below problems logged as a part of this thread ? Are they resolved with 10.0 as well.1. PDFNEWNET-374592. PDFNEWNET-37460Hi Dinesh,Thanks for your patience.I have further discussed the status of above stated issues with development team and as per our estimates, we plan to get this problem resolved in April-2015 and the fix will become part of Aspose.Pdf for .NET 10.4.0, which is planned for May-2015. As soon as we have some further updates, we will let you know.
We have tried with suggested code approach (DOM approach) like mentioned above with the latest Aspose.PDF 10.3 but still i am facing Memory issue. memory usage increases over 1 GB. At one point of time, it throws an out of memory error for just 55 sample tiff image which i have just attached in my first post. Refer chain of threads for more detail.
Hi Dinesh,
Dim pdfDocument As Document = New Document()<o:p></o:p>
'r Each FilePath As String In FileNames
Dim pdfPage As Aspose.Pdf.Page = pdfDocument.Pages.Add()
'Set margins so image will fit, etc.
pdfPage.PageInfo.Margin.Top = 0
pdfPage.PageInfo.Margin.Bottom = 0
pdfPage.PageInfo.Margin.Left = 0
pdfPage.PageInfo.Margin.Right = 0
Dim pdfImage As New Aspose.Pdf.Image()
pdfImage.File = "c:/pdftest/img20140822_18405542.tif"
Dim counter As Integer
For counter = 1 To 55
'Add the image into paragraphs collection of the section
pdfPage.Paragraphs.Add(pdfImage)
Next
pdfDocument.Save(<span style=“font-size:9.5pt;
line-height:115%;font-family:Consolas;mso-fareast-font-family:“Malgun Gothic”;
mso-fareast-theme-font:minor-fareast;color:#A31515;background:white;mso-highlight:
white;mso-ansi-language:EN-US;mso-fareast-language:KO;mso-bidi-language:AR-SA”>“c:/pdftest/55_TIFF_Image_test.pdf”)