본문 바로가기
C#

C# Base64 PDF 변환

by Sudarii 2025. 4. 3.
728x90

API 호출 후 PDF 를 저장 하기 위해 사용한다 .

 

 

HttpResponseMessage response = await client.PostAsync(url, content);
string responseContent = await response.Content.ReadAsStringAsync();

Console.WriteLine($"Response Status Code: {response.StatusCode}");
Console.WriteLine($"Response Body: {responseContent}");

// JSON 파싱
JObject jsonObj = JObject.Parse(responseContent);
string base64Content = jsonObj["documents"][0]["content"].ToString(); // content 값 가져오기
                                                                    // JSON에서 content 가져오기 (Base64 인코딩된 PDF)

string filePath = "output.pdf";
byte[] pdfBytes = Convert.FromBase64String(base64Content);
File.WriteAllBytes(filePath, pdfBytes);

Console.WriteLine($"PDF 저장 완료: {filePath}");

// PDF 파일 열기 (자동 출력)
Process.Start(new ProcessStartInfo(filePath) { UseShellExecute = true });
728x90