0

I was using a library called PDF-Writer for C++ (https://github.com/galkahana/PDF-Writer) and I was writing some code like this:

void app::saveaspdf()
{
    PDFWriter* pdfWriter = new PDFWriter();
    
    PDFPage* sheet = new PDFPage();
    
    pdfWriter->StartPDF("c:\\a.pdf", ePDFVersion13);
    
    // ...add content to PDF file...
    
    sheet->SetMediaBox(PDFRectangle(0, 0, 595, 842));
    
    sheet->SetRotate(0);
    
    sheet->SetTrimBox(PDFRectangle(0, 0, 595, 842));
    
    sheet->SetCropBox(PDFRectangle(0, 0, 595, 842));
    
    sheet->SetBleedBox(PDFRectangle(0, 0, 595, 842));
    
    sheet->SetArtBox(PDFRectangle(0, 0, 595, 842));
    
    pdfWriter->WritePageAndRelease(sheet);
    
    pdfWriter->EndPDF();
}

Then I stumbled on a problem. If I run this, I get an "Access violation reading location" error, and it seems to be sheet because on the mediabox, rotation, trimbox, cropbox, bleedbox and artbox's values seem to be all 0.00000000000, which is confusing since I defined them on top, as you can see. I also thoroughly checked the Wiki on the GitHub page and it said:

https://github.com/galkahana/PDF-Writer/wiki/Creating-PDF-Pages

Note that a PDF Page has more boxes definition than just a Media Box.
PDF defines a Crop Box, a Bleed Box, A Trim Box and an Art Box. you can set these boxes up by using SetCropBox, SetBleedBox, SetTrimBox and SetArtBox respectively.

And only that after the example code, so I don't know what I did wrong here. So, how do I solve these errors?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

0 Answers0