我正在为我的项目使用 pdfsharp..
我正在尝试将转换后的 PdfDocument 对象保存到指定路径中的 pdf 文件中。
我有这个方法
public static PdfDocument ConvertTiff2Pdf(string docpath)
{
var pdfDoc = Tiff2Pdf(docpath);
return pdfDoc;
}
Run Code Online (Sandbox Code Playgroud)
这将返回 PdfDocument,我想将其保存到“C:\temp\docname.pdf”文件夹中。
如何在不使用http响应的情况下使用csharp来做到这一点..因为我必须首先将其存储在服务器上然后使用..请帮助我..
我说的是 PdfSharp。纵向方向适用于有边距或无边距。但在横向的情况下,一旦我使用 TrimMargins 设置任何边距,页面就会在右侧截断。我在 pdfSharp 的示例代码上尝试了同样的事情并且遇到了同样的问题!
看看以下代码的 pdf 渲染效果是否良好
page = document.AddPage();
page.Size = PdfSharp.PageSize.A4;
page.Orientation = PageOrientation.Landscape;
gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("A4 (landscape)", font,XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),XStringFormats.Center);
Run Code Online (Sandbox Code Playgroud)
但是对于以下代码,pdf 渲染得不好,在右侧截断
page = document.AddPage();
page.TrimMargins.Top = 5;
page.TrimMargins.Right = 5;
page.TrimMargins.Bottom = 5;
page.TrimMargins.Left = 5;
page.Size = PdfSharp.PageSize.A4;
page.Orientation = PageOrientation.Landscape;
gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("A4 (landscape)", font,XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),XStringFormats.Center);
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?谢谢
使用 PDFsharp .NET 库,我需要将 PDF 文档中的页面大小设置为与图像相同。
示例,图像编号。1 尺寸为 152 像素 x 1775 像素。图片编号 2 个 100 像素 x 1582 像素
生成的 PDF 内部应该有不同的页面大小。
请帮忙。
使用以下代码,我可以设置图像的大小,现在的问题是设置页面大小。
PdfDocument doc = new PdfDocument();
//doc.Pages.Add(new PdfPage());
PdfPage page = doc.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(doc.Pages[0]);
XImage xImage = XImage.FromFile(source);
gfx.DrawImage(xImage, 0, 0, xImage.PixelWidth, xImage.PixelHeight);
doc.Save(destinaton);
doc.Close();
//
Run Code Online (Sandbox Code Playgroud) 无论我是否使用XTextFormatter,我都得到关于LayoutRectangle的高度为0或类似的错误.
new PdfSharp.Drawing.Layout.XTextFormatter(_gfx).DrawString(text
, new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle)
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(xPos, yPos), new PdfSharp.Drawing.XPoint(xLimit, yLimit))
, PdfSharp.Drawing.XStringFormats.Default);
Run Code Online (Sandbox Code Playgroud)
fontStyle的类型为System.Drawing.FontStyle foreColour的类型为System.Drawing.Color我已经从PdfPage预定义_gfx,Orientation = Landscape,Size = Letter xPos和yPos是double类型的参数,与xLimit和yLimit相同.
我得到运行时错误,LayoutRectangle的高度必须为零(0)...
根据定义,矩形意味着具有高度,否则称为线!我不明白!...
我直接尝试使用XGraphics.DrawString()方法,我得到了同样的错误.似乎我不能使用LayoutRectangle,但必须手动管理文本适合所需区域.
var textFont = new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (xPos + _gfx.MeasureString(text, textFont).Width > xLimit)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (yPos + _gfx.MeasureString(text, textFont).Height > yLimit && fontSize > 0)
textFont = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pdfsharp库将多个图像转换为pdf .
我能够转换单个图像,它工作得很好.
虽然转换bulk images为single pdf我面临的问题是它需要所有图像并转换它们但转换后如果我检查它只显示最后一个图像,因为它没有附加到现有图像并且它会覆盖前一个图像.
那么我该如何纠正呢?
任何帮助将不胜感激,因为我第一次使用pdf库并指出我如果我正在做任何错误.我将会更多地了解这一点,我不会感到如果你指出我的错误我完成了.
这是我的代码:
Private Sub btnAddFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddFolder.Click
If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim f As New DirectoryInfo(Me.FolderBrowserDialog1.SelectedPath)
Dim fso As New System.Object
For Each file As FileInfo In f.GetFiles
Select Case file.Extension.ToLower
Case ".jpg", ".bmp", ".gif", ".png"
Me.ThumbControl1.BackgroundImage = Nothing
Me.CheckedListBox1.Items.Add(file.FullName, CheckState.Checked)
Me.ThumbControl1.AddThumbnail(file.FullName)
Me.ThumbControl1.BackgroundImage = Nothing
Me.CheckedListBox1.SelectedIndex = 0
End Select
Next
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
背景工作者:
Private Sub bw_DoWork(ByVal …Run Code Online (Sandbox Code Playgroud) 我是第一次使用 MigraDoc 库,需要帮助。我正在使用 .pdf 格式打印表格MigraDoc。在我的表 3 行形成一个组。所以每个 3 行组必须在同一页面上,但在我当前的代码中这不会发生。
它将在同一页上打印第一行或第二行,如果页面结束,则第三行进入下一页。
public void CreateDocument()
{
this.document = new Document { Info = { Title = "Time Sheet Report By Job", } };
this.DefineStyles();
this.CreatePage();
this.FillContent();
}
public void FillContent()
{
int x = 1;
foreach (XElement r in this.xReport.Element(ElrepTable).Elements(ElrepRow))
{
Row row1 = this.table.AddRow();
int i = 0;
row1.Cells[0].Borders.Visible = false;
foreach (XElement c in r.Elements(ElrepCell))
{
row1.Cells[i++].AddParagraph(c.Value);
}
if (x++ % 3 != 0)
{
continue; …Run Code Online (Sandbox Code Playgroud) 我是c#,wpf和pdfsharp库的新手.这是我的XAML代码:
<Grid>
<zoom:ZoomControl>
<graphsharp:GraphLayout x:Name="graphLayout"
Graph="{Binding ElementName=root, Path=GraphToVisualize}"
LayoutAlgorithmType="FR"
OverlapRemovalAlgorithmType="FSA"
HighlightAlgorithmType="Simple"></graphsharp:GraphLayout>
</zoom:ZoomControl>
<Button Content="Button" Height="23" Name="button1" Width="75" Margin="12,294,658,412" Click="button1_Click" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
我现在想要使用Pdfsharp将我的"graphLayout"保存到pdf文件中.我创建了一个按钮,基本上使用了pdfsharp wiki中的"hello world"示例代码来启动.
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
gfx.DrawString("My Graph", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.TopCenter);
const string filename = "MyGraph.pdf";
document.Save(graphLayout+filename);
Process.Start(filename);
Run Code Online (Sandbox Code Playgroud)
我得到一个pdf,但其中只有文字.有人可以告诉我,我如何将整个布局保存为PDF格式?谢谢
我有两个非常相似的pdf文件。但是,如果我尝试处理第一个,它会抛出“令牌 '373071' 不是预期的”异常,但对于其他的,我可以完全执行代码。下面是我的代码
class Program
{
static void Main(string[] args)
{
int bufferSize = 20480;
try
{
byte[] byteBuffer = new byte[bufferSize];
byteBuffer = File.ReadAllBytes(@"..\..\Fail.pdf");
MemoryStream coverSheetContent = new MemoryStream();
coverSheetContent.Write(byteBuffer, 0, byteBuffer.Length);
int t = PdfReader.TestPdfFile(coverSheetContent);
PdfReader.Open(coverSheetContent);
}
catch (Exception ex)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还添加了那些 PDF 文件。好吧,这些 PDF 对我来说是行输入,我不知道它们是从哪里创建的,也不知道是谁创建的。
关于PDFsharp的信息非常少,请帮我解决问题。
我做了很多挖掘,找出了将XPS文档转换为PDF的简单方法.有许多工具可以做到这一点,但它们不是免费的.有免费的替代品吗?
我被困住了。目前,我正在尝试模拟从应该是TIFF图像的数据库中提取二进制Blob。我在image变量中使用这个要点image.tif来做到这一点。我很确定我即将实现这一目标。问题可能与我将字符串转换为字节数组或其他方式有关。基本上,该应用程序引发异常,说明它无法创建具有0帧的PDF。在这一点上,我必须承认,我可能对此不屑一顾。有人会这么友善,并在这方面帮助我吗?
该代码包括在下面:
using System;
using System.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Text;
namespace ConvertTifToPDFFile
{
class Program
{
static void Main(string[] args)
{
string image = "";
byte[] imageAsByteStream = Encoding.ASCII.GetBytes(image);
int imageByteStreamLength = imageAsByteStream.Length;
string base64EncodedImage = Convert.ToBase64String(imageAsByteStream);
imageAsByteStream = Encoding.ASCII.GetBytes(base64EncodedImage);
Stream imageStream = TiffImageSplitter.ByteArrayToMemoryStream(imageAsByteStream);
// Image splitImage = TiffImageSplitter.getTiffImage(imageStream, 1);
TiffImageSplitter.tiff2PDF(imageStream);
}
}
public class TiffImageSplitter
{
private static TiffImageSplitter tiff = new TiffImageSplitter();
public static void tiff2PDF(Stream imageByteStream)
{
PdfDocument doc …Run Code Online (Sandbox Code Playgroud)