parzival-au20 / sefa

0 stars 0 forks source link

new pdf #43

Open parzival-au20 opened 8 months ago

parzival-au20 commented 8 months ago

public System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn) { MemoryStream memoryStream = new MemoryStream(byteArrayIn); using (MemoryStream ms = new MemoryStream(byteArrayIn)) { System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms); new Bitmap(returnImage, new Size(85, 85)).Save(memoryStream, ImageFormat.Jpeg); returnImage = System.Drawing.Image.FromStream(memoryStream); return returnImage; } memoryStream.Close(); }

parzival-au20 commented 8 months ago

int totalfonts = FontFactory.RegisterDirectory("C:\WINDOWS\Fonts");

StringBuilder sb = new StringBuilder();

foreach (string fontname in FontFactory.RegisteredFonts)

{

sb.Append(fontname + "\n");

}

doc.Add(new Paragraph("All Fonts:\n" + sb.ToString()));

parzival-au20 commented 8 months ago

string fontpath = Server.MapPath(".");

BaseFont customfont = BaseFont.CreateFont(fontpath + "myspecial.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);

Font font = new Font(customfont, 12);

string s = "My expensive custom font.";

doc.Add(new Paragraph(s, font));

parzival-au20 commented 8 months ago

public System.Drawing.Image ResizeImage(byte[] byteArrayIn, int width, int height) { using (MemoryStream ms = new MemoryStream(byteArrayIn)) { System.Drawing.Image sourceImage = System.Drawing.Image.FromStream(ms); System.Drawing.Image resizedImage = sourceImage.GetThumbnailImage(width, height, null, IntPtr.Zero); return resizedImage; } }

parzival-au20 commented 8 months ago

public System.Drawing.Image ResizeImage(byte[] byteArrayIn, float targetHeightInCM) { float dpi = 96; // varsayılan DPI değeri float targetHeightInInch = targetHeightInCM / 2.54f; // Santimetreleri inçe çevirme int targetHeightInPixels = (int)(targetHeightInInch * dpi); // Yüksekliği piksel cinsine dönüştürme

using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
    System.Drawing.Image sourceImage = System.Drawing.Image.FromStream(ms);

    if (sourceImage.Height < targetHeightInPixels)
    {
        // Resmin yüksekliği 3 cm'den küçükse, orijinal boyutunu koruyarak bas
        return sourceImage;
    }

    float aspectRatio = (float)sourceImage.Width / sourceImage.Height;
    int targetWidthInPixels = (int)(targetHeightInPixels * aspectRatio); // Genişliği yüksekliğe göre oranlama

    System.Drawing.Image resizedImage = sourceImage.GetThumbnailImage(targetWidthInPixels, targetHeightInPixels, null, IntPtr.Zero);
    return resizedImage;
}

}