Reputation: 1656
I'm attempting to add trim/bleed marks to a PDF using PDFsharp
I can set the top left hand corner of the PDF, however all other corners are not showing,
What I am doing is setting the xGraphics.DrawLine
to the position of the top left, adding the bleed marks for both the top left and top left bottom and then I am rotating the PDF's page so that the same xGraphics.DrawLine
positions can be used,
so that if the PDF's pages size was different, I'm hoping because its the top left, it would always have the correct bleed mark position.
Below is the method I have created as well as the result.
I also tried putting using (XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage))
within for (int i = 1; i <= 4; i++)
hoping it would reload the pdf page with the changes as the first loop seems to be ok, however there was no change.
/// <summary>
/// Add Bleed To PDF.
/// </summary>
/// <param name="pdfDocument"></param>
static void AddBleed(ref PdfDocument pdfDocument)
{
// Check The Pdf Has Been Loaded Into Memory.
if (pdfDocument.PageCount > 0)
{
// Create Pen.
XPen xPen = new XPen(XColors.Gray, 3);
const float TRIM_MARK_LEN = 30;
// Start Looping The Pdf's Pages
foreach (PdfPage pdfPage in pdfDocument.Pages)
{
using (XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage))
{
// A Page Has 4 Sides.
for (int i = 1; i <= 4; i++)
{
// Top Left.
xGraphics.DrawLine(xPen, TRIM_MARK_LEN, TRIM_MARK_LEN - 10, TRIM_MARK_LEN, -10);
// Bottom Top Left.
xGraphics.DrawLine(xPen, 0, TRIM_MARK_LEN, TRIM_MARK_LEN - 10, TRIM_MARK_LEN);
// Rotate The Pdf Page.
xGraphics.PdfPage.Rotate = xGraphics.PdfPage.Rotate + 90;
// Save The Graphics.
xGraphics.Save();
}
}
}
}
}
Upvotes: 0
Views: 440
Reputation: 21689
AFAIK you have to create a new XGraphics object after changing the rotation of the page.
You want to draw four angles, one in each corner. But AFAIK your code will draw four angles at the same position as the co-ordinates rotate with the page.
Stop rotating the page and draw the four angles separately.
BTW: Calling Save()
only makes sense when you call Restore()
later on. The invocation of Save()
in your code has no visual effect as far as I can tell. Better drop that line.
Upvotes: 1