PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Oct 16, 2019 4:28 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Aug 07, 2018 1:36 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
Hi, I'm using PDFSharp to create PDF.
Now I trying to copy other document/image (PDF format with A3 size) and paste it in the box (x,y) in the new document (A4 size).
In the new document, there will be have image details box and image box.
So, how do I copy the image from other PDF into the image box in the new document?

I also attach the sample I need to create using PDFSharp.

Thanks.


Attachments:
Capture.PNG
Capture.PNG [ 123.91 KiB | Viewed 1277 times ]
Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 5:38 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 481
Location: CCAA
Hi!

You can draw pages from other PDF files like you draw images - draw them anywhere at any angle and any size.
You may have to do some calculations to maintain the aspect ratio.

See the Two Pages on One sample:
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
Lines 40 and 54 draw PDF pages. Check the lines above for prerequisites.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 8:34 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
TH-Soft wrote:
Hi!

You can draw pages from other PDF files like you draw images - draw them anywhere at any angle and any size.
You may have to do some calculations to maintain the aspect ratio.

See the Two Pages on One sample:
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
Lines 40 and 54 draw PDF pages. Check the lines above for prerequisites.


Thanks for reply.

Now I'm stuck at Line 21
Code:
XPdfForm form = XPdfForm.FromFile(filename);


I got below error.
Code:
ArgumentException: The specified file has no valid PDF file header.
Parameter name: path


I already check the pdf, it not set as read-only files. Even I follow straight away, copy the file and remove Read-Only attr, but still got the error.
It should be okay to read the files. :?:

Here below is my code:
Code:
var filename = "sample.pdf";
var file = Path.Combine(Directory.GetCurrentDirectory(), filename);
File.Copy(Path.Combine("../MyPDFSourceFolder/", filename), file, true);

File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);

var form = XPdfForm.FromFile(file);


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 8:44 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2980
Location: Cologne, Germany
Hi!

PDF files start with a header like "%PDF-1.4%". These should be the first bytes in the file. It seems your file does not have this header.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 8:57 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
Thomas Hoevel wrote:
Hi!

PDF files start with a header like "%PDF-1.4%". These should be the first bytes in the file. It seems your file does not have this header.


Is it related to pdf version? I already check my pdf, it got %PDF-1.3.% but got those error.

Even I try other pdf got from ADOBE site, still got this error - %PDF-1.4.%.
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 2:40 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
Hi, I trying to follow below example to draw pdf to new pdf.
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

But got this error:
Code:
ArgumentException: The specified file has no valid PDF file header.
Parameter name: path


At line 21 when call below code
Code:
XPdfForm form = XPdfForm.FromFile(filename);


I already check, my pdf is valid. Got %PDF-1.3.% in the header.
Even I try other pdf with %PDF-1.4.% header from Adobe (https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf)
but still got those error. Can anyone help me. Thanks


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 08, 2018 5:32 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 481
Location: CCAA
Hi!

If you think there is a bug with PDFsharp, please use the IssueSubmissionTemplate to make it replicable.
See also:
viewtopic.php?f=2&t=832

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 346 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group