티스토리 뷰
try
{
PrintDialog printDialog = new PrintDialog(); // 프린트 다이얼로그 생성
printDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
printDialog.PageRangeSelection = PageRangeSelection.AllPages;
printDialog.SelectedPagesEnabled = true;
printDialog.UserPageRangeEnabled = true;
string return_value = string.Empty;
if (Print_Queue == true)
{
Print_Queue = false;
printDialog.MaxPage = 7; // 최대페이지.
Nullable print;
print = printDialog.ShowDialog();
string panel_name = string.Empty;
if (print == true)
{
int TS, ES;
if ((bool)print_chk.IsChecked) // Checkbox 프린트, PDF인쇄중 프린트 체크박스 선택
{
TS = printDialog.PageRange.PageFrom;
ES = printDialog.PageRange.PageTo;
}
else
{
TS = 1;
ES = 7;
}
if (ES == 0) // 모두 인쇄 하면 마지막장이 0으로... 그래서 최대 페이지로
{
ES = 7;
}
StackPanel SP = new StackPanel();
CheckBox CBX = new CheckBox();
int print_count = 0;
int page_count = 0;
// pdfSharp 을 누겟에서 설치하고 사용. 버전 v1.50.4147 ( PDFsharp 작성자: empira software GmbH)
//using PdfSharp.Drawing;
//using PdfSharp.Pdf;
PdfDocument document = new PdfDocument(); // PDF Document 생성
PdfPage page = new PdfPage(); // PDF page 생성
Image _img = new Image();
for (int TST = TS-1; TST < ES; TST++)
{
var CBX_Name = print_stack_grid.Children.OfType<CheckBox>().Where(txb => txb.Name == "print" + TST).FirstOrDefault();
// print_stack_grid에서 print1~7 번까지 체크박스를 찾고
CBX = (CheckBox)CBX_Name; // CBX 에 할당.
print_count += 1;
SP = (StackPanel)MainBody_Pan.FindName("Panel" + TST.ToString()); // 메인패널에서 Panel1~7까지 찾아.
System.Windows.Rect bounds = VisualTreeHelper.GetDescendantBounds(SP);
double dpi = 96;
RenderTargetBitmap rtb = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, dpi, dpi, System.Windows.Media.PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(SP);
dc.DrawRectangle(vb, null, new System.Windows.Rect(new System.Windows.Point(), bounds.Size));
}
rtb.Render(dv);
if ((bool)print_chk.IsChecked)
{
printDialog.PrintVisual(dv, "Page" + TST.ToString()); //프린트한다.
}
// PDF제작
byte[] data;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
BitmapEncoder endocder2 = new PngBitmapEncoder();
endocder2.Frames.Add(BitmapFrame.Create(rtb));
endocder2.Save(ms);
data = ms.ToArray();
BitmapImage _image = new BitmapImage();
_image.BeginInit();
_image.StreamSource = ms;
_image.EndInit();
using (XImage img = XImage.FromStream(ms))
{
page = document.AddPage();
page.Orientation = PdfSharp.PageOrientation.Landscape;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawImage(img, 0, 0, SP.Width*0.75, SP.Height*0.75);
}
}
// PDF Document 생성완료
} // for loop end
return_value = PDF_FTP(document, Member_Names, "Report"); // 제작된 PDF를 FTP로 전송
MessageBox.Show("출력되었습니다.");
}
}
return return_value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return "";
}
// FTP전송
private string PDF_FTP(PdfDocument png, string Member_Names, string panel_name)
{
try
{
byte[] data;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
png.Save(ms);
data = ms.ToArray();
}
string serverAddress = "ftp://";
string userId = "id";
string userPass = "pass";
string dir = "/저장경로";
string Times = DateTime.Now.ToString().Replace(" ", "").Replace("-", "").Replace(":", "").Replace("/", ""); // file_addname + //DateTime.Now.ToString();
string uploadPath = serverAddress + dir + Member_Names + Times + "_" + panel_name + ".pdf";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uploadPath);
// FTP 업로드한다는 것을 표시
request.Method = WebRequestMethods.Ftp.UploadFile;
// 쓰기 권한이 있는 FTP 사용자 로그인 지정
request.Credentials = new NetworkCredential(userId, userPass);
// RequestStream에 데이타를 쓴다
request.ContentLength = data.Length;
using (System.IO.Stream reqStream = request.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
}
// FTP Upload 실행
using (FtpWebResponse resp = (FtpWebResponse)request.GetResponse())
{
return Member_Names + Times + "_" + panel_name + ".pdf";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return "";
}
}
'WPF' 카테고리의 다른 글
WPF SQLite Nuget 설치후 x86/x64 버전 SQLite.Interop.dll을 찾지 못할때 (0) | 2020.03.25 |
---|---|
Custom class Clr-namespace (0) | 2020.03.17 |
Datagrid CheckBox Template GetCellContent Null Exception or always False Value error (0) | 2020.02.02 |
WPF Rectangle Animate (0) | 2020.01.29 |
DataTable Column Sum Total (0) | 2020.01.22 |
- Total
- Today
- Yesterday
- 연산자 뒤에 피연산자가 없습니다.
- 서버 수준의 URN 필터
- c# Encrypt / Decrypt
- Microcharts
- SkiaSharp
- Xamarin Firebase Phone User Add
- 암호 마스터키
- FileStream Add Byte
- Xamarin.Forms
- Xamarin.Ios Firebase Phone Auth
- Windows IIS FTP 디렉토리 목록 오류
- Xamarin.Ios Firebase Phone SMS OTP Send
- Linux SSH Multi Computer Join
- WPF Excel Export Microsoft.Office.Interop 성능향상(열 기준으로 복사)
- WPF Textbox
- Xamarin.Ios Firebase Phone User Add
- Entry '' has empty native path
- Label Text LineBreak in Xaml
- Xamarin SMS OTP Send
- C# LINQ Left join
- GetCellContent CheckBox Value
- Xamarin Firebase Phone Auth
- WPF Scrollviewer in ScrollViwer
- ClickOnce 인증서 인증기간 변경
- Xamarin reCAPTCHA
- WPF Datagrid Cell Value Change
- ssl_client_socket_impl.cc
- Embeded 한글Font적용
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |