Hi,
I have another problem. Here is my code :
FileStream inFileStream1 = File.OpenRead("C:\\Temp\\file.pdf");
MemoryStream doc1 = new MemoryStream();
doc1.SetLength(inFileStream1.Length);
inFileStream1.Read(doc1.GetBuffer(), 0, (int)inFileStream1.Length);
using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(doc1))
{
//Check first page to verify size and adjust if not 8.5 x 11 inches
PageInfo pageInfo = new PageInfo();
if (doc.Pages[1].MediaBox.URY != pageInfo.Height || doc.Pages[1].MediaBox.URX != pageInfo.Width)
{
pageInfo.Height = (int)doc.Pages[1].MediaBox.URY;
pageInfo.Width = (int)doc.Pages[1].MediaBox.URX;
}
using (Aspose.Pdf.Facades.PdfFileMend mendor = new Aspose.Pdf.Facades.PdfFileMend(doc))
{
Stream imageMemoryStream = new MemoryStream();
float halfWidth = 0.0f, halfHeight = 0.0f, x = 0.0f, y = 0.0f;
// Instantiate linear barcode object
BarCodeBuilder barCodeBuilder = new BarCodeBuilder();
barCodeBuilder.CodeText = "FRE0400 - 0000284A";
barCodeBuilder.CodeTextFont = new System.Drawing.Font(barCodeBuilder.CodeTextFont.Name, 10f);
barCodeBuilder.CodeTextSpace = 1f;
barCodeBuilder.xDimension = 0.2f;
barCodeBuilder.BarHeight = 6.5f;
barCodeBuilder.SymbologyType = Symbology.Code128;
barCodeBuilder.Resolution = new Resolution(300f, 300f, ResolutionMode.Customized);
barCodeBuilder.BarCodeImage.Save(imageMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp); // Jpeg and BMP are the fastest
barCodeBuilder.BarCodeImage.Save("C:\\Temp\\barcode.bmp");
halfWidth = (float)ConvertUtil.PixelToPoint(barCodeBuilder.BarCodeImage.Width) / 2f;
halfHeight = (float)ConvertUtil.PixelToPoint(barCodeBuilder.BarCodeImage.Height) / 2f;
// Add image to the input PDF file on the first page at specified location
x = (float)pageInfo.Width - halfWidth;
y = (float)pageInfo.Height - halfHeight;
float LLX = x - halfWidth;
float LLY = y - halfHeight;
float URX = x + halfWidth;
float URY = y + halfHeight;
mendor.AddImage(imageMemoryStream, 1, LLX, LLY, URX, URY);
Stream outStream = new MemoryStream();
doc.Save(outStream);
// Rewind the stream position back to zero so it is ready for next reader
outStream.Position = 0;
FileStream outFileStream1 = new FileStream("C:\\Temp\\file_barcode1.pdf", FileMode.Create);
(outStream as MemoryStream).WriteTo(outFileStream1);
}
}
When I'm looking at barcode.bmp the resolution is 300 DPI which is good.
But when I'm looking at file_barcode1.pdf, the resolution is only 96 DPI. Do you have any idea why ?
Thank you !