Open parzival-au20 opened 9 months ago
using System; using System.Collections.Generic; using Microsoft.Office.Interop.Word;
namespace MetinHesaplamaUygulamasi
{
class Program
{
static void Main(string[] args)
{
// Örnek metinler
List
// Yazı tipi ve sayfa boyutunu tanımla
float sayfaGenisligiInch = 8.5f; // Örnek: A4 kağıdı genişliği (inç cinsinden)
float sayfaUzunluguInch = 11f; // Örnek: A4 kağıdı uzunluğu (inç cinsinden)
float yazıTipiBoyutu = 12f; // Örnek: 12 punto
float kenarBosluguInch = 1f; // Kenar boşluğu (inç cinsinden)
// Maksimum metin uzunluğunu hesapla
float maksimumMetinUzunlugu = ((sayfaGenisligiInch - kenarBosluguInch * 2) * (sayfaUzunluguInch - kenarBosluguInch * 2))
/ (yazıTipiBoyutu * 0.75f); // Yazı tipi boyutuna göre ortalama karakter uzunluğu hesaplanabilir
// Toplam metin uzunluğunu hesapla
float toplamMetinUzunlugu = 0;
foreach (string paragraf in paragraflar)
{
toplamMetinUzunlugu += paragraf.Length;
}
// Kalan alanı hesapla
float kalanAlan = maksimumMetinUzunlugu - toplamMetinUzunlugu;
Console.WriteLine("Maksimum metin uzunluğu: " + maksimumMetinUzunlugu);
Console.WriteLine("Toplam metin uzunluğu: " + toplamMetinUzunlugu);
Console.WriteLine("Kalan alan: " + kalanAlan);
}
}
}
System.Drawing.Image image = ByteArrayToImage(yurtDisiHaberler[i].Image); int desiredWidth = 300; // İstenen genişlik int desiredHeight = 200; // İstenen yükseklik image = ResizeImage(image, desiredWidth, desiredHeight); // ResizeImage fonksiyonunu kullandık
private System.Drawing.Image ResizeImage(System.Drawing.Image image, int width, int height) { // Yeni bir Bitmap oluştur System.Drawing.Image newImage = new System.Drawing.Bitmap(width, height);
// Graphics objesi oluştur ve yeni resmi oluşturulan Bitmap'e çiz
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(newImage))
{
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(image, 0, 0, width, height);
}
return newImage;
}
error CS0051: Inconsistent accessibility: parameter type 'ListNewsEntity' is less accessible than method 'Form1.AddStyledParagraph(Document, ListNewsEntity, int, string, object, Color)' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
int PageNo = 1;
if (yurtIciHaberler.Any())
{
iTextSharp.text.Paragraph yurtIciHaberlerTitle = new iTextSharp.text.Paragraph(new Chunk("YURT ICI KAYNAKLI HABERLER", FontFactory.GetFont(FontFactory.TIMES_BOLD, 12, iTextSharp.text.Font.NORMAL)));
yurtIciHaberlerTitle.Alignment = Element.ALIGN_CENTER;
document.Add(yurtIciHaberlerTitle);
for (int y = 0; y < yurtIciHaberler.Count; y++)
{
List<Paragraph> addedParagraphs = new List<Paragraph>();
var anchor = new Chunk("Devami için tiklayiniz.")
{
Font = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, iTextSharp.text.Font.NORMAL, BaseColor.BLUE)
};
string[] sentences = Regex.Split(yurtIciHaberler[y].Text, @"(?<=[\.!\?])\s+");
foreach (var sentence in sentences)
{
newsContent += sentence.Replace('ş', 's').Replace('ü', 'u').Replace('ı', 'i').Replace('ö', 'o').Replace('ğ', 'g').Replace('ç', 'c').Replace('Ü', 'U')
.Replace('Ş', 'S').Replace('İ', 'I').Replace('Ğ', 'G').Replace('Ö', 'O');
if (newsContent.Length >= 1000)
{
anchor.SetAnchor(yurtIciHaberler[y].Url);
break;
}
}
iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(new Chunk(newsContent, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, iTextSharp.text.Font.NORMAL)));
if (newsContent.Length >= 1000)
{
paragraph.Add("\n");
paragraph.Add(anchor);
}
if (yurtIciHaberler[y].Title.Contains("Haber Merkezi"))
{
yurtIciHaberler[y].Title = yurtIciHaberler[y].Title.Substring(0, yurtIciHaberler[y].Title.IndexOf("Haber Merkezi"));
}
yurtIciHaberler[y].Title = yurtIciHaberler[y].Title.Replace('ş', 's').Replace('ü', 'u').Replace('ı', 'i').Replace('ö', 'o').Replace('ğ', 'g').Replace('ç', 'c').Replace('Ü', 'U')
.Replace('Ş', 'S').Replace('İ', 'I').Replace('Ğ', 'G').Replace('Ö', 'O');
iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph(new Chunk(yurtIciHaberler[y].Title, FontFactory.GetFont(FontFactory.TIMES_BOLD, 16, iTextSharp.text.Font.NORMAL)));
iTextSharp.text.Paragraph date = new iTextSharp.text.Paragraph(new Chunk(yurtIciHaberler[y].PublishDate.ToString("dd.MM.yyyy"), FontFactory.GetFont(FontFactory.TIMES_ITALIC, 11, iTextSharp.text.Font.NORMAL)));
iTextSharp.text.Paragraph newsSource = new iTextSharp.text.Paragraph(new Chunk(yurtIciHaberler[y].WebSiteName, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, iTextSharp.text.Font.NORMAL)));
int index = !yurtIciHaberler[y].Url.Contains(".net") ? yurtIciHaberler[y].Url.IndexOf(".com") : yurtIciHaberler[y].Url.IndexOf(".net");
iTextSharp.text.Paragraph newsUrl = new iTextSharp.text.Paragraph(new Chunk(yurtIciHaberler[y].Url.Substring(0, index + 4), FontFactory.GetFont(FontFactory.TIMES_ITALIC, 11, iTextSharp.text.Font.NORMAL)));
paragraph.Alignment = Element.ALIGN_JUSTIFIED;
title.Alignment = Element.ALIGN_CENTER;
date.Alignment = Element.ALIGN_RIGHT;
newsSource.Alignment = Element.ALIGN_RIGHT;
newsUrl.Alignment = Element.ALIGN_LEFT;
addedParagraphs.Add(new Chunk("\n\n\n"));
addedParagraphs.Add(title);
addedParagraphs.Add(new Chunk("\n"));
addedParagraphs.Add(date);
addedParagraphs.Add(newsSource);
addedParagraphs.Add(new Chunk("\n"));
if (yurtIciHaberler[y].Image != null)
{
try
{
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(yurtIciHaberler[y].Image);
img.ScaleToFit(250f, 250f);
img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_CENTER;
img.IndentationLeft = 9f;
img.SpacingAfter = 9f;
addedParagraphs.Add(img);
addedParagraphs.Add(new Chunk("\n"));
}
catch
{
addedParagraphs.Add(new Chunk("\n"));
}
}
addedParagraphs.Add(paragraph);
addedParagraphs.Add(new Chunk("\n"));
addedParagraphs.Add(newsUrl);
foreach (var item in addedParagraphs){
document.Add(item);
}
if(writer.PageNumber > PageNo){
document.rem
document.NewPage();
PageNo++;
}
newsContent = "";
//document.NewPage();
}
}
iText represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high- and low-level programming capabilities and the ability to create, edit and enhance PDF documents, the iText PDF library can be a boon to nearly every workflow. iText allows you to build custom PDF scenarios for web, mobile, desktop or cloud apps in .NET.
iText was built on nearly a decade of lessons learned from iText 5 (iTextSharp) development. It is a simpler, more performant and extensible library that is ready to handle the increased challenges of today's document workflows, one add-on at a time.
The iText Suite consists of iText Core and several add-ons. The add-ons are accessible as different packages.
What you can do with iText: Generate PDFs:
Mass generation of PDFs, including tagged PDFs which contain metadata to describe the document structure and the order of its elements (e.g. titles, text blocks, columns and pictures) Convert images to PDF Convert HTML to PDF (with the pdfHTML iText add-on) iText is unique in its breadth of language support, including Indic languages, Thai, Khmer, Arabi, Hebrew, Chinese, Japanese, Korean, Cyrillic languages and many more, in combination of (with the pdfCalligraph iText add-on) Edit and manipulate PDFs:
Split or merge PDFs, delete pages from a PDF Rotate a PDF or specific pages Add passwords and PDF permission options to a PDF, or remove password protection from a PDF Update/add content, PDF objects [dictionaries etc.], watermarks, bookmarks… Remove sensitive data, Regex based redaction (PDF redaction) (with the pdfSweep iText add-on) Create and modify annotations Programmatically fill out PDF forms (AcroForm and XFA) Flatten AcroForms Read XFA Flatten XFA (with the pdfXFA iText add-on)
'Paragraph' is an ambiguous reference between 'Microsoft.Office.Interop.Word.Paragraph' and 'iTextSharp.text.Paragraph'
: error CS0104: 'Paragraphs' is an ambiguous reference between 'Aspose.Pdf.Paragraphs' and 'Microsoft.Office.Interop.Word.Paragraphs'
1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(1800,54,1800,76): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List
public class News
{
public List
public News()
{
iTextSharp.text.Paragraph Paragraphs = new List<Paragraphs>();
}
}
The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2115,9,2115,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2132,9,2132,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2144,9,2144,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2149,9,2149,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2154,9,2154,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2159,9,2159,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2180,12,2180,19): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2185,9,2185,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2194,9,2194,16): error CS0106: The modifier 'private' is not valid for this item 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2194,17,2194,23): error CS8370: Feature 'static local functions' is not available in C# 7.3. Please use language version 8.0 or greater. 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2194,24,2194,30): error CS8370: Feature 'extern local functions' is not available in C# 7.3. Please use language version 9.0 or greater. 1>C:\Users\s20128\Desktop\MedyaTakip2 - 2.0 - Prod-To\MedyaTakip2\Form1.cs(2204,2,2204,2): error CS1513: } expected
public void AddNews(List
// Eğer paragraf mevcut sayfaya sığmazsa yeni bir sayfa ekle
if (paragraphHeight > remainingSpace)
{
document.NewPage();
remainingSpace = document.PageSize.Height - document.TopMargin - document.BottomMargin - document.Bottom;
}
// Paragrafı sayfaya ekle
document.Add(paragraph);
remainingSpace -= paragraphHeight;
}
}
Paragraph' does not contain a definition for 'CalculateHeights' and no accessible extension method 'CalculateHeights' accepting a first argument of type 'Paragraph' could be found (are you missing a using directive or an assembly reference?)
public float CalculateParagraphHeight(Paragraph paragraph, PdfWriter writer) { // PdfContentByte nesnesi oluşturun PdfContentByte canvas = writer.DirectContent;
// ColumnText nesnesi oluşturun
ColumnText column = new ColumnText(canvas);
column.AddElement(paragraph);
column.SetSimpleColumn(0, 0, 300, 800); // Genişlik ve yükseklik ayarlarını dilediğiniz gibi ayarlayabilirsiniz
column.Go();
// Yüksekliği hesaplayın
return column.YLine;
}
public void AddNews(List
// Eğer paragraf mevcut sayfaya sığmazsa yeni bir sayfa ekle
if (paragraphHeight > remainingSpace)
{
document.NewPage();
remainingSpace = document.PageSize.Height - document.TopMargin - document.BottomMargin - document.Bottom;
}
// Paragrafı sayfaya ekle
document.Add(newsParagraph);
remainingSpace -= paragraphHeight;
}
}
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 40, 40, 0, 0);
public float CalculateParagraphHeight(iTextSharp.text.Paragraph paragraph, PdfWriter writer, iTextSharp.text.Document document) { // PdfContentByte nesnesi oluşturun PdfContentByte canvas = writer.DirectContent;
// ColumnText nesnesi oluşturun
ColumnText column = new ColumnText(canvas);
column.AddElement(paragraph);
column.SetSimpleColumn(40, 0, 555, 842); // Genişlik ve yükseklik ayarlarını dilediğiniz gibi ayarlayabilirsiniz
column.Go();
document.NewPage();
// Yüksekliği hesaplayın
float lineHeight = column.YLine;
//canvas.Reset();
return lineHeight;
}
Bunun paragraf boyutunu doğru hesapladığına emin misin
private void CreateDocumentsWithWord(List newsEntities, string selectedFilePath)
{
List yurtDisiHaberler = newsEntities.Where(p => p.WebSiteName != "DefenceTurk" && p.WebSiteName != "DefenceTurkey" && p.WebSiteName != "SavunmaSanayist").ToList();
List yurtIciHaberler = newsEntities.Where(p => p.WebSiteName == "DefenceTurk" || p.WebSiteName == "DefenceTurkey" || p.WebSiteName == "SavunmaSanayist").ToList();